diff mbox series

[1/2] net: skge: Fix error handling in skge_init_module()

Message ID 20221113093719.23687-2-yuancan@huawei.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Fix error handling path | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 25 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yuan Can Nov. 13, 2022, 9:37 a.m. UTC
A problem about modprobe skge failed is triggered with the following log
given:

 debugfs: Directory 'skge' with parent '/' already present!
 ------------[ cut here ]------------
 notifier callback skge_device_event [skge] already registered
 WARNING: CPU: 1 PID: 236 at kernel/notifier.c:29 notifier_chain_register+0x168/0x230
 ...

The reason is that skge_init_module() returns pci_register_driver()
directly without checking its return value, if pci_register_driver()
failed, it returns without removing skge debugfs and unregister
skge_notifier, resulting the debugfs of skge can never be created later
and triggers the WARNING of notifier registered.

 skge_init_module()
   skge_debug_init() # create debugfs and register skge_notifier
   pci_register_driver()
     driver_register()
       bus_add_driver()
         priv = kzalloc(...) # OOM happened
   # return without destroy debugfs and unregister skge_notifier

Fix by calling skge_debug_cleanup() when pci_register_driver() returns
error.

Fixes: 678aa1f6ac86 ("skge: add a debug interface")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/net/ethernet/marvell/skge.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

kernel test robot Nov. 13, 2022, 1:41 p.m. UTC | #1
Hi Yuan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]
[also build test WARNING on net/master linus/master v6.1-rc4 next-20221111]
[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/Yuan-Can/Fix-error-handling-path/20221113-174019
patch link:    https://lore.kernel.org/r/20221113093719.23687-2-yuancan%40huawei.com
patch subject: [PATCH 1/2] net: skge: Fix error handling in skge_init_module()
config: openrisc-buildonly-randconfig-r003-20221113
compiler: or1k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/d0e0ff74baf3e1336c052f8100f16f21b80b43a6
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Yuan-Can/Fix-error-handling-path/20221113-174019
        git checkout d0e0ff74baf3e1336c052f8100f16f21b80b43a6
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=openrisc SHELL=/bin/bash drivers/net/ethernet/marvell/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/net/ethernet/marvell/skge.c: In function 'skge_init_module':
>> drivers/net/ethernet/marvell/skge.c:4189:37: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
    4189 |                 skge_debug_cleanup();
         |                                     ^


vim +/if +4189 drivers/net/ethernet/marvell/skge.c

  4179	
  4180	static int __init skge_init_module(void)
  4181	{
  4182		int ret;
  4183	
  4184		if (dmi_check_system(skge_32bit_dma_boards))
  4185			only_32bit_dma = 1;
  4186		skge_debug_init();
  4187		ret = pci_register_driver(&skge_driver);
  4188		if (ret)
> 4189			skge_debug_cleanup();
  4190	
  4191		return ret;
  4192	}
  4193
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/skge.c b/drivers/net/ethernet/marvell/skge.c
index 1b43704baceb..01d141369b3e 100644
--- a/drivers/net/ethernet/marvell/skge.c
+++ b/drivers/net/ethernet/marvell/skge.c
@@ -3776,7 +3776,7 @@  static __init void skge_debug_init(void)
 	register_netdevice_notifier(&skge_notifier);
 }
 
-static __exit void skge_debug_cleanup(void)
+static void skge_debug_cleanup(void)
 {
 	if (skge_debug) {
 		unregister_netdevice_notifier(&skge_notifier);
@@ -4179,10 +4179,16 @@  static const struct dmi_system_id skge_32bit_dma_boards[] = {
 
 static int __init skge_init_module(void)
 {
+	int ret;
+
 	if (dmi_check_system(skge_32bit_dma_boards))
 		only_32bit_dma = 1;
 	skge_debug_init();
-	return pci_register_driver(&skge_driver);
+	ret = pci_register_driver(&skge_driver);
+	if (ret)
+		skge_debug_cleanup();
+
+	return ret;
 }
 
 static void __exit skge_cleanup_module(void)