]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
imsm: fix reading scsi serial
authorArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Thu, 2 Nov 2017 15:10:57 +0000 (16:10 +0100)
committerJes Sorensen <jsorensen@fb.com>
Thu, 2 Nov 2017 15:33:09 +0000 (11:33 -0400)
Improve error detection after SG_IO ioctl. Checking only the return
value and response length is insufficient and leads to anomalies if a
drive does not have a serial number.

Reported-by: NeilBrown <neilb@suse.com>
Tested-by: NeilBrown <neilb@suse.com>
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
sg_io.c

diff --git a/sg_io.c b/sg_io.c
index 42c91e1e9c6be4deb7a96d7a78c0c29dd9aaaa01..7889a95ecae4dbead43c1e1b866277152924ca49 100644 (file)
--- a/sg_io.c
+++ b/sg_io.c
@@ -46,6 +46,9 @@ int scsi_get_serial(int fd, void *buf, size_t buf_len)
        if (rv)
                return rv;
 
+       if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
+               return -1;
+
        rsp_len = rsp_buf[3];
 
        if (!rsp_len || buf_len < rsp_len)