Skip to content

Commit

Permalink
scsi: sd: Free scsi_disk device via put_device()
Browse files Browse the repository at this point in the history
[ Upstream commit 265dfe8 ]

After a device is initialized via device_initialize() it should be freed
via put_device(). sd_probe() currently gets this wrong, fix it up.

Link: https://lore.kernel.org/r/20210906090112.531442-1-ming.lei@redhat.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Ming Lei authored and Greg Kroah-Hartman committed Oct 9, 2021
1 parent aae02f8 commit a3e5a92
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3179,15 +3179,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);

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

0 comments on commit a3e5a92

Please sign in to comment.