2022-06-14 16:50:13

by Zhi Song

[permalink] [raw]
Subject: [PATCH v2] isa: put_device after failing to device_register

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 <[email protected]>
---
V1 -> V2: Fix up the changelog text correct.
---
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


2022-06-15 11:40:02

by William Breathitt Gray

[permalink] [raw]
Subject: Re: [PATCH v2] isa: put_device after failing to device_register

On Wed, Jun 15, 2022 at 12:47:10AM +0800, Zhi Song wrote:
> 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 <[email protected]>

Hi Zhi,

Would you add a Fixes tag line specifying the commit where this bug was
introduced. That will help us get this fix into previous kernel versions
as well.

Thanks,

William Breathitt Gray

> ---
> V1 -> V2: Fix up the changelog text correct.
> ---
> 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
>


Attachments:
(No filename) (1.15 kB)
signature.asc (235.00 B)
Download all attachments