Skip to content

Commit f7d7129

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: sr: Fix sshdr use in sr_get_events
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 c8b7ef3 commit f7d7129

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/scsi/sr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ static unsigned int sr_get_events(struct scsi_device *sdev)
177177

178178
result = scsi_execute_cmd(sdev, cmd, REQ_OP_DRV_IN, buf, sizeof(buf),
179179
SR_TIMEOUT, MAX_RETRIES, &exec_args);
180-
if (scsi_sense_valid(&sshdr) && sshdr.sense_key == UNIT_ATTENTION)
180+
if (result > 0 && scsi_sense_valid(&sshdr) &&
181+
sshdr.sense_key == UNIT_ATTENTION)
181182
return DISK_EVENT_MEDIA_CHANGE;
182183

183184
if (result || be16_to_cpu(eh->data_len) < sizeof(*med))

0 commit comments

Comments
 (0)