[PATCH] PNP: add a error handling in pnpacpi_init()

Haoxiang Li posted 1 patch 1 month, 3 weeks ago
drivers/pnp/pnpacpi/core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] PNP: add a error handling in pnpacpi_init()
Posted by Haoxiang Li 1 month, 3 weeks ago
Add a error handling for pnp_register_protocol(), and if
it fails, call put_device() to drop the device reference.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
---
 drivers/pnp/pnpacpi/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index a0927081a003..0b63e1748b7c 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -304,7 +304,10 @@ static int __init pnpacpi_init(void)
 		return 0;
 	}
 	printk(KERN_INFO "pnp: PnP ACPI init\n");
-	pnp_register_protocol(&pnpacpi_protocol);
+	if (pnp_register_protocol(&pnpacpi_protocol)) {
+		put_device(&pnpacpi_protocol.dev);
+		return 0;
+	}
 	acpi_get_devices(NULL, pnpacpi_add_device_handler, NULL, NULL);
 	printk(KERN_INFO "pnp: PnP ACPI: found %d devices\n", num);
 	pnp_platform_devices = 1;
-- 
2.25.1
Re: [PATCH] PNP: add a error handling in pnpacpi_init()
Posted by Greg KH 1 month, 3 weeks ago
On Thu, Dec 18, 2025 at 04:29:03PM +0800, Haoxiang Li wrote:
> Add a error handling for pnp_register_protocol(), and if
> it fails, call put_device() to drop the device reference.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
> ---
>  drivers/pnp/pnpacpi/core.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
> index a0927081a003..0b63e1748b7c 100644
> --- a/drivers/pnp/pnpacpi/core.c
> +++ b/drivers/pnp/pnpacpi/core.c
> @@ -304,7 +304,10 @@ static int __init pnpacpi_init(void)
>  		return 0;
>  	}
>  	printk(KERN_INFO "pnp: PnP ACPI init\n");
> -	pnp_register_protocol(&pnpacpi_protocol);
> +	if (pnp_register_protocol(&pnpacpi_protocol)) {
> +		put_device(&pnpacpi_protocol.dev);

Again, this looks really wrong.

What tool are you all using to "find" these issues?  Why aren't you
properly documenting it?

thanks,

greg k-h
Re: [PATCH] PNP: add a error handling in pnpacpi_init()
Posted by Haoxiang Li 1 month, 3 weeks ago
On Thu, 18 Dec 2025 12:33:05 +0100, Greg KH Wrote:
> What tool are you all using to "find" these issues?  Why aren't you
> properly documenting it?

Sorry for the inconvenience. I found these through manual code review.
I realize I completely overlooked the static structure. I am sorry for
my lack of thoroughness again.
I will document how the issue was identified later.

Thanks,
Haoxiang Li
Re: [PATCH] PNP: add a error handling in pnpacpi_init()
Posted by Greg KH 1 month, 3 weeks ago
On Thu, Dec 18, 2025 at 08:24:22PM +0800, Haoxiang Li wrote:
> On Thu, 18 Dec 2025 12:33:05 +0100, Greg KH Wrote:
> > What tool are you all using to "find" these issues?  Why aren't you
> > properly documenting it?
> 
> Sorry for the inconvenience. I found these through manual code review.

Manually?  Really?  Why are you manually reviewing pnp code?  Do you
have this hardware?  Why not focus on code for hardware you have and can
test the fix for?

> I will document how the issue was identified later.

It should be in the changelog text, as is required.

thanks,

greg k-h
Re: [PATCH] PNP: add a error handling in pnpacpi_init()
Posted by Haoxiang Li 1 month, 3 weeks ago
On Thu, 18 Dec 2025 13:40:09 +0100, Greg KH Wrote:
> Manually?  Really?  Why are you manually reviewing pnp code?  Do you
> have this hardware?  Why not focus on code for hardware you have and can
> test the fix for?

I apologize for the confusion. I did a targeted search for device_register()
and check their error handling. And Thanks for your guidance and patience!

> It should be in the changelog text, as is required.

Copy that. I will follow the rule.

Thanks,
Haoxiang Li