USB make device_path handled by usbutils
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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
diff --git a/driver-avalon.c b/driver-avalon.c
index 35307c4..df17d00 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -574,7 +574,6 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
int this_option_offset = ++option_offset;
struct avalon_info *info;
struct cgpu_info *avalon;
- char devpath[20];
bool configured;
int ret;
@@ -591,14 +590,8 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
avalon->usbdev->usb_type = USB_TYPE_STD;
/* We have a real Avalon! */
- sprintf(devpath, "%d:%d",
- (int)(avalon->usbinfo.bus_number),
- (int)(avalon->usbinfo.device_address));
-
avalon_initialise(avalon);
- avalon->device_path = strdup(devpath);
-
avalon->device_data = calloc(sizeof(struct avalon_info), 1);
if (unlikely(!(avalon->device_data)))
quit(1, "Failed to calloc avalon_info data");
@@ -642,7 +635,7 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
applog(LOG_DEBUG, "Avalon Detected: %s "
"(miner_count=%d asic_count=%d timeout=%d frequency=%d)",
- devpath, info->miner_count, info->asic_count, info->timeout,
+ avalon->device_path, info->miner_count, info->asic_count, info->timeout,
info->frequency);
return true;
@@ -656,9 +649,6 @@ shin:
free(avalon->device_data);
avalon->device_data = NULL;
- free(avalon->device_path);
- avalon->device_path = NULL;
-
avalon = usb_free_cgpu(avalon);
return false;
diff --git a/driver-bflsc.c b/driver-bflsc.c
index 52ba312..9d1b71c 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -802,7 +802,6 @@ static bool bflsc_detect_one(struct libusb_device *dev, struct usb_find_devices
{
struct bflsc_info *sc_info = NULL;
char buf[BFLSC_BUFSIZ+1];
- char devpath[20];
int i, err, amount;
struct timeval init_start, init_now;
int init_sleep, init_count;
@@ -821,11 +820,6 @@ static bool bflsc_detect_one(struct libusb_device *dev, struct usb_find_devices
if (!usb_init(bflsc, dev, found))
goto shin;
- sprintf(devpath, "%d:%d",
- (int)(bflsc->usbinfo.bus_number),
- (int)(bflsc->usbinfo.device_address));
-
-
// Allow 2 complete attempts if the 1st time returns an unrecognised reply
ident_first = true;
retry:
@@ -837,7 +831,7 @@ reinit:
err = write_to_dev(bflsc, 0, BFLSC_IDENTIFY, BFLSC_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY);
if (err < 0 || amount != BFLSC_IDENTIFY_LEN) {
applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)",
- bflsc->drv->dname, devpath, amount, err);
+ bflsc->drv->dname, bflsc->device_path, amount, err);
goto unshin;
}
@@ -848,7 +842,7 @@ reinit:
if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
if (init_count == 2) {
applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
- bflsc->drv->dname, devpath, amount, err);
+ bflsc->drv->dname, bflsc->device_path, amount, err);
}
nmsleep(init_sleep);
if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
@@ -858,14 +852,14 @@ reinit:
if (init_count > 0)
applog(LOG_WARNING, "%s detect (%s) init failed %d times %.2fs",
- bflsc->drv->dname, devpath, init_count, tdiff(&init_now, &init_start));
+ bflsc->drv->dname, bflsc->device_path, init_count, tdiff(&init_now, &init_start));
if (err < 0) {
applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)",
- bflsc->drv->dname, devpath, amount, err);
+ bflsc->drv->dname, bflsc->device_path, amount, err);
} else {
applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
- bflsc->drv->dname, devpath, amount);
+ bflsc->drv->dname, bflsc->device_path, amount);
}
goto unshin;
@@ -874,24 +868,22 @@ reinit:
if (unlikely(!strstr(buf, BFLSC_BFLSC))) {
applog(LOG_DEBUG, "%s detect (%s) found an FPGA '%s' ignoring",
- bflsc->drv->dname, devpath, buf);
+ bflsc->drv->dname, bflsc->device_path, buf);
goto unshin;
}
if (unlikely(strstr(buf, BFLSC_IDENTITY))) {
if (ident_first) {
applog(LOG_DEBUG, "%s detect (%s) didn't recognise '%s' trying again ...",
- bflsc->drv->dname, devpath, buf);
+ bflsc->drv->dname, bflsc->device_path, buf);
ident_first = false;
goto retry;
}
applog(LOG_DEBUG, "%s detect (%s) didn't recognise '%s' on 2nd attempt",
- bflsc->drv->dname, devpath, buf);
+ bflsc->drv->dname, bflsc->device_path, buf);
goto unshin;
}
- bflsc->device_path = strdup(devpath);
-
if (!getinfo(bflsc, 0))
goto unshin;
@@ -945,7 +937,7 @@ reinit:
// We have a real BFLSC!
applog(LOG_DEBUG, "%s (%s) identified as: '%s'",
- bflsc->drv->dname, devpath, bflsc->drv->name);
+ bflsc->drv->dname, bflsc->device_path, bflsc->drv->name);
if (!add_cgpu(bflsc))
goto unshin;
@@ -965,9 +957,6 @@ unshin:
shin:
- free(bflsc->device_path);
- bflsc->device_path = NULL;
-
free(bflsc->device_data);
bflsc->device_data = NULL;
diff --git a/driver-bitforce.c b/driver-bitforce.c
index de575cf..3306170 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -166,7 +166,6 @@ failed:
static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
char buf[BITFORCE_BUFSIZ+1];
- char devpath[20];
int err, amount;
char *s;
struct timeval init_start, init_now;
@@ -178,10 +177,6 @@ static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devic
if (!usb_init(bitforce, dev, found))
goto shin;
- sprintf(devpath, "%d:%d",
- (int)(bitforce->usbinfo.bus_number),
- (int)(bitforce->usbinfo.device_address));
-
// Allow 2 complete attempts if the 1st time returns an unrecognised reply
ident_first = true;
retry:
@@ -192,7 +187,7 @@ reinit:
bitforce_initialise(bitforce, false);
if ((err = usb_write(bitforce, BITFORCE_IDENTIFY, BITFORCE_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY)) < 0 || amount != BITFORCE_IDENTIFY_LEN) {
applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)",
- bitforce->drv->dname, devpath, amount, err);
+ bitforce->drv->dname, bitforce->device_path, amount, err);
goto unshin;
}
@@ -202,7 +197,7 @@ reinit:
if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
if (init_count == 2) {
applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
- bitforce->drv->dname, devpath, amount, err);
+ bitforce->drv->dname, bitforce->device_path, amount, err);
}
nmsleep(init_sleep);
if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
@@ -212,14 +207,14 @@ reinit:
if (init_count > 0)
applog(LOG_WARNING, "%s detect (%s) init failed %d times %.2fs",
- bitforce->drv->dname, devpath, init_count, tdiff(&init_now, &init_start));
+ bitforce->drv->dname, bitforce->device_path, init_count, tdiff(&init_now, &init_start));
if (err < 0) {
applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)",
- bitforce->drv->dname, devpath, amount, err);
+ bitforce->drv->dname, bitforce->device_path, amount, err);
} else {
applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
- bitforce->drv->dname, devpath, amount);
+ bitforce->drv->dname, bitforce->device_path, amount);
}
goto unshin;
@@ -229,12 +224,12 @@ reinit:
if (unlikely(!strstr(buf, "SHA256"))) {
if (ident_first) {
applog(LOG_WARNING, "%s detect (%s) didn't recognise '%s' trying again ...",
- bitforce->drv->dname, devpath, buf);
+ bitforce->drv->dname, bitforce->device_path, buf);
ident_first = false;
goto retry;
}
applog(LOG_ERR, "%s detect (%s) didn't recognise '%s' on 2nd attempt",
- bitforce->drv->dname, devpath, buf);
+ bitforce->drv->dname, bitforce->device_path, buf);
goto unshin;
}
@@ -256,7 +251,7 @@ reinit:
// We have a real BitForce!
applog(LOG_DEBUG, "%s (%s) identified as: '%s'",
- bitforce->drv->dname, devpath, bitforce->name);
+ bitforce->drv->dname, bitforce->device_path, bitforce->name);
/* Initially enable support for nonce range and disable it later if it
* fails */
@@ -269,8 +264,6 @@ reinit:
bitforce->kname = KNAME_WORK;
}
- bitforce->device_path = strdup(devpath);
-
if (!add_cgpu(bitforce))
goto unshin;
@@ -286,9 +279,6 @@ unshin:
shin:
- free(bitforce->device_path);
- bitforce->device_path = NULL;
-
if (bitforce->name != blank) {
free(bitforce->name);
bitforce->name = NULL;
diff --git a/driver-icarus.c b/driver-icarus.c
index 4b06c53..86a781a 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -728,7 +728,6 @@ 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)
{
int this_option_offset = ++option_offset;
- char devpath[20];
struct ICARUS_INFO *info;
struct timeval tv_start, tv_finish;
@@ -758,12 +757,6 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
get_options(this_option_offset, icarus, &baud, &work_division, &fpga_count);
- sprintf(devpath, "%d:%d",
- (int)(icarus->usbinfo.bus_number),
- (int)(icarus->usbinfo.device_address));
-
- icarus->device_path = strdup(devpath);
-
hex2bin(ob_bin, golden_ob, sizeof(ob_bin));
tries = 2;
@@ -789,7 +782,7 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
applog(LOG_ERR,
"Icarus Detect: "
"Test failed at %s: get %s, should: %s",
- devpath, nonce_hex, golden_nonce);
+ icarus->device_path, nonce_hex, golden_nonce);
}
}
free(nonce_hex);
@@ -801,7 +794,7 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
applog(LOG_DEBUG,
"Icarus Detect: "
"Test succeeded at %s: got %s",
- devpath, golden_nonce);
+ icarus->device_path, golden_nonce);
/* We have a real Icarus! */
if (!add_cgpu(icarus))
@@ -810,7 +803,7 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
update_usb_stats(icarus);
applog(LOG_INFO, "%s%d: Found at %s",
- icarus->drv->name, icarus->device_id, devpath);
+ icarus->drv->name, icarus->device_id, icarus->device_path);
applog(LOG_DEBUG, "%s%d: Init baud=%d work_division=%d fpga_count=%d",
icarus->drv->name, icarus->device_id, baud, work_division, fpga_count);
@@ -842,9 +835,6 @@ unshin:
usb_uninit(icarus);
- free(icarus->device_path);
- icarus->device_path = NULL;
-
shin:
icarus = usb_free_cgpu(icarus);
diff --git a/driver-modminer.c b/driver-modminer.c
index f537e7d..1519bc9 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -115,7 +115,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
{
char buf[0x100+1];
char *devname = NULL;
- char devpath[20];
+ char devpath[32];
int err, i, amount;
bool added = false;
@@ -128,44 +128,40 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
if (!usb_init(modminer, dev, found))
goto shin;
- sprintf(devpath, "%d:%d",
- (int)(modminer->usbinfo.bus_number),
- (int)(modminer->usbinfo.device_address));
-
do_ping(modminer);
if ((err = usb_write(modminer, MODMINER_GET_VERSION, 1, &amount, C_REQUESTVERSION)) < 0 || amount != 1) {
applog(LOG_ERR, "%s detect (%s) send version request failed (%d:%d)",
- modminer->drv->dname, devpath, amount, err);
+ modminer->drv->dname, modminer->device_path, amount, err);
goto unshin;
}
if ((err = usb_read_once(modminer, buf, sizeof(buf)-1, &amount, C_GETVERSION)) < 0 || amount < 1) {
if (err < 0)
applog(LOG_ERR, "%s detect (%s) no version reply (%d)",
- modminer->drv->dname, devpath, err);
+ modminer->drv->dname, modminer->device_path, err);
else
applog(LOG_ERR, "%s detect (%s) empty version reply (%d)",
- modminer->drv->dname, devpath, amount);
+ modminer->drv->dname, modminer->device_path, amount);
applog(LOG_DEBUG, "%s detect (%s) check the firmware",
- modminer->drv->dname, devpath);
+ modminer->drv->dname, modminer->device_path);
goto unshin;
}
buf[amount] = '\0';
devname = strdup(buf);
- applog(LOG_DEBUG, "%s (%s) identified as: %s", modminer->drv->dname, devpath, devname);
+ applog(LOG_DEBUG, "%s (%s) identified as: %s", modminer->drv->dname, modminer->device_path, devname);
if ((err = usb_write(modminer, MODMINER_FPGA_COUNT, 1, &amount, C_REQUESTFPGACOUNT) < 0 || amount != 1)) {
applog(LOG_ERR, "%s detect (%s) FPGA count request failed (%d:%d)",
- modminer->drv->dname, devpath, amount, err);
+ modminer->drv->dname, modminer->device_path, amount, err);
goto unshin;
}
if ((err = usb_read(modminer, buf, 1, &amount, C_GETFPGACOUNT)) < 0 || amount != 1) {
applog(LOG_ERR, "%s detect (%s) no FPGA count reply (%d:%d)",
- modminer->drv->dname, devpath, amount, err);
+ modminer->drv->dname, modminer->device_path, amount, err);
goto unshin;
}
@@ -174,18 +170,18 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
if (buf[0] == 0) {
applog(LOG_ERR, "%s detect (%s) zero FPGA count from %s",
- modminer->drv->dname, devpath, devname);
+ modminer->drv->dname, modminer->device_path, devname);
goto unshin;
}
if (buf[0] < 1 || buf[0] > 4) {
applog(LOG_ERR, "%s detect (%s) invalid FPGA count (%u) from %s",
- modminer->drv->dname, devpath, buf[0], devname);
+ modminer->drv->dname, modminer->device_path, buf[0], devname);
goto unshin;
}
applog(LOG_DEBUG, "%s (%s) %s has %u FPGAs",
- modminer->drv->dname, devpath, devname, buf[0]);
+ modminer->drv->dname, modminer->device_path, devname, buf[0]);
modminer->name = devname;
@@ -209,8 +205,6 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
tmp->modminer_mutex = modminer->modminer_mutex;
if (!add_cgpu(tmp)) {
- free(tmp->device_path);
- tmp->device_path = NULL;
tmp = usb_free_cgpu(tmp);
goto unshin;
}
diff --git a/usbutils.c b/usbutils.c
index 1a0e118..fd3859d 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -1423,6 +1423,8 @@ struct cgpu_info *usb_free_cgpu(struct cgpu_info *cgpu)
if (cgpu->drv->copy)
free(cgpu->drv);
+ free(cgpu->device_path);
+
free(cgpu);
return NULL;
@@ -1439,6 +1441,7 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
const struct libusb_interface_descriptor *idesc;
const struct libusb_endpoint_descriptor *epdesc;
unsigned char strbuf[STRBUFLEN+1];
+ char devpath[32];
char devstr[STRBUFLEN+1];
int err, i, j, k;
int bad = USB_INIT_FAIL;
@@ -1446,8 +1449,13 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
cgpu->usbinfo.bus_number = libusb_get_bus_number(dev);
cgpu->usbinfo.device_address = libusb_get_device_address(dev);
- sprintf(devstr, "- %s device %d:%d", found->name,
- cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address);
+ sprintf(devpath, "%d:%d",
+ (int)(cgpu->usbinfo.bus_number),
+ (int)(cgpu->usbinfo.device_address));
+
+ cgpu->device_path = strdup(devpath);
+
+ sprintf(devstr, "- %s device %s", found->name, devpath);
cgusb = calloc(1, sizeof(*cgusb));
if (unlikely(!cgusb))