device_drv - allow .name to be changed before add_cgpu()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
diff --git a/cgminer.c b/cgminer.c
index 177f61c..befe57e 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -6360,6 +6360,21 @@ bool add_cgpu(struct cgpu_info*cgpu)
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[])
{
bool pools_active = false;
diff --git a/driver-bitforce.c b/driver-bitforce.c
index f119632..0181b17 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -240,6 +240,9 @@ shin:
if (bitforce->name != blank)
free(bitforce->name);
+ if (bitforce->drv->copy)
+ free(bitforce->drv);
+
free(bitforce);
return false;
diff --git a/driver-modminer.c b/driver-modminer.c
index 0868e85..246947b 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -182,7 +182,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
for (i = 0; i < buf[0]; i++) {
struct cgpu_info *tmp = calloc(1, sizeof(*tmp));
- tmp->drv = modminer->drv;
+ tmp->drv = copy_drv(modminer->drv);
tmp->name = devname;
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)) {
free(tmp->device_path);
+ if (tmp->drv->copy)
+ free(tmp->drv);
free(tmp);
goto unshin;
}
@@ -211,6 +213,9 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
added = true;
}
+ if (modminer->drv->copy)
+ free(modminer->drv);
+
free(modminer);
return true;
@@ -223,6 +228,9 @@ shin:
if (!added)
free(modminer->modminer_mutex);
+ if (modminer->drv->copy)
+ free(modminer->drv);
+
free(modminer);
if (added)
diff --git a/miner.h b/miner.h
index 4e888f3..b89d072 100644
--- a/miner.h
+++ b/miner.h
@@ -299,8 +299,13 @@ struct device_drv {
void (*hw_error)(struct thr_info *);
void (*thread_shutdown)(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 {
DEV_ENABLED,
DEV_DISABLED,
diff --git a/usbutils.c b/usbutils.c
index bebd722..ebfcc0b 100644
--- a/usbutils.c
+++ b/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);
+ // 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;
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) {
- applog(LOG_DEBUG, "%s looking for %04x:%04x but found %04x:%04x instead",
- drv->name, look->idVendor, look->idProduct, desc.idVendor, desc.idProduct);
+ applog(LOG_DEBUG, "%s looking for %s %04x:%04x but found %04x:%04x instead",
+ drv->name, look->name, look->idVendor, look->idProduct, desc.idVendor, desc.idProduct);
return false;
}
- applog(LOG_DEBUG, "%s looking for and found %04x:%04x",
- drv->name, look->idVendor, look->idProduct);
+ applog(LOG_DEBUG, "%s looking for and found %s %04x:%04x",
+ drv->name, look->name, look->idVendor, look->idProduct);
return true;
}