[PATCH] PNP: add put_device() in pnpbios_init()

Haoxiang Li posted 1 patch 1 month, 3 weeks ago
drivers/pnp/pnpbios/core.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] PNP: add put_device() in pnpbios_init()
Posted by Haoxiang Li 1 month, 3 weeks ago
If pnp_register_protocol() 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/pnpbios/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
index f7e86ae9f72f..997e0153d6e3 100644
--- a/drivers/pnp/pnpbios/core.c
+++ b/drivers/pnp/pnpbios/core.c
@@ -538,6 +538,7 @@ static int __init pnpbios_init(void)
 	/* register with the pnp layer */
 	ret = pnp_register_protocol(&pnpbios_protocol);
 	if (ret) {
+		put_device(&pnpbios_protocol.dev)
 		printk(KERN_ERR
 		       "PnPBIOS: Unable to register driver.  Aborting.\n");
 		return ret;
-- 
2.25.1
Re: [PATCH] PNP: add put_device() in pnpbios_init()
Posted by kernel test robot 1 month, 2 weeks ago
Hi Haoxiang,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.19-rc1 next-20251219]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Haoxiang-Li/PNP-add-put_device-in-pnpbios_init/20251218-162345
base:   linus/master
patch link:    https://lore.kernel.org/r/20251218081955.548521-1-lihaoxiang%40isrc.iscas.ac.cn
patch subject: [PATCH] PNP: add put_device() in pnpbios_init()
config: i386-randconfig-004-20251219 (https://download.01.org/0day-ci/archive/20251221/202512210013.9DqxXceY-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251221/202512210013.9DqxXceY-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512210013.9DqxXceY-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/pnp/pnpbios/core.c:90:13: warning: variable 'value' set but not used [-Wunused-but-set-variable]
      90 |         int i = 0, value;
         |                    ^
>> drivers/pnp/pnpbios/core.c:542:3: error: expected expression
     542 |                 printk(KERN_ERR
         |                 ^
   include/linux/printk.h:512:26: note: expanded from macro 'printk'
     512 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
         |                          ^
   include/linux/printk.h:482:3: note: expanded from macro 'printk_index_wrap'
     482 |         ({                                                              \
         |          ^
   1 warning and 1 error generated.


vim +542 drivers/pnp/pnpbios/core.c

^1da177e4c3f41 Linus Torvalds 2005-04-16  522  
^1da177e4c3f41 Linus Torvalds 2005-04-16  523  	/* scan the system for pnpbios support */
^1da177e4c3f41 Linus Torvalds 2005-04-16  524  	if (!pnpbios_probe_system())
^1da177e4c3f41 Linus Torvalds 2005-04-16  525  		return -ENODEV;
^1da177e4c3f41 Linus Torvalds 2005-04-16  526  
^1da177e4c3f41 Linus Torvalds 2005-04-16  527  	/* make preparations for bios calls */
^1da177e4c3f41 Linus Torvalds 2005-04-16  528  	pnpbios_calls_init(pnp_bios_install);
^1da177e4c3f41 Linus Torvalds 2005-04-16  529  
^1da177e4c3f41 Linus Torvalds 2005-04-16  530  	/* read the node info */
^1da177e4c3f41 Linus Torvalds 2005-04-16  531  	ret = pnp_bios_dev_node_info(&node_info);
^1da177e4c3f41 Linus Torvalds 2005-04-16  532  	if (ret) {
9dd78466c956ac Bjorn Helgaas  2007-07-26  533  		printk(KERN_ERR
9dd78466c956ac Bjorn Helgaas  2007-07-26  534  		       "PnPBIOS: Unable to get node info.  Aborting.\n");
^1da177e4c3f41 Linus Torvalds 2005-04-16  535  		return ret;
^1da177e4c3f41 Linus Torvalds 2005-04-16  536  	}
^1da177e4c3f41 Linus Torvalds 2005-04-16  537  
^1da177e4c3f41 Linus Torvalds 2005-04-16  538  	/* register with the pnp layer */
^1da177e4c3f41 Linus Torvalds 2005-04-16  539  	ret = pnp_register_protocol(&pnpbios_protocol);
^1da177e4c3f41 Linus Torvalds 2005-04-16  540  	if (ret) {
72a4fc1c3483e8 Haoxiang Li    2025-12-18  541  		put_device(&pnpbios_protocol.dev)
9dd78466c956ac Bjorn Helgaas  2007-07-26 @542  		printk(KERN_ERR
9dd78466c956ac Bjorn Helgaas  2007-07-26  543  		       "PnPBIOS: Unable to register driver.  Aborting.\n");
^1da177e4c3f41 Linus Torvalds 2005-04-16  544  		return ret;
^1da177e4c3f41 Linus Torvalds 2005-04-16  545  	}
^1da177e4c3f41 Linus Torvalds 2005-04-16  546  
^1da177e4c3f41 Linus Torvalds 2005-04-16  547  	/* start the proc interface */
^1da177e4c3f41 Linus Torvalds 2005-04-16  548  	ret = pnpbios_proc_init();
^1da177e4c3f41 Linus Torvalds 2005-04-16  549  	if (ret)
^1da177e4c3f41 Linus Torvalds 2005-04-16  550  		printk(KERN_ERR "PnPBIOS: Failed to create proc interface.\n");
^1da177e4c3f41 Linus Torvalds 2005-04-16  551  
^1da177e4c3f41 Linus Torvalds 2005-04-16  552  	/* scan for pnpbios devices */
^1da177e4c3f41 Linus Torvalds 2005-04-16  553  	build_devlist();
^1da177e4c3f41 Linus Torvalds 2005-04-16  554  
8f81dd149806bc Bjorn Helgaas  2007-05-08  555  	pnp_platform_devices = 1;
^1da177e4c3f41 Linus Torvalds 2005-04-16  556  	return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  557  }
^1da177e4c3f41 Linus Torvalds 2005-04-16  558  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] PNP: add put_device() in pnpbios_init()
Posted by kernel test robot 1 month, 2 weeks ago
Hi Haoxiang,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.19-rc1 next-20251219]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Haoxiang-Li/PNP-add-put_device-in-pnpbios_init/20251218-162345
base:   linus/master
patch link:    https://lore.kernel.org/r/20251218081955.548521-1-lihaoxiang%40isrc.iscas.ac.cn
patch subject: [PATCH] PNP: add put_device() in pnpbios_init()
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20251221/202512210401.KjSlGMtG-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251221/202512210401.KjSlGMtG-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512210401.KjSlGMtG-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/pnp/pnpbios/core.c: In function 'pnp_dock_event':
   drivers/pnp/pnpbios/core.c:90:20: warning: variable 'value' set but not used [-Wunused-but-set-variable]
      90 |         int i = 0, value;
         |                    ^~~~~
   In file included from include/asm-generic/bug.h:31,
                    from arch/x86/include/asm/bug.h:193,
                    from arch/x86/include/asm/alternative.h:9,
                    from arch/x86/include/asm/barrier.h:5,
                    from include/asm-generic/bitops/generic-non-atomic.h:7,
                    from include/linux/bitops.h:28,
                    from include/linux/kernel.h:23,
                    from drivers/pnp/pnpbios/core.c:38:
   drivers/pnp/pnpbios/core.c: In function 'pnpbios_init':
>> include/linux/printk.h:482:10: error: expected expression before '{' token
     482 |         ({                                                              \
         |          ^
   include/linux/printk.h:512:26: note: in expansion of macro 'printk_index_wrap'
     512 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
         |                          ^~~~~~~~~~~~~~~~~
   drivers/pnp/pnpbios/core.c:542:17: note: in expansion of macro 'printk'
     542 |                 printk(KERN_ERR
         |                 ^~~~~~
>> drivers/pnp/pnpbios/core.c:541:17: error: called object is not a function or function pointer
     541 |                 put_device(&pnpbios_protocol.dev)
         |                 ^~~~~~~~~~


vim +541 drivers/pnp/pnpbios/core.c

   522	
   523		/* scan the system for pnpbios support */
   524		if (!pnpbios_probe_system())
   525			return -ENODEV;
   526	
   527		/* make preparations for bios calls */
   528		pnpbios_calls_init(pnp_bios_install);
   529	
   530		/* read the node info */
   531		ret = pnp_bios_dev_node_info(&node_info);
   532		if (ret) {
   533			printk(KERN_ERR
   534			       "PnPBIOS: Unable to get node info.  Aborting.\n");
   535			return ret;
   536		}
   537	
   538		/* register with the pnp layer */
   539		ret = pnp_register_protocol(&pnpbios_protocol);
   540		if (ret) {
 > 541			put_device(&pnpbios_protocol.dev)
   542			printk(KERN_ERR
   543			       "PnPBIOS: Unable to register driver.  Aborting.\n");
   544			return ret;
   545		}
   546	
   547		/* start the proc interface */
   548		ret = pnpbios_proc_init();
   549		if (ret)
   550			printk(KERN_ERR "PnPBIOS: Failed to create proc interface.\n");
   551	
   552		/* scan for pnpbios devices */
   553		build_devlist();
   554	
   555		pnp_platform_devices = 1;
   556		return 0;
   557	}
   558	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] PNP: add put_device() in pnpbios_init()
Posted by Greg KH 1 month, 3 weeks ago
On Thu, Dec 18, 2025 at 04:19:55PM +0800, Haoxiang Li wrote:
> If pnp_register_protocol() 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/pnpbios/core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
> index f7e86ae9f72f..997e0153d6e3 100644
> --- a/drivers/pnp/pnpbios/core.c
> +++ b/drivers/pnp/pnpbios/core.c
> @@ -538,6 +538,7 @@ static int __init pnpbios_init(void)
>  	/* register with the pnp layer */
>  	ret = pnp_register_protocol(&pnpbios_protocol);
>  	if (ret) {
> +		put_device(&pnpbios_protocol.dev)

This feels wrong, as this is a static structure, why would it have a
reference count?  Something is not working properly here if this is
required.

What testing caused this to trigger?  How was this found?

thanks,

greg k-h