All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] isa: put_device after failing to device_register
@ 2022-06-15 15:15 Zhi Song
  2022-06-15 22:03 ` William Breathitt Gray
  2022-06-27 14:06 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Zhi Song @ 2022-06-15 15:15 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.

Fixes: a5117ba7da37 ("Driver model: add ISA bus")
Signed-off-by: Zhi Song <zhi.song@bytedance.com>
---
V1 -> V2: Fix up the changelog text correct.
V2 -> V3: Add a fixes tag line specifying the commit where this bug was
introduced.
---
 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 related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] isa: put_device after failing to device_register
  2022-06-15 15:15 [PATCH v3] isa: put_device after failing to device_register Zhi Song
@ 2022-06-15 22:03 ` William Breathitt Gray
  2022-06-27 14:06 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: William Breathitt Gray @ 2022-06-15 22:03 UTC (permalink / raw)
  To: Zhi Song; +Cc: vilhelm.gray, gregkh, rafael, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1175 bytes --]

On Wed, Jun 15, 2022 at 11:15:58PM +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.
> 
> Fixes: a5117ba7da37 ("Driver model: add ISA bus")
> Signed-off-by: Zhi Song <zhi.song@bytedance.com>

Acked-by: William Breathitt Gray <william.gray@linaro.org>

> ---
> V1 -> V2: Fix up the changelog text correct.
> V2 -> V3: Add a fixes tag line specifying the commit where this bug was
> introduced.
> ---
>  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
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH v3] isa: put_device after failing to device_register
  2022-06-15 15:15 [PATCH v3] isa: put_device after failing to device_register Zhi Song
  2022-06-15 22:03 ` William Breathitt Gray
@ 2022-06-27 14:06 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2022-06-27 14:06 UTC (permalink / raw)
  To: Zhi Song; +Cc: vilhelm.gray, rafael, linux-kernel

On Wed, Jun 15, 2022 at 11:15:58PM +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.
> 
> Fixes: a5117ba7da37 ("Driver model: add ISA bus")
> Signed-off-by: Zhi Song <zhi.song@bytedance.com>
> ---
> V1 -> V2: Fix up the changelog text correct.
> V2 -> V3: Add a fixes tag line specifying the commit where this bug was
> introduced.
> ---
>  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);

Did you test this change and notice the kernel log error that happens
when you run it?

If you can really reproduce this in a real-life situation, you need to
do more than just this change.

thanks,

greg k-h

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15 15:15 [PATCH v3] isa: put_device after failing to device_register Zhi Song
2022-06-15 22:03 ` William Breathitt Gray
2022-06-27 14:06 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.