mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] isa: put_device after failing to device_register
@ 2022-06-14 14:57 Zhi Song
  2022-06-14 15:13 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Zhi Song @ 2022-06-14 14:57 UTC (permalink / raw)
  To: vilhelm.gray, gregkh, rafael; +Cc: linux-kernel, Zhi Song

device_register() is used to register a device with the system.

We cannot directly free dev after calling this function,
even if it returns an error.

We should use put_device() to give up the reference
initialized in this function instead.

Signed-off-by: Zhi Song <zhi.song@bytedance.com>
---
 drivers/base/isa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/isa.c b/drivers/base/isa.c
index 55e3ee2da98f..cf88f3d77b7d 100644
--- a/drivers/base/isa.c
+++ b/drivers/base/isa.c
@@ -173,8 +173,10 @@ static int __init isa_bus_init(void)
 	error = bus_register(&isa_bus_type);
 	if (!error) {
 		error = device_register(&isa_bus);
-		if (error)
+		if (error) {
+			put_device(&isa_bus);
 			bus_unregister(&isa_bus_type);
+		}
 	}
 	return error;
 }
-- 
2.30.2


^ permalink raw reply	[flat|nested] 4+ messages in thread
* [PATCH] isa: put_device after failing to device_register
@ 2022-06-14 16:01 Zhi Song
  2022-06-14 16:07 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Zhi Song @ 2022-06-14 16:01 UTC (permalink / raw)
  To: vilhelm.gray, gregkh, rafael; +Cc: linux-kernel, Zhi Song

device_register() is used to register a device with the system.
We need to call put_device() to give up the reference initialized
in device_register() when it returns an error and this will clean
up correctly.

Signed-off-by: Zhi Song <zhi.song@bytedance.com>
---
 drivers/base/isa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/isa.c b/drivers/base/isa.c
index 55e3ee2da98f..cf88f3d77b7d 100644
--- a/drivers/base/isa.c
+++ b/drivers/base/isa.c
@@ -173,8 +173,10 @@ static int __init isa_bus_init(void)
 	error = bus_register(&isa_bus_type);
 	if (!error) {
 		error = device_register(&isa_bus);
-		if (error)
+		if (error) {
+			put_device(&isa_bus);
 			bus_unregister(&isa_bus_type);
+		}
 	}
 	return error;
 }
-- 
2.30.2


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

end of thread, other threads:[~2022-06-14 16:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-14 14:57 [PATCH] isa: put_device after failing to device_register Zhi Song
2022-06-14 15:13 ` Greg KH
2022-06-14 16:01 Zhi Song
2022-06-14 16:07 ` Greg KH

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®