[v5,13/13] scsi: ch: need to check whether sshdr is valid in ch_do_scsi
diff mbox series

Message ID 1571387071-28853-14-git-send-email-zhengbin13@huawei.com
State Changes Requested
Headers show
Series
  • scsi: core: fix uninit-value access of variable sshdr
Related show

Commit Message

zhengbin Oct. 18, 2019, 8:24 a.m. UTC
Like sd_pr_command, before use sshdr, we need to check whether
sshdr is valid.

Signed-off-by: zhengbin <zhengbin13@huawei.com>
---
 drivers/scsi/ch.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--
2.7.4

Patch
diff mbox series

diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 76751d6..dba6fe2 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -200,7 +200,7 @@  ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
 				  buflength, &sshdr, timeout * HZ,
 				  MAX_RETRIES, NULL);

-	if (driver_byte(result) == DRIVER_SENSE) {
+	if (driver_byte(result) == DRIVER_SENSE && scsi_sense_valid(&sshdr)) {
 		if (debug)
 			scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
 		errno = ch_find_errno(&sshdr);
@@ -212,7 +212,9 @@  ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
 				goto retry;
 			break;
 		}
-	}
+	} else if (result)
+		errno = -EIO;
+
 	return errno;
 }