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)
commitc3eedf65671ea82704e68e4b69796d7067170815
tree96829bcf2a1cd009bf2f90f09786d35ff2680866
parent739ce84bfae2734e741a7fe94d4fa8af4903c050
scsi_id: correct error handling in prepend_vendor_model

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