Skip to content

Commit b4d0c33

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: sd: Fix sshdr use in sd_spinup_disk
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 <michael.christie@oracle.com> Link: https://lore.kernel.org/r/20231004210013.5601-3-michael.christie@oracle.com Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: John Garry <john.g.garry@oracle.com> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Martin Wilck <mwilck@suse.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent bd593bd commit b4d0c33

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

drivers/scsi/sd.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,19 +2180,21 @@ sd_spinup_disk(struct scsi_disk *sdkp)
21802180
sdkp->max_retries,
21812181
&exec_args);
21822182

2183-
/*
2184-
* If the drive has indicated to us that it
2185-
* doesn't have any media in it, don't bother
2186-
* with any more polling.
2187-
*/
2188-
if (media_not_present(sdkp, &sshdr)) {
2189-
if (media_was_present)
2190-
sd_printk(KERN_NOTICE, sdkp, "Media removed, stopped polling\n");
2191-
return;
2192-
}
2183+
if (the_result > 0) {
2184+
/*
2185+
* If the drive has indicated to us that it
2186+
* doesn't have any media in it, don't bother
2187+
* with any more polling.
2188+
*/
2189+
if (media_not_present(sdkp, &sshdr)) {
2190+
if (media_was_present)
2191+
sd_printk(KERN_NOTICE, sdkp,
2192+
"Media removed, stopped polling\n");
2193+
return;
2194+
}
21932195

2194-
if (the_result)
21952196
sense_valid = scsi_sense_valid(&sshdr);
2197+
}
21962198
retries++;
21972199
} while (retries < 3 &&
21982200
(!scsi_status_is_good(the_result) ||

0 commit comments

Comments
 (0)