[PATCH] isa: put_device after failing to device_register

Zhi Song posted 1 patch 3 years, 10 months ago
There is a newer version of this series
drivers/base/isa.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] isa: put_device after failing to device_register
Posted by Zhi Song 3 years, 10 months ago
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
Re: [PATCH] isa: put_device after failing to device_register
Posted by Greg KH 3 years, 10 months ago
On Tue, Jun 14, 2022 at 10:57:57PM +0800, Zhi Song wrote:
> 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.

Same comments on this one as my last review.

greg k-h