Make usb_detect return the cgpu associated with it to check if it succeeds to decide on whether to increment the device count or not.
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
diff --git a/driver-avalon.c b/driver-avalon.c
index 4a4b0b8..aaabe55 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -741,7 +741,7 @@ static void bitburner_get_version(struct cgpu_info *avalon)
}
}
-static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *avalon_detect_one(libusb_device *dev, struct usb_find_devices *found)
{
int baud, miner_count, asic_count, timeout, frequency;
int this_option_offset;
@@ -851,7 +851,7 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
bitburner_get_version(avalon);
}
- return true;
+ return avalon;
unshin:
@@ -864,7 +864,7 @@ shin:
avalon = usb_free_cgpu(avalon);
- return false;
+ return NULL;
}
static void avalon_detect(bool __maybe_unused hotplug)
diff --git a/driver-bflsc.c b/driver-bflsc.c
index f3e45c4..5dafa9c 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -688,7 +688,7 @@ ne:
return ok;
}
-static bool bflsc_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *bflsc_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
struct bflsc_info *sc_info = NULL;
char buf[BFLSC_BUFSIZ+1];
@@ -888,7 +888,7 @@ reinit:
mutex_init(&bflsc->device_mutex);
rwlock_init(&sc_info->stat_lock);
- return true;
+ return bflsc;
unshin:
@@ -906,7 +906,7 @@ shin:
bflsc = usb_free_cgpu(bflsc);
- return false;
+ return NULL;
}
static void bflsc_detect(bool __maybe_unused hotplug)
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 901ba08..d4f51c1 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -162,7 +162,7 @@ failed:
mutex_unlock(&bitforce->device_mutex);
}
-static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *bitforce_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
char buf[BITFORCE_BUFSIZ+1];
int err, amount;
@@ -270,7 +270,7 @@ reinit:
mutex_init(&bitforce->device_mutex);
- return true;
+ return bitforce;
unshin:
@@ -285,7 +285,7 @@ shin:
bitforce = usb_free_cgpu(bitforce);
- return false;
+ return NULL;
}
static void bitforce_detect(bool __maybe_unused hotplug)
diff --git a/driver-bitfury.c b/driver-bitfury.c
index f171120..a54723a 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -270,7 +270,7 @@ out_close:
return false;
}
-static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
struct cgpu_info *bitfury;
struct bitfury_info *info;
@@ -308,7 +308,7 @@ static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_device
out:
bitfury = usb_free_cgpu(bitfury);
}
- return ret;
+ return bitfury;
}
static void bitfury_detect(bool __maybe_unused hotplug)
diff --git a/driver-icarus.c b/driver-icarus.c
index 7da4a99..af35124 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -786,7 +786,7 @@ static void get_options(int this_option_offset, struct cgpu_info *icarus, int *b
}
}
-static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
int this_option_offset = ++option_offset;
struct ICARUS_INFO *info;
@@ -1010,7 +1010,7 @@ cmr2_retry:
}
}
- return true;
+ return icarus;
unshin:
@@ -1022,7 +1022,7 @@ shin:
icarus = usb_free_cgpu(icarus);
- return false;
+ return NULL;
}
static void icarus_detect(bool __maybe_unused hotplug)
diff --git a/driver-klondike.c b/driver-klondike.c
index 3a740ec..5da915c 100644
--- a/driver-klondike.c
+++ b/driver-klondike.c
@@ -765,7 +765,7 @@ static void control_init(struct cgpu_info *klncgpu)
klncgpu->drv->name, klncgpu->device_id, err);
}
-static bool klondike_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *klondike_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
struct cgpu_info *klncgpu = usb_alloc_cgpu(&klondike_drv, 1);
struct klondike_info *klninfo = NULL;
@@ -823,7 +823,7 @@ static bool klondike_detect_one(struct libusb_device *dev, struct usb_find_devic
applog(LOG_DEBUG, "Klondike cgpu added");
rwlock_init(&klninfo->stat_lock);
cglock_init(&klninfo->klist_lock);
- return true;
+ return klncgpu;
}
}
usb_uninit(klncgpu);
@@ -831,7 +831,7 @@ static bool klondike_detect_one(struct libusb_device *dev, struct usb_find_devic
free(klninfo->free);
free(klninfo);
free(klncgpu);
- return false;
+ return NULL;
}
static void klondike_detect(bool __maybe_unused hotplug)
diff --git a/driver-modminer.c b/driver-modminer.c
index e10cbba..642d13d 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -109,7 +109,7 @@ static void do_ping(struct cgpu_info *modminer)
modminer->drv->name, modminer->fpgaid, amount, err);
}
-static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info *modminer_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
char buf[0x100+1];
char *devname = NULL;
@@ -217,7 +217,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
modminer = usb_free_cgpu(modminer);
- return true;
+ return modminer;
unshin:
if (!added)
@@ -232,9 +232,9 @@ shin:
modminer = usb_free_cgpu(modminer);
if (added)
- return true;
+ return modminer;
else
- return false;
+ return NULL;
}
static void modminer_detect(bool __maybe_unused hotplug)
diff --git a/usbutils.c b/usbutils.c
index 482471f..b3459d2 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -1410,6 +1410,7 @@ void usb_uninit(struct cgpu_info *cgpu)
static void release_cgpu(struct cgpu_info *cgpu)
{
struct cg_usb_device *cgusb = cgpu->usbdev;
+ bool initted = cgpu->usbinfo.initialised;
struct cgpu_info *lookcgpu;
int i;
@@ -1420,9 +1421,11 @@ static void release_cgpu(struct cgpu_info *cgpu)
applog(LOG_DEBUG, "USB release %s%i",
cgpu->drv->name, cgpu->device_id);
- zombie_devs++;
- total_count--;
- drv_count[cgpu->drv->drv_id].count--;
+ if (initted) {
+ zombie_devs++;
+ total_count--;
+ drv_count[cgpu->drv->drv_id].count--;
+ }
cgpu->usbinfo.nodev = true;
cgpu->usbinfo.nodev_count++;
@@ -1432,8 +1435,10 @@ static void release_cgpu(struct cgpu_info *cgpu)
for (i = 0; i < total_devices; i++) {
lookcgpu = get_devices(i);
if (lookcgpu != cgpu && lookcgpu->usbdev == cgusb) {
- total_count--;
- drv_count[lookcgpu->drv->drv_id].count--;
+ if (initted) {
+ total_count--;
+ drv_count[lookcgpu->drv->drv_id].count--;
+ }
lookcgpu->usbinfo.nodev = true;
lookcgpu->usbinfo.nodev_count++;
@@ -1978,11 +1983,12 @@ static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv,
return NULL;
}
-void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *))
+void usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *))
{
libusb_device **list;
ssize_t count, i;
struct usb_find_devices *found;
+ struct cgpu_info *cgpu;
applog(LOG_DEBUG, "USB scan devices: checking for %s devices", drv->name);
@@ -2027,9 +2033,11 @@ void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_devi
if (is_in_use(list[i]) || cgminer_usb_lock(drv, list[i]) == false)
free(found);
else {
- if (!device_detect(list[i], found))
+ cgpu = device_detect(list[i], found);
+ if (!cgpu)
cgminer_usb_unlock(drv, list[i]);
else {
+ cgpu->usbinfo.initialised = true;
total_count++;
drv_count[drv->drv_id].count++;
}
diff --git a/usbutils.h b/usbutils.h
index a663816..035f83e 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -230,6 +230,7 @@ struct cg_usb_info {
uint8_t device_address;
int usbstat;
bool nodev;
+ bool initialised;
int nodev_count;
struct timeval last_nodev;
uint32_t ioerr_count;
@@ -388,7 +389,7 @@ struct cgpu_info *usb_alloc_cgpu(struct device_drv *drv, int threads);
struct cgpu_info *usb_free_cgpu(struct cgpu_info *cgpu);
void usb_uninit(struct cgpu_info *cgpu);
bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found);
-void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *));
+void usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *));
struct api_data *api_usb_stats(int *count);
void update_usb_stats(struct cgpu_info *cgpu);
int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, int timeout, const char *end, enum usb_cmds cmd, bool readonce, bool cancellable);