scsi: sd: Fix sshdr use in sd_suspend_common()
authorMike Christie <michael.christie@oracle.com>
Mon, 6 Nov 2023 23:13:04 +0000 (17:13 -0600)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 9 Nov 2023 02:46:58 +0000 (21:46 -0500)
commit3b83486399a6a9feb9c681b74c21a227d48d7020
treeaef166e064a809e1bc0c18cdf6f8df52693e3df7
parent037fbd3fcfbd99145f9310d93f6637012807cfd0
scsi: sd: Fix sshdr use in sd_suspend_common()

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. sd_sync_cache() will
only access the sshdr if it's been setup because it calls
scsi_status_is_check_condition() before accessing it. However, the
sd_sync_cache() caller, sd_suspend_common(), does not check.

sd_suspend_common() is only checking for ILLEGAL_REQUEST which it's using
to determine if the command is supported. If it's not it just ignores the
error. So to fix its sshdr use this patch just moves that check to
sd_sync_cache() where it converts ILLEGAL_REQUEST to success/0.
sd_suspend_common() was ignoring that error and sd_shutdown() doesn't check
for errors so there will be no behavior changes.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231106231304.5694-2-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/sd.c