Browse Source

USB make device_path handled by usbutils

Kano 12 years ago
parent
commit
b8b137aeef
6 changed files with 42 additions and 81 deletions
  1. 1 11
      driver-avalon.c
  2. 9 20
      driver-bflsc.c
  3. 8 18
      driver-bitforce.c
  4. 3 13
      driver-icarus.c
  5. 11 17
      driver-modminer.c
  6. 10 2
      usbutils.c

+ 1 - 11
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;
 	int this_option_offset = ++option_offset;
 	struct avalon_info *info;
 	struct avalon_info *info;
 	struct cgpu_info *avalon;
 	struct cgpu_info *avalon;
-	char devpath[20];
 	bool configured;
 	bool configured;
 	int ret;
 	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;
 	avalon->usbdev->usb_type = USB_TYPE_STD;
 
 
 	/* We have a real Avalon! */
 	/* We have a real Avalon! */
-	sprintf(devpath, "%d:%d",
-			(int)(avalon->usbinfo.bus_number),
-			(int)(avalon->usbinfo.device_address));
-
 	avalon_initialise(avalon);
 	avalon_initialise(avalon);
 
 
-	avalon->device_path = strdup(devpath);
-
 	avalon->device_data = calloc(sizeof(struct avalon_info), 1);
 	avalon->device_data = calloc(sizeof(struct avalon_info), 1);
 	if (unlikely(!(avalon->device_data)))
 	if (unlikely(!(avalon->device_data)))
 		quit(1, "Failed to calloc avalon_info 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 "
 	applog(LOG_DEBUG, "Avalon Detected: %s "
 	       "(miner_count=%d asic_count=%d timeout=%d frequency=%d)",
 	       "(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);
 	       info->frequency);
 
 
 	return true;
 	return true;
@@ -656,9 +649,6 @@ shin:
 	free(avalon->device_data);
 	free(avalon->device_data);
 	avalon->device_data = NULL;
 	avalon->device_data = NULL;
 
 
-	free(avalon->device_path);
-	avalon->device_path = NULL;
-
 	avalon = usb_free_cgpu(avalon);
 	avalon = usb_free_cgpu(avalon);
 
 
 	return false;
 	return false;

+ 9 - 20
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;
 	struct bflsc_info *sc_info = NULL;
 	char buf[BFLSC_BUFSIZ+1];
 	char buf[BFLSC_BUFSIZ+1];
-	char devpath[20];
 	int i, err, amount;
 	int i, err, amount;
 	struct timeval init_start, init_now;
 	struct timeval init_start, init_now;
 	int init_sleep, init_count;
 	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))
 	if (!usb_init(bflsc, dev, found))
 		goto shin;
 		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
 	// Allow 2 complete attempts if the 1st time returns an unrecognised reply
 	ident_first = true;
 	ident_first = true;
 retry:
 retry:
@@ -837,7 +831,7 @@ reinit:
 	err = write_to_dev(bflsc, 0, BFLSC_IDENTIFY, BFLSC_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY);
 	err = write_to_dev(bflsc, 0, BFLSC_IDENTIFY, BFLSC_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY);
 	if (err < 0 || amount != BFLSC_IDENTIFY_LEN) {
 	if (err < 0 || amount != BFLSC_IDENTIFY_LEN) {
 		applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)",
 		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;
 		goto unshin;
 	}
 	}
 
 
@@ -848,7 +842,7 @@ reinit:
 		if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
 		if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
 			if (init_count == 2) {
 			if (init_count == 2) {
 				applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
 				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);
 			nmsleep(init_sleep);
 			if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
 			if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
@@ -858,14 +852,14 @@ reinit:
 
 
 		if (init_count > 0)
 		if (init_count > 0)
 			applog(LOG_WARNING, "%s detect (%s) init failed %d times %.2fs",
 			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) {
 		if (err < 0) {
 			applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)",
 			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 {
 		} else {
 			applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
 			applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
-				bflsc->drv->dname, devpath, amount);
+				bflsc->drv->dname, bflsc->device_path, amount);
 		}
 		}
 
 
 		goto unshin;
 		goto unshin;
@@ -874,24 +868,22 @@ reinit:
 
 
 	if (unlikely(!strstr(buf, BFLSC_BFLSC))) {
 	if (unlikely(!strstr(buf, BFLSC_BFLSC))) {
 		applog(LOG_DEBUG, "%s detect (%s) found an FPGA '%s' ignoring",
 		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;
 		goto unshin;
 	}
 	}
 
 
 	if (unlikely(strstr(buf, BFLSC_IDENTITY))) {
 	if (unlikely(strstr(buf, BFLSC_IDENTITY))) {
 		if (ident_first) {
 		if (ident_first) {
 			applog(LOG_DEBUG, "%s detect (%s) didn't recognise '%s' trying again ...",
 			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;
 			ident_first = false;
 			goto retry;
 			goto retry;
 		}
 		}
 		applog(LOG_DEBUG, "%s detect (%s) didn't recognise '%s' on 2nd attempt",
 		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;
 		goto unshin;
 	}
 	}
 
 
-	bflsc->device_path = strdup(devpath);
-
 	if (!getinfo(bflsc, 0))
 	if (!getinfo(bflsc, 0))
 		goto unshin;
 		goto unshin;
 
 
@@ -945,7 +937,7 @@ reinit:
 
 
 	// We have a real BFLSC!
 	// We have a real BFLSC!
 	applog(LOG_DEBUG, "%s (%s) identified as: '%s'",
 	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))
 	if (!add_cgpu(bflsc))
 		goto unshin;
 		goto unshin;
@@ -965,9 +957,6 @@ unshin:
 
 
 shin:
 shin:
 
 
-	free(bflsc->device_path);
-	bflsc->device_path = NULL;
-
 	free(bflsc->device_data);
 	free(bflsc->device_data);
 	bflsc->device_data = NULL;
 	bflsc->device_data = NULL;
 
 

+ 8 - 18
driver-bitforce.c

@@ -166,7 +166,6 @@ failed:
 static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
 static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
 {
 {
 	char buf[BITFORCE_BUFSIZ+1];
 	char buf[BITFORCE_BUFSIZ+1];
-	char devpath[20];
 	int err, amount;
 	int err, amount;
 	char *s;
 	char *s;
 	struct timeval init_start, init_now;
 	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))
 	if (!usb_init(bitforce, dev, found))
 		goto shin;
 		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
 	// Allow 2 complete attempts if the 1st time returns an unrecognised reply
 	ident_first = true;
 	ident_first = true;
 retry:
 retry:
@@ -192,7 +187,7 @@ reinit:
 	bitforce_initialise(bitforce, false);
 	bitforce_initialise(bitforce, false);
 	if ((err = usb_write(bitforce, BITFORCE_IDENTIFY, BITFORCE_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY)) < 0 || amount != BITFORCE_IDENTIFY_LEN) {
 	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)",
 		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;
 		goto unshin;
 	}
 	}
 
 
@@ -202,7 +197,7 @@ reinit:
 		if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
 		if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
 			if (init_count == 2) {
 			if (init_count == 2) {
 				applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
 				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);
 			nmsleep(init_sleep);
 			if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
 			if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
@@ -212,14 +207,14 @@ reinit:
 
 
 		if (init_count > 0)
 		if (init_count > 0)
 			applog(LOG_WARNING, "%s detect (%s) init failed %d times %.2fs",
 			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) {
 		if (err < 0) {
 			applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)",
 			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 {
 		} else {
 			applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
 			applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
-				bitforce->drv->dname, devpath, amount);
+				bitforce->drv->dname, bitforce->device_path, amount);
 		}
 		}
 
 
 		goto unshin;
 		goto unshin;
@@ -229,12 +224,12 @@ reinit:
 	if (unlikely(!strstr(buf, "SHA256"))) {
 	if (unlikely(!strstr(buf, "SHA256"))) {
 		if (ident_first) {
 		if (ident_first) {
 			applog(LOG_WARNING, "%s detect (%s) didn't recognise '%s' trying again ...",
 			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;
 			ident_first = false;
 			goto retry;
 			goto retry;
 		}
 		}
 		applog(LOG_ERR, "%s detect (%s) didn't recognise '%s' on 2nd attempt",
 		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;
 		goto unshin;
 	}
 	}
 
 
@@ -256,7 +251,7 @@ reinit:
 
 
 	// We have a real BitForce!
 	// We have a real BitForce!
 	applog(LOG_DEBUG, "%s (%s) identified as: '%s'",
 	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
 	/* Initially enable support for nonce range and disable it later if it
 	 * fails */
 	 * fails */
@@ -269,8 +264,6 @@ reinit:
 		bitforce->kname = KNAME_WORK;
 		bitforce->kname = KNAME_WORK;
 	}
 	}
 
 
-	bitforce->device_path = strdup(devpath);
-
 	if (!add_cgpu(bitforce))
 	if (!add_cgpu(bitforce))
 		goto unshin;
 		goto unshin;
 
 
@@ -286,9 +279,6 @@ unshin:
 
 
 shin:
 shin:
 
 
-	free(bitforce->device_path);
-	bitforce->device_path = NULL;
-
 	if (bitforce->name != blank) {
 	if (bitforce->name != blank) {
 		free(bitforce->name);
 		free(bitforce->name);
 		bitforce->name = NULL;
 		bitforce->name = NULL;

+ 3 - 13
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)
 static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
 {
 {
 	int this_option_offset = ++option_offset;
 	int this_option_offset = ++option_offset;
-	char devpath[20];
 	struct ICARUS_INFO *info;
 	struct ICARUS_INFO *info;
 	struct timeval tv_start, tv_finish;
 	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);
 	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));
 	hex2bin(ob_bin, golden_ob, sizeof(ob_bin));
 
 
 	tries = 2;
 	tries = 2;
@@ -789,7 +782,7 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
 				applog(LOG_ERR,
 				applog(LOG_ERR,
 					"Icarus Detect: "
 					"Icarus Detect: "
 					"Test failed at %s: get %s, should: %s",
 					"Test failed at %s: get %s, should: %s",
-					devpath, nonce_hex, golden_nonce);
+					icarus->device_path, nonce_hex, golden_nonce);
 			}
 			}
 		}
 		}
 		free(nonce_hex);
 		free(nonce_hex);
@@ -801,7 +794,7 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
 	applog(LOG_DEBUG,
 	applog(LOG_DEBUG,
 		"Icarus Detect: "
 		"Icarus Detect: "
 		"Test succeeded at %s: got %s",
 		"Test succeeded at %s: got %s",
-			devpath, golden_nonce);
+			icarus->device_path, golden_nonce);
 
 
 	/* We have a real Icarus! */
 	/* We have a real Icarus! */
 	if (!add_cgpu(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);
 	update_usb_stats(icarus);
 
 
 	applog(LOG_INFO, "%s%d: Found at %s",
 	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",
 	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);
 		icarus->drv->name, icarus->device_id, baud, work_division, fpga_count);
@@ -842,9 +835,6 @@ unshin:
 
 
 	usb_uninit(icarus);
 	usb_uninit(icarus);
 
 
-	free(icarus->device_path);
-	icarus->device_path = NULL;
-
 shin:
 shin:
 
 
 	icarus = usb_free_cgpu(icarus);
 	icarus = usb_free_cgpu(icarus);

+ 11 - 17
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 buf[0x100+1];
 	char *devname = NULL;
 	char *devname = NULL;
-	char devpath[20];
+	char devpath[32];
 	int err, i, amount;
 	int err, i, amount;
 	bool added = false;
 	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))
 	if (!usb_init(modminer, dev, found))
 		goto shin;
 		goto shin;
 
 
-	sprintf(devpath, "%d:%d",
-			(int)(modminer->usbinfo.bus_number),
-			(int)(modminer->usbinfo.device_address));
-
 	do_ping(modminer);
 	do_ping(modminer);
 
 
 	if ((err = usb_write(modminer, MODMINER_GET_VERSION, 1, &amount, C_REQUESTVERSION)) < 0 || amount != 1) {
 	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)",
 		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;
 		goto unshin;
 	}
 	}
 
 
 	if ((err = usb_read_once(modminer, buf, sizeof(buf)-1, &amount, C_GETVERSION)) < 0 || amount < 1) {
 	if ((err = usb_read_once(modminer, buf, sizeof(buf)-1, &amount, C_GETVERSION)) < 0 || amount < 1) {
 		if (err < 0)
 		if (err < 0)
 			applog(LOG_ERR, "%s detect (%s) no version reply (%d)",
 			applog(LOG_ERR, "%s detect (%s) no version reply (%d)",
-				modminer->drv->dname, devpath, err);
+				modminer->drv->dname, modminer->device_path, err);
 		else
 		else
 			applog(LOG_ERR, "%s detect (%s) empty version reply (%d)",
 			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",
 		applog(LOG_DEBUG, "%s detect (%s) check the firmware",
-				modminer->drv->dname, devpath);
+				modminer->drv->dname, modminer->device_path);
 
 
 		goto unshin;
 		goto unshin;
 	}
 	}
 	buf[amount] = '\0';
 	buf[amount] = '\0';
 	devname = strdup(buf);
 	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)) {
 	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)",
 		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;
 		goto unshin;
 	}
 	}
 
 
 	if ((err = usb_read(modminer, buf, 1, &amount, C_GETFPGACOUNT)) < 0 || amount != 1) {
 	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)",
 		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;
 		goto unshin;
 	}
 	}
 
 
@@ -174,18 +170,18 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
 
 
 	if (buf[0] == 0) {
 	if (buf[0] == 0) {
 		applog(LOG_ERR, "%s detect (%s) zero FPGA count from %s",
 		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;
 		goto unshin;
 	}
 	}
 
 
 	if (buf[0] < 1 || buf[0] > 4) {
 	if (buf[0] < 1 || buf[0] > 4) {
 		applog(LOG_ERR, "%s detect (%s) invalid FPGA count (%u) from %s",
 		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;
 		goto unshin;
 	}
 	}
 
 
 	applog(LOG_DEBUG, "%s (%s) %s has %u FPGAs",
 	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;
 	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;
 		tmp->modminer_mutex = modminer->modminer_mutex;
 
 
 		if (!add_cgpu(tmp)) {
 		if (!add_cgpu(tmp)) {
-			free(tmp->device_path);
-			tmp->device_path = NULL;
 			tmp = usb_free_cgpu(tmp);
 			tmp = usb_free_cgpu(tmp);
 			goto unshin;
 			goto unshin;
 		}
 		}

+ 10 - 2
usbutils.c

@@ -1423,6 +1423,8 @@ struct cgpu_info *usb_free_cgpu(struct cgpu_info *cgpu)
 	if (cgpu->drv->copy)
 	if (cgpu->drv->copy)
 		free(cgpu->drv);
 		free(cgpu->drv);
 
 
+	free(cgpu->device_path);
+
 	free(cgpu);
 	free(cgpu);
 
 
 	return NULL;
 	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_interface_descriptor *idesc;
 	const struct libusb_endpoint_descriptor *epdesc;
 	const struct libusb_endpoint_descriptor *epdesc;
 	unsigned char strbuf[STRBUFLEN+1];
 	unsigned char strbuf[STRBUFLEN+1];
+	char devpath[32];
 	char devstr[STRBUFLEN+1];
 	char devstr[STRBUFLEN+1];
 	int err, i, j, k;
 	int err, i, j, k;
 	int bad = USB_INIT_FAIL;
 	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.bus_number = libusb_get_bus_number(dev);
 	cgpu->usbinfo.device_address = libusb_get_device_address(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));
 	cgusb = calloc(1, sizeof(*cgusb));
 	if (unlikely(!cgusb))
 	if (unlikely(!cgusb))