From 607cfe6f4776093ad72fa3149318cf8ce8124bef Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Thu, 15 Oct 2015 17:40:34 +0800 Subject: [PATCH] ID:394 - plugins/usb: Fix probe for SCSI devices The current USB plugin doesn't find my IPMI channel: # ipmitool -I usb mc info Error in USB session setup Unable to setup interface usb Error loading interface usb This is beacuse I have more than 8 scsi-generic devices that identify as AMI: # grep -c ^AMI /proc/scsi/sg/device_strs 13 So we end up hitting the max in FindG2CDROM, and abort without finding the actual IPMI endpoint (on my system, this is /dev/sg11). This change bumps that maximum up to 16. However, that means we hit another bug in scsiProbeNew, where if we hit the end of the file without completely filling the array, we return with an error. This change handles the EOF condition gracefully instead. Also, fp is never going to become NULL; we don't need to check for that condition. Signed-off-by: Jeremy Kerr --- src/plugins/usb/usb.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/plugins/usb/usb.c b/src/plugins/usb/usb.c index 2d768de..888d81d 100644 --- a/src/plugins/usb/usb.c +++ b/src/plugins/usb/usb.c @@ -131,11 +131,7 @@ scsiProbeNew(int *num_ami_devices, int *sg_nos) while (1) { /* Read line by line and search for "AMI" */ if (fgets(linebuf, 80, fp) == NULL) { - if (fp != NULL) { - fclose(fp); - } - /* Return 1 on error */ - return 1; + break; } if (sscanf(linebuf, "%s", vendor) == 1) { @@ -151,9 +147,7 @@ scsiProbeNew(int *num_ami_devices, int *sg_nos) } *num_ami_devices = numdevfound; - if (fp != NULL) { - fclose(fp); - } + fclose(fp); return 0; } @@ -268,8 +262,8 @@ FindG2CDROM(struct ipmi_intf *intf) { int err = 0; char device[256]; - int devarray[8]; - int numdev = 8; + int devarray[16]; + int numdev = 16; int iter; err = scsiProbeNew(&numdev, devarray);