diff mbox series

[1/2] fm10k: Fix error handling in fm10k_init_module()

Message ID 20221114082640.91128-2-yuancan@huawei.com (mailing list archive)
State Awaiting Upstream
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: 0 this patch: 0
netdev/cc_maintainers success CCed 11 of 11 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: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 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. 14, 2022, 8:26 a.m. UTC
A problem about modprobe fm10k failed is triggered with the following log
given:

 Intel(R) Ethernet Switch Host Interface Driver
 Copyright(c) 2013 - 2019 Intel Corporation.
 debugfs: Directory 'fm10k' with parent '/' already present!

The reason is that fm10k_init_module() returns fm10k_register_pci_driver()
directly without checking its return value, if fm10k_register_pci_driver()
failed, it returns without removing debugfs and destroy workqueue,
resulting the debugfs of fm10k can never be created later and leaks the
workqueue.

 fm10k_init_module()
   alloc_workqueue()
   fm10k_dbg_init() # create debugfs
   fm10k_register_pci_driver()
     pci_register_driver()
       driver_register()
         bus_add_driver()
           priv = kzalloc(...) # OOM happened
   # return without remove debugfs and destroy workqueue

Fix by remove debugfs and destroy workqueue when
fm10k_register_pci_driver() returns error.

Fixes: 7461fd913afe ("fm10k: Add support for debugfs")
Fixes: b382bb1b3e2d ("fm10k: use separate workqueue for fm10k driver")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/net/ethernet/intel/fm10k/fm10k_main.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Jacob Keller Nov. 14, 2022, 4:36 p.m. UTC | #1
> -----Original Message-----
> From: Yuan Can <yuancan@huawei.com>
> Sent: Monday, November 14, 2022 12:27 AM
> To: Brandeburg, Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; davem@davemloft.net; edumazet@google.com;
> kuba@kernel.org; pabeni@redhat.com; alexander.h.duyck@intel.com;
> jeffrey.t.kirsher@intel.com; Vick, Matthew <matthew.vick@intel.com>; Keller,
> Jacob E <jacob.e.keller@intel.com>; intel-wired-lan@lists.osuosl.org;
> netdev@vger.kernel.org
> Cc: yuancan@huawei.com
> Subject: [PATCH 1/2] fm10k: Fix error handling in fm10k_init_module()
> 
> A problem about modprobe fm10k failed is triggered with the following log
> given:
> 
>  Intel(R) Ethernet Switch Host Interface Driver
>  Copyright(c) 2013 - 2019 Intel Corporation.
>  debugfs: Directory 'fm10k' with parent '/' already present!
> 
> The reason is that fm10k_init_module() returns fm10k_register_pci_driver()
> directly without checking its return value, if fm10k_register_pci_driver()
> failed, it returns without removing debugfs and destroy workqueue,
> resulting the debugfs of fm10k can never be created later and leaks the
> workqueue.
> 
>  fm10k_init_module()
>    alloc_workqueue()
>    fm10k_dbg_init() # create debugfs
>    fm10k_register_pci_driver()
>      pci_register_driver()
>        driver_register()
>          bus_add_driver()
>            priv = kzalloc(...) # OOM happened
>    # return without remove debugfs and destroy workqueue
> 
> Fix by remove debugfs and destroy workqueue when
> fm10k_register_pci_driver() returns error.
> 
> Fixes: 7461fd913afe ("fm10k: Add support for debugfs")
> Fixes: b382bb1b3e2d ("fm10k: use separate workqueue for fm10k driver")
> Signed-off-by: Yuan Can <yuancan@huawei.com>


Makes sense. Thanks!

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

> ---
>  drivers/net/ethernet/intel/fm10k/fm10k_main.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_main.c
> b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
> index 4a6630586ec9..fc373472e4e1 100644
> --- a/drivers/net/ethernet/intel/fm10k/fm10k_main.c
> +++ b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
> @@ -32,6 +32,8 @@ struct workqueue_struct *fm10k_workqueue;
>   **/
>  static int __init fm10k_init_module(void)
>  {
> +	int ret;
> +
>  	pr_info("%s\n", fm10k_driver_string);
>  	pr_info("%s\n", fm10k_copyright);
> 
> @@ -43,7 +45,13 @@ static int __init fm10k_init_module(void)
> 
>  	fm10k_dbg_init();
> 
> -	return fm10k_register_pci_driver();
> +	ret = fm10k_register_pci_driver();
> +	if (ret) {
> +		fm10k_dbg_exit();
> +		destroy_workqueue(fm10k_workqueue);
> +	}
> +
> +	return ret;
>  }
>  module_init(fm10k_init_module);
> 
> --
> 2.17.1
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_main.c b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
index 4a6630586ec9..fc373472e4e1 100644
--- a/drivers/net/ethernet/intel/fm10k/fm10k_main.c
+++ b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
@@ -32,6 +32,8 @@  struct workqueue_struct *fm10k_workqueue;
  **/
 static int __init fm10k_init_module(void)
 {
+	int ret;
+
 	pr_info("%s\n", fm10k_driver_string);
 	pr_info("%s\n", fm10k_copyright);
 
@@ -43,7 +45,13 @@  static int __init fm10k_init_module(void)
 
 	fm10k_dbg_init();
 
-	return fm10k_register_pci_driver();
+	ret = fm10k_register_pci_driver();
+	if (ret) {
+		fm10k_dbg_exit();
+		destroy_workqueue(fm10k_workqueue);
+	}
+
+	return ret;
 }
 module_init(fm10k_init_module);