* [PATCH] Use a better comparitor for scsi vendor/model table matching.
@ 2011-01-05 15:39 Peter Jones
2011-01-05 16:36 ` James Bottomley
0 siblings, 1 reply; 3+ messages in thread
From: Peter Jones @ 2011-01-05 15:39 UTC (permalink / raw)
To: James Bottomley; +Cc: Tejun Heo, Linux SCSI, Peter Jones
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Use a better comparitor for scsi vendor/model table matching.
2011-01-05 15:39 [PATCH] Use a better comparitor for scsi vendor/model table matching Peter Jones
@ 2011-01-05 16:36 ` James Bottomley
2011-01-05 16:50 ` Peter Jones
0 siblings, 1 reply; 3+ messages in thread
From: James Bottomley @ 2011-01-05 16:36 UTC (permalink / raw)
To: Peter Jones; +Cc: Tejun Heo, Linux SCSI
On Wed, 2011-01-05 at 10:39 -0500, Peter Jones wrote:
> 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.
Hmm, the cockup comes from dh rolling its own comparators. Could you
just convert it to use the standard ones in scsi_devinfo.c? There's an
example of how to do this in scsi_transport_spi.c
James
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Use a better comparitor for scsi vendor/model table matching.
2011-01-05 16:36 ` James Bottomley
@ 2011-01-05 16:50 ` Peter Jones
0 siblings, 0 replies; 3+ messages in thread
From: Peter Jones @ 2011-01-05 16:50 UTC (permalink / raw)
To: James Bottomley; +Cc: Tejun Heo, Linux SCSI
On 01/05/2011 11:36 AM, James Bottomley wrote:
> On Wed, 2011-01-05 at 10:39 -0500, Peter Jones wrote:
>> 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.
>
> Hmm, the cockup comes from dh rolling its own comparators. Could you
> just convert it to use the standard ones in scsi_devinfo.c? There's an
> example of how to do this in scsi_transport_spi.c
Oh, sure. Thanks for the pointer.
--
Peter
THE MAGIC WORDS ARE SQUEAMISH OSSIFRAGE
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-01-05 16:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-05 15:39 [PATCH] Use a better comparitor for scsi vendor/model table matching Peter Jones
2011-01-05 16:36 ` James Bottomley
2011-01-05 16:50 ` Peter Jones
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.