[PATCH] Use a better comparitor for scsi vendor/model table matching.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Previously we were using strncmp in order to avoid having to include
whitespace in the devlist, but this means "HSV1000" matches a device
list entry that says "HSV100", which is wrong.  This patch adds
scsi_dh_strcmp(), which checks that any trailing characters in string 2
are the pad character 0x20.
---
 drivers/scsi/device_handler/scsi_dh.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/device_handler/scsi_dh.c b/drivers/scsi/device_handler/scsi_dh.c
index 6fae3d2..ec2eafb 100644
--- a/drivers/scsi/device_handler/scsi_dh.c
+++ b/drivers/scsi/device_handler/scsi_dh.c
@@ -71,16 +71,31 @@ scsi_dh_cache_lookup(struct scsi_device *sdev)
 	return found_dh;
 }
 
+static int scsi_dh_strcmp(const char *a, const char *b)
+{
+	int blen = strlen(b);
+	int rc = strncmp(a, b, blen);
+	int i;
+
+	if (rc != 0)
+		return rc;
+
+	for (i = blen; a[i] != '\0'; i++) {
+		if (a[i] != ' ') {
+			return a[blen] < b[blen] ? -1 : 1;
+		}
+	}
+	return 0;
+}
+
 static int scsi_dh_handler_lookup(struct scsi_device_handler *scsi_dh,
 				  struct scsi_device *sdev)
 {
 	int i, found = 0;
 
 	for(i = 0; scsi_dh->devlist[i].vendor; i++) {
-		if (!strncmp(sdev->vendor, scsi_dh->devlist[i].vendor,
-			     strlen(scsi_dh->devlist[i].vendor)) &&
-		    !strncmp(sdev->model, scsi_dh->devlist[i].model,
-			     strlen(scsi_dh->devlist[i].model))) {
+		if (!scsi_dh_strcmp(sdev->vendor, scsi_dh->devlist[i].vendor) &&
+		    !scsi_dh_strcmp(sdev->model, scsi_dh->devlist[i].model)) {
 			found = 1;
 			break;
 		}
-- 
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux