Message ID | 20221113093719.23687-3-yuancan@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | Fix error handling path | expand |
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-3-yuancan%40huawei.com patch subject: [PATCH 2/2] net: sky2: Fix error handling in sky2_init_module() config: i386-defconfig compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/ec8673a78a9b9fd5452193e20a75ed983b6cf668 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 ec8673a78a9b9fd5452193e20a75ed983b6cf668 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=i386 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/sky2.c: In function 'sky2_init_module': >> drivers/net/ethernet/marvell/sky2.c:5154:37: warning: suggest braces around empty body in an 'if' statement [-Wempty-body] 5154 | sky2_debug_cleanup(); | ^ vim +/if +5154 drivers/net/ethernet/marvell/sky2.c 5144 5145 static int __init sky2_init_module(void) 5146 { 5147 int ret; 5148 5149 pr_info("driver version " DRV_VERSION "\n"); 5150 5151 sky2_debug_init(); 5152 ret = pci_register_driver(&sky2_driver); 5153 if (ret) > 5154 sky2_debug_cleanup(); 5155 5156 return ret; 5157 } 5158
diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c index ab33ba1c3023..6996169b7ddd 100644 --- a/drivers/net/ethernet/marvell/sky2.c +++ b/drivers/net/ethernet/marvell/sky2.c @@ -4536,7 +4536,7 @@ static __init void sky2_debug_init(void) register_netdevice_notifier(&sky2_notifier); } -static __exit void sky2_debug_cleanup(void) +static void sky2_debug_cleanup(void) { if (sky2_debug) { unregister_netdevice_notifier(&sky2_notifier); @@ -5144,10 +5144,16 @@ static struct pci_driver sky2_driver = { static int __init sky2_init_module(void) { + int ret; + pr_info("driver version " DRV_VERSION "\n"); sky2_debug_init(); - return pci_register_driver(&sky2_driver); + ret = pci_register_driver(&sky2_driver); + if (ret) + sky2_debug_cleanup(); + + return ret; } static void __exit sky2_cleanup_module(void)
A problem about modprobe sky2 failed is triggered with the following log given: sky2: driver version 1.30 debugfs: Directory 'sky2' with parent '/' already present! The reason is that sky2_init_module() returns pci_register_driver() directly without checking its return value, if pci_register_driver() failed, it returns without removing sky2 debugfs and unregister sky2_notifier, resulting the debugfs of sky2 can never be created later. sky2_init_module() sky2_debug_init() # create debugfs and register sky2_notifier pci_register_driver() driver_register() bus_add_driver() priv = kzalloc(...) # OOM happened # return without destroy debugfs and unregister sky2_notifier Fix by calling sky2_debug_cleanup() when pci_register_driver() returns error. Fixes: 3cf267539f1f ("sky2: debug interface") Signed-off-by: Yuan Can <yuancan@huawei.com> --- drivers/net/ethernet/marvell/sky2.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)