]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blobdiff - drivers/scsi/sd.c
Merge tag 'for-5.16/block-2021-10-29' of git://git.kernel.dk/linux-block
[mirror_ubuntu-kernels.git] / drivers / scsi / sd.c
index cbd9999f93a6b2a08c5f625b2184a21dd8bbb407..9bdee968d3b57d3acb31e00c673d9dd1d8437b52 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/blkpg.h>
 #include <linux/blk-pm.h>
 #include <linux/delay.h>
+#include <linux/major.h>
 #include <linux/mutex.h>
 #include <linux/string_helpers.h>
 #include <linux/async.h>
@@ -2124,6 +2125,8 @@ sd_spinup_disk(struct scsi_disk *sdkp)
                retries = 0;
 
                do {
+                       bool media_was_present = sdkp->media_present;
+
                        cmd[0] = TEST_UNIT_READY;
                        memset((void *) &cmd[1], 0, 9);
 
@@ -2138,7 +2141,8 @@ sd_spinup_disk(struct scsi_disk *sdkp)
                         * with any more polling.
                         */
                        if (media_not_present(sdkp, &sshdr)) {
-                               sd_printk(KERN_NOTICE, sdkp, "Media removed, stopped polling\n");
+                               if (media_was_present)
+                                       sd_printk(KERN_NOTICE, sdkp, "Media removed, stopped polling\n");
                                return;
                        }
 
@@ -3401,15 +3405,16 @@ static int sd_probe(struct device *dev)
        }
 
        device_initialize(&sdkp->dev);
-       sdkp->dev.parent = dev;
+       sdkp->dev.parent = get_device(dev);
        sdkp->dev.class = &sd_disk_class;
        dev_set_name(&sdkp->dev, "%s", dev_name(dev));
 
        error = device_add(&sdkp->dev);
-       if (error)
-               goto out_free_index;
+       if (error) {
+               put_device(&sdkp->dev);
+               goto out;
+       }
 
-       get_device(dev);
        dev_set_drvdata(dev, sdkp);
 
        gd->major = sd_major((index & 0xf0) >> 4);
@@ -3679,7 +3684,12 @@ static int sd_resume(struct device *dev)
 static int sd_resume_runtime(struct device *dev)
 {
        struct scsi_disk *sdkp = dev_get_drvdata(dev);
-       struct scsi_device *sdp = sdkp->device;
+       struct scsi_device *sdp;
+
+       if (!sdkp)      /* E.g.: runtime resume at the start of sd_probe() */
+               return 0;
+
+       sdp = sdkp->device;
 
        if (sdp->ignore_media_change) {
                /* clear the device's sense data */