Browse Source

Bugfix: Handle errors creating a vcom devid more gracefully

Conflicts:
	fpgautils.c
Luke Dashjr 12 years ago
parent
commit
cc342b66cb
2 changed files with 13 additions and 1 deletions
  1. 12 1
      fpgautils.c
  2. 1 0
      miner.c

+ 12 - 1
fpgautils.c

@@ -106,6 +106,8 @@ struct lowlevel_device_info *_vcom_devinfo_findorcreate(struct lowlevel_device_i
 {
 	struct lowlevel_device_info *devinfo;
 	char * const devid = _vcom_unique_id(devpath);
+	if (!devid)
+		return NULL;
 	HASH_FIND_STR(*devinfo_list, devid, devinfo);
 	if (!devinfo)
 	{
@@ -210,7 +212,7 @@ void _vcom_devinfo_scan_devserial(struct lowlevel_device_info ** const devinfo_l
 			continue;
 		strcpy(devfile, de->d_name);
 		devinfo = _vcom_devinfo_findorcreate(devinfo_list, devpath);
-		if (!(devinfo->manufacturer || devinfo->product || devinfo->serial))
+		if (devinfo && !(devinfo->manufacturer || devinfo->product || devinfo->serial))
 			devinfo->product = strdup(devfile);
 	}
 	closedir(D);
@@ -273,6 +275,8 @@ void _sysfs_find_tty(char *devpath, char *devfile, const char *prod, struct lowl
 		
 		strcpy(&ttybuf[5], de->d_name);
 		devinfo = _vcom_devinfo_findorcreate(devinfo_list, ttybuf);
+		if (!devinfo)
+			continue;
 		BFGINIT(devinfo->manufacturer, maybe_strdup(_sysfs_do_read(manuf, sizeof(manuf), devpath, devfile, "/manufacturer")));
 		BFGINIT(devinfo->product, maybe_strdup(prod));
 		BFGINIT(devinfo->serial, maybe_strdup(_sysfs_do_read(serial, sizeof(serial), devpath, devfile, "/serial")));
@@ -460,6 +464,11 @@ out:
 	}
 	
 	devinfo = _vcom_devinfo_findorcreate(devinfo_list, devpath);
+	if (!devinfo)
+	{
+		free(serial);
+		return;
+	}
 	BFGINIT(devinfo->manufacturer, windows_usb_get_string(hubh, portno, devdesc->iManufacturer));
 	BFGINIT(devinfo->product, windows_usb_get_string(hubh, portno, devdesc->iProduct));
 	if (devinfo->serial)
@@ -636,6 +645,8 @@ void _vcom_devinfo_scan_ftdi(struct lowlevel_device_info ** const devinfo_list)
 		sprintf(devpathnum, "%d", (int)lComPortNumber);
 		
 		devinfo = _vcom_devinfo_findorcreate(devinfo_list, devpath);
+		if (!devinfo)
+			continue;
 		BFGINIT(devinfo->product, (bufptrs[i] && bufptrs[i][0]) ? strdup(bufptrs[i]) : NULL);
 		BFGINIT(devinfo->serial, maybe_strdup(_ftdi_get_string(serial, i, FT_OPEN_BY_SERIAL_NUMBER)));
 	}

+ 1 - 0
miner.c

@@ -914,6 +914,7 @@ tryagain: ;
 		if (strncmp("COM", t, 3))
 			continue;
 		memcpy(devp, t, tLen);
+		// NOTE: We depend on _vcom_devinfo_findorcreate to further check that there's a number (and only a number) on the end
 		_vcom_devinfo_findorcreate(devinfo_list, dev);
 	}
 }