Skip to content

Commit

Permalink
sd: get disk reference in sd_check_events()
Browse files Browse the repository at this point in the history
sd_check_events() is called asynchronously, and might race
with device removal. So always take a disk reference when
processing the event to avoid the device being removed while
the event is processed.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Ewan D. Milne <emilne@redhat.com>
Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Hannes Reinecke authored and Martin K. Petersen committed May 22, 2016
1 parent a621bac commit eb72d0b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1398,11 +1398,15 @@ static int media_not_present(struct scsi_disk *sdkp,
**/
static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
{
struct scsi_disk *sdkp = scsi_disk(disk);
struct scsi_device *sdp = sdkp->device;
struct scsi_disk *sdkp = scsi_disk_get(disk);
struct scsi_device *sdp;
struct scsi_sense_hdr *sshdr = NULL;
int retval;

if (!sdkp)
return 0;

sdp = sdkp->device;
SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_check_events\n"));

/*
Expand Down Expand Up @@ -1459,6 +1463,7 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
kfree(sshdr);
retval = sdp->changed ? DISK_EVENT_MEDIA_CHANGE : 0;
sdp->changed = 0;
scsi_disk_put(sdkp);
return retval;
}

Expand Down

0 comments on commit eb72d0b

Please sign in to comment.