lkml.org 
[lkml]   [2021]   [Sep]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL 5.10 11/23] scsi: sd: Free scsi_disk device via put_device()
    Date
    From: Ming Lei <ming.lei@redhat.com>

    [ Upstream commit 265dfe8ebbabae7959060bd1c3f75c2473b697ed ]

    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>
    ---
    drivers/scsi/sd.c | 9 +++++----
    1 file changed, 5 insertions(+), 4 deletions(-)

    diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
    index f0c0935d7909..56e291708587 100644
    --- a/drivers/scsi/sd.c
    +++ b/drivers/scsi/sd.c
    @@ -3443,15 +3443,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);
    --
    2.33.0
    \
     
     \ /
      Last update: 2021-09-28 08:00    [W:4.046 / U:1.192 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site