Skip to content

Commit c8b7ef3

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: sd: Fix sshdr use in cache_type_store
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 8f00176 commit c8b7ef3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/scsi/sd.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
143143
struct scsi_mode_data data;
144144
struct scsi_sense_hdr sshdr;
145145
static const char temp[] = "temporary ";
146-
int len;
146+
int len, ret;
147147

148148
if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC)
149149
/* no cache control on RBC devices; theoretically they
@@ -190,9 +190,10 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
190190
*/
191191
data.device_specific = 0;
192192

193-
if (scsi_mode_select(sdp, 1, sp, buffer_data, len, SD_TIMEOUT,
194-
sdkp->max_retries, &data, &sshdr)) {
195-
if (scsi_sense_valid(&sshdr))
193+
ret = scsi_mode_select(sdp, 1, sp, buffer_data, len, SD_TIMEOUT,
194+
sdkp->max_retries, &data, &sshdr);
195+
if (ret) {
196+
if (ret > 0 && scsi_sense_valid(&sshdr))
196197
sd_print_sense_hdr(sdkp, &sshdr);
197198
return -EINVAL;
198199
}

0 commit comments

Comments
 (0)