diff mbox

[2/4] sd: Check if parent is still present before proceeding with probing

Message ID 1513069072-32514-3-git-send-email-hare@suse.de (mailing list archive)
State Changes Requested
Headers show

Commit Message

Hannes Reinecke Dec. 12, 2017, 8:57 a.m. UTC
When a new SCSI disk is created we should be checking if the parent
device is actually present before proceeding with probing.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/sd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Bart Van Assche Dec. 14, 2017, 10:02 p.m. UTC | #1
On Tue, 2017-12-12 at 09:57 +0100, Hannes Reinecke wrote:
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c

> index ab75ebd..228b0b62 100644

> --- a/drivers/scsi/sd.c

> +++ b/drivers/scsi/sd.c

> @@ -3399,6 +3399,10 @@ static int sd_probe(struct device *dev)

>  	}

>  

>  	device_initialize(&sdkp->dev);

> +

> +	if (!get_device(dev))

> +		goto out_free_index;


get_device(dev) returns the value of the 'dev' argument. Are you sure the
if-test is useful? Did you perhaps want to check sdp->sdev_state like
scsi_device_get() does?

>  	sdkp->dev.parent = dev;

>  	sdkp->dev.class = &sd_disk_class;

>  	dev_set_name(&sdkp->dev, "%s", dev_name(dev));

> @@ -3407,7 +3411,6 @@ static int sd_probe(struct device *dev)

>  	if (error)

>  		goto out_free_index;

>  

> -	get_device(dev);

>  	dev_set_drvdata(dev, sdkp);

>  

>  	get_device(&sdkp->dev);	/* prevent release before async_schedule */


Since the get_device() call has been moved up, are there any error paths that
have to be adjusted?

Bart.
diff mbox

Patch

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index ab75ebd..228b0b62 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3399,6 +3399,10 @@  static int sd_probe(struct device *dev)
 	}
 
 	device_initialize(&sdkp->dev);
+
+	if (!get_device(dev))
+		goto out_free_index;
+
 	sdkp->dev.parent = dev;
 	sdkp->dev.class = &sd_disk_class;
 	dev_set_name(&sdkp->dev, "%s", dev_name(dev));
@@ -3407,7 +3411,6 @@  static int sd_probe(struct device *dev)
 	if (error)
 		goto out_free_index;
 
-	get_device(dev);
 	dev_set_drvdata(dev, sdkp);
 
 	get_device(&sdkp->dev);	/* prevent release before async_schedule */