mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: sd: unregister device if device_add_disk() failed in sd_probe()
@ 2023-12-08  8:23 linan666
  2023-12-22  6:49 ` Luis Chamberlain
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: linan666 @ 2023-12-08  8:23 UTC (permalink / raw)
  To: jejb, martin.petersen, mcgrof
  Cc: linux-scsi, linux-kernel, linan122, yukuai3, yi.zhang, houtao1,
	yangerkun

From: Li Nan <linan122@huawei.com>

"if device_add() succeeds, you should call device_del() when you want to
get rid of it."

In sd_probe(), device_add_disk() fails when device_add() has already
succeeded, so change put_device() to device_unregister() to ensure device
resources are released.

Fixes: 2a7a891f4c40 ("scsi: sd: Add error handling support for add_disk()")
Signed-off-by: Li Nan <linan122@huawei.com>
---
 drivers/scsi/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 542a4bbb21bc..d81cbeee06eb 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3736,7 +3736,7 @@ static int sd_probe(struct device *dev)
 
 	error = device_add_disk(dev, gd, NULL);
 	if (error) {
-		put_device(&sdkp->disk_dev);
+		device_unregister(&sdkp->disk_dev);
 		put_disk(gd);
 		goto out;
 	}
-- 
2.39.2


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-04-02  1:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-08  8:23 [PATCH] scsi: sd: unregister device if device_add_disk() failed in sd_probe() linan666
2023-12-22  6:49 ` Luis Chamberlain
2023-12-22  8:27   ` Yu Kuai
2024-01-29 17:46     ` Luis Chamberlain
2024-01-30  1:30       ` Yu Kuai
2024-01-29 13:26 ` Li Nan
2024-02-22  9:24 ` Li Nan
2024-04-01  1:31 ` Yu Kuai
2024-04-01 17:51   ` Bart Van Assche
2024-04-02  0:16     ` Damien Le Moal
2024-04-01 17:49 ` Bart Van Assche
2024-04-02  1:48 ` 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

all inboxes | Powered by JetHome®