From: Hannes Reinecke Date: Tue, 26 Apr 2016 06:06:58 +0000 (+0200) Subject: sd: get disk reference in sd_check_events() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1ba4fc4b0772b130c3acc9cd377f3039b9b24f8f;p=GitHub%2Fmt8127%2Fandroid_kernel_alcatel_ttab.git sd: get disk reference in sd_check_events() commit eb72d0bb84eee5d0dc3044fd17b75e7101dabb57 upstream. 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 Reviewed-by: Ewan D. Milne Reviewed-by: Bart Van Assche Signed-off-by: Martin K. Petersen Cc: Jinpu Wang Signed-off-by: Jiri Slaby Signed-off-by: Willy Tarreau --- diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 749893e145e4..880a300baf7a 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1354,11 +1354,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")); /* @@ -1415,6 +1419,7 @@ out: kfree(sshdr); retval = sdp->changed ? DISK_EVENT_MEDIA_CHANGE : 0; sdp->changed = 0; + scsi_disk_put(sdkp); return retval; }