* [PATCH] scsi: sd: free 'scsi_disk' device via put_device
@ 2021-09-06 9:01 Ming Lei
2021-09-07 0:30 ` Bart Van Assche
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ming Lei @ 2021-09-06 9:01 UTC (permalink / raw)
To: Martin K . Petersen, linux-scsi; +Cc: Ming Lei
Once the device is initialized via device_initialize(), it should be
freed via put_device, so fix it. Meantime get the parent before adding
device, the release handler can work as expected always.
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
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 cbd9999f93a6..a8039beb5a02 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3401,15 +3401,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.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: sd: free 'scsi_disk' device via put_device
2021-09-06 9:01 [PATCH] scsi: sd: free 'scsi_disk' device via put_device Ming Lei
@ 2021-09-07 0:30 ` Bart Van Assche
2021-09-07 6:53 ` Christoph Hellwig
2021-09-14 3:43 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2021-09-07 0:30 UTC (permalink / raw)
To: Ming Lei, Martin K . Petersen, linux-scsi
On 9/6/21 02:01, Ming Lei wrote:
> Once the device is initialized via device_initialize(), it should be
> freed via put_device, so fix it. Meantime get the parent before adding
> device, the release handler can work as expected always.
Since we are in the middle of the merge window this is probably not the
best time to post patches. Anyway:
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: sd: free 'scsi_disk' device via put_device
2021-09-06 9:01 [PATCH] scsi: sd: free 'scsi_disk' device via put_device Ming Lei
2021-09-07 0:30 ` Bart Van Assche
@ 2021-09-07 6:53 ` Christoph Hellwig
2021-09-14 3:43 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2021-09-07 6:53 UTC (permalink / raw)
To: Ming Lei; +Cc: Martin K . Petersen, linux-scsi
On Mon, Sep 06, 2021 at 05:01:12PM +0800, Ming Lei wrote:
> Once the device is initialized via device_initialize(), it should be
> freed via put_device, so fix it. Meantime get the parent before adding
> device, the release handler can work as expected always.
>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: sd: free 'scsi_disk' device via put_device
2021-09-06 9:01 [PATCH] scsi: sd: free 'scsi_disk' device via put_device Ming Lei
2021-09-07 0:30 ` Bart Van Assche
2021-09-07 6:53 ` Christoph Hellwig
@ 2021-09-14 3:43 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2021-09-14 3:43 UTC (permalink / raw)
To: Ming Lei, linux-scsi; +Cc: Martin K . Petersen
On Mon, 6 Sep 2021 17:01:12 +0800, Ming Lei wrote:
> Once the device is initialized via device_initialize(), it should be
> freed via put_device, so fix it. Meantime get the parent before adding
> device, the release handler can work as expected always.
>
>
Applied to 5.15/scsi-fixes, thanks!
[1/1] scsi: sd: free 'scsi_disk' device via put_device
https://git.kernel.org/mkp/scsi/c/265dfe8ebbab
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-14 3:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06 9:01 [PATCH] scsi: sd: free 'scsi_disk' device via put_device Ming Lei
2021-09-07 0:30 ` Bart Van Assche
2021-09-07 6:53 ` Christoph Hellwig
2021-09-14 3:43 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).