chiark / gitweb /
scsi_id: correct error handling in prepend_vendor_model
authorIan Campbell <Ian.Campbell@citrix.com>
Mon, 6 Jul 2009 13:54:52 +0000 (14:54 +0100)
committerKay Sievers <kay.sievers@vrfy.org>
Mon, 6 Jul 2009 14:21:08 +0000 (16:21 +0200)
The callers of prepend_vendor_model both expect < 0 to be returned on
error and the index to be returned otherwise. However
prepend_vendor_model actually returns 1 on error. Fix this by correctly
returning -1.

Older kernels (before e5b3cd42: "SCSI: sanitize INQUIRY strings")
truncated the model field in sysfs (or propagated bad results from the
target) to less than the expected/required 16 characters which meant
that the SCSI id was mangled into:
        # /sbin/scsi_id -g -s /block/sdg
        S146cee20VIRTUAL-DISK
when it should have been:
        # /sbin/scsi_id -g -s /block/sdg
        SIET     VIRTUAL-DISK   146cee20

Notice how the serial number has been pasted over the vendor+model at
index 1 instead of being added at the end.

In the former case:
        # cat /sys/devices/platform/host5/session1/target5:0:0/5:0:0:1/model | od -t c -t x1
        0000000   V   I   R   T   U   A   L   -   D   I   S   K  \n
                56 49 52 54 55 41 4c 2d 44 49 53 4b 0a
But it should have been:
        # cat /sys/devices/platform/host5/session1/target5:0:0/5:0:0:1/model | od -t c -t x1
        0000000   V   I   R   T   U   A   L   -   D   I   S   K
                56 49 52 54 55 41 4c 2d 44 49 53 4b 20 20 20 20
        0000020  \n
                0a

Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
extras/scsi_id/scsi_serial.c

index 68bed082415666261c75bd2dabc0df09b933a009..4248829180b36475f519f775d3377a19a16d2033 100644 (file)
@@ -467,7 +467,7 @@ static int prepend_vendor_model(struct udev *udev,
        if (ind != (VENDOR_LENGTH + MODEL_LENGTH)) {
                info(udev, "%s: expected length %d, got length %d\n",
                     dev_scsi->kernel, (VENDOR_LENGTH + MODEL_LENGTH), ind);
-               return 1;
+               return -1;
        }
        return ind;
 }