mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-22 20:44:19 +00:00
device_drv - allow .name to be changed before add_cgpu()
This commit is contained in:
parent
a4e95cfa42
commit
f9e04a3c5b
15
cgminer.c
15
cgminer.c
@ -6360,6 +6360,21 @@ bool add_cgpu(struct cgpu_info*cgpu)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct device_drv *copy_drv(struct device_drv *drv)
|
||||||
|
{
|
||||||
|
struct device_drv *copy;
|
||||||
|
char buf[100];
|
||||||
|
|
||||||
|
if (unlikely(!(copy = malloc(sizeof(*copy))))) {
|
||||||
|
sprintf(buf, "Failed to allocate device_drv copy of %s (%s)",
|
||||||
|
drv->name, drv->copy ? "copy" : "original");
|
||||||
|
quit(1, buf);
|
||||||
|
}
|
||||||
|
memcpy(copy, drv, sizeof(*copy));
|
||||||
|
copy->copy = true;
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
bool pools_active = false;
|
bool pools_active = false;
|
||||||
|
@ -240,6 +240,9 @@ shin:
|
|||||||
if (bitforce->name != blank)
|
if (bitforce->name != blank)
|
||||||
free(bitforce->name);
|
free(bitforce->name);
|
||||||
|
|
||||||
|
if (bitforce->drv->copy)
|
||||||
|
free(bitforce->drv);
|
||||||
|
|
||||||
free(bitforce);
|
free(bitforce);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -182,7 +182,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
|
|||||||
for (i = 0; i < buf[0]; i++) {
|
for (i = 0; i < buf[0]; i++) {
|
||||||
struct cgpu_info *tmp = calloc(1, sizeof(*tmp));
|
struct cgpu_info *tmp = calloc(1, sizeof(*tmp));
|
||||||
|
|
||||||
tmp->drv = modminer->drv;
|
tmp->drv = copy_drv(modminer->drv);
|
||||||
tmp->name = devname;
|
tmp->name = devname;
|
||||||
|
|
||||||
sprintf(devpath, "%d:%d:%d",
|
sprintf(devpath, "%d:%d:%d",
|
||||||
@ -202,6 +202,8 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
|
|||||||
|
|
||||||
if (!add_cgpu(tmp)) {
|
if (!add_cgpu(tmp)) {
|
||||||
free(tmp->device_path);
|
free(tmp->device_path);
|
||||||
|
if (tmp->drv->copy)
|
||||||
|
free(tmp->drv);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
goto unshin;
|
goto unshin;
|
||||||
}
|
}
|
||||||
@ -211,6 +213,9 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
|
|||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (modminer->drv->copy)
|
||||||
|
free(modminer->drv);
|
||||||
|
|
||||||
free(modminer);
|
free(modminer);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -223,6 +228,9 @@ shin:
|
|||||||
if (!added)
|
if (!added)
|
||||||
free(modminer->modminer_mutex);
|
free(modminer->modminer_mutex);
|
||||||
|
|
||||||
|
if (modminer->drv->copy)
|
||||||
|
free(modminer->drv);
|
||||||
|
|
||||||
free(modminer);
|
free(modminer);
|
||||||
|
|
||||||
if (added)
|
if (added)
|
||||||
|
5
miner.h
5
miner.h
@ -299,8 +299,13 @@ struct device_drv {
|
|||||||
void (*hw_error)(struct thr_info *);
|
void (*hw_error)(struct thr_info *);
|
||||||
void (*thread_shutdown)(struct thr_info *);
|
void (*thread_shutdown)(struct thr_info *);
|
||||||
void (*thread_enable)(struct thr_info *);
|
void (*thread_enable)(struct thr_info *);
|
||||||
|
|
||||||
|
// Does it need to be free()d?
|
||||||
|
bool copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern struct device_drv *copy_drv(struct device_drv*);
|
||||||
|
|
||||||
enum dev_enable {
|
enum dev_enable {
|
||||||
DEV_ENABLED,
|
DEV_ENABLED,
|
||||||
DEV_DISABLED,
|
DEV_DISABLED,
|
||||||
|
16
usbutils.c
16
usbutils.c
@ -891,6 +891,14 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
|
|||||||
|
|
||||||
libusb_free_config_descriptor(config);
|
libusb_free_config_descriptor(config);
|
||||||
|
|
||||||
|
// Allow a name change based on the idVendor+idProduct
|
||||||
|
// N.B. must be done before calling add_cgpu()
|
||||||
|
if (strcmp(cgpu->drv->name, found->name)) {
|
||||||
|
if (!cgpu->drv->copy)
|
||||||
|
cgpu->drv = copy_drv(cgpu->drv);
|
||||||
|
cgpu->drv->name = (char *)(found->name);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
cldame:
|
cldame:
|
||||||
@ -919,14 +927,14 @@ static bool usb_check_device(struct device_drv *drv, struct libusb_device *dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (desc.idVendor != look->idVendor || desc.idProduct != look->idProduct) {
|
if (desc.idVendor != look->idVendor || desc.idProduct != look->idProduct) {
|
||||||
applog(LOG_DEBUG, "%s looking for %04x:%04x but found %04x:%04x instead",
|
applog(LOG_DEBUG, "%s looking for %s %04x:%04x but found %04x:%04x instead",
|
||||||
drv->name, look->idVendor, look->idProduct, desc.idVendor, desc.idProduct);
|
drv->name, look->name, look->idVendor, look->idProduct, desc.idVendor, desc.idProduct);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
applog(LOG_DEBUG, "%s looking for and found %04x:%04x",
|
applog(LOG_DEBUG, "%s looking for and found %s %04x:%04x",
|
||||||
drv->name, look->idVendor, look->idProduct);
|
drv->name, look->name, look->idVendor, look->idProduct);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user