Skip to content

Commit f43158e

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: Fix sshdr use in scsi_test_unit_ready
If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0. Signed-off-by: Mike Christie <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: John Garry <[email protected]> Reviewed-by: Martin Wilck <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent add2c24 commit f43158e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,10 +2299,10 @@ scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries,
22992299
do {
23002300
result = scsi_execute_cmd(sdev, cmd, REQ_OP_DRV_IN, NULL, 0,
23012301
timeout, 1, &exec_args);
2302-
if (sdev->removable && scsi_sense_valid(sshdr) &&
2302+
if (sdev->removable && result > 0 && scsi_sense_valid(sshdr) &&
23032303
sshdr->sense_key == UNIT_ATTENTION)
23042304
sdev->changed = 1;
2305-
} while (scsi_sense_valid(sshdr) &&
2305+
} while (result > 0 && scsi_sense_valid(sshdr) &&
23062306
sshdr->sense_key == UNIT_ATTENTION && --retries);
23072307

23082308
return result;

0 commit comments

Comments
 (0)