From c3eedf65671ea82704e68e4b69796d7067170815 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Mon, 6 Jul 2009 14:54:52 +0100 Subject: [PATCH] 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 --- extras/scsi_id/scsi_serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/scsi_id/scsi_serial.c b/extras/scsi_id/scsi_serial.c index 68bed0824..424882918 100644 --- a/extras/scsi_id/scsi_serial.c +++ b/extras/scsi_id/scsi_serial.c @@ -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; } -- 2.30.2