Fix error handling path
Subsystems (3)
cover Fix error handling path
This series contains two missing error handling related bugfixes.
Yuan Can (2):
fm10k: Fix error handling in fm10k_init_module()
iavf: Fix error handling in iavf_init_module()
drivers/net/ethernet/intel/fm10k/fm10k_main.c | 10 +++++++++- drivers/net/ethernet/intel/iavf/iavf_main.c | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
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 whenfm10k_register_pci_driver() returns error.
--- drivers/net/ethernet/intel/fm10k/fm10k_main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/fm10k/fm10k_main.c +9 -1
@@ -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);
Signature · 1 line
2.17.1
RE: [PATCH 1/2] fm10k: Fix error handling in fm10k_init_module()
Quoted 35 lines
-----Original Message-----
From: Yuan Can <[email protected]>
Sent: Monday, November 14, 2022 12:27 AM
To: Brandeburg, Jesse <[email protected]>; Nguyen, Anthony L <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Vick, Matthew <[email protected]>; Keller, Jacob E <[email protected]>; [email protected]; [email protected]
Cc: [email protected]
Subject: [PATCH 1/2] fm10k: Fix error handling infm10k_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()returnsfm10k_register_pci_driver()directly without checking its return value, iffm10k_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
Quoted 8 lines
# return without remove debugfs and destroy workqueueFix 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 <[email protected]>
Makes sense. Thanks!
Quoted 34 lines
--- drivers/net/ethernet/intel/fm10k/fm10k_main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/net/ethernet/intel/fm10k/fm10k_main.c +9
-2@@ -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); --
Quoted 1 line
2.17.1
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
PATCH 2/2 iavf: Fix error handling in iavf_init_module()
In reply to Yuan CanThe iavf_init_module() won't destroy workqueue when pci_register_driver() failed. Call destroy_workqueue() when pci_register_driver() failed to prevent the resource leak.
Similar to the handling of u132_hcd_init in commit f276e002793c ("usb: u132-hcd: fix resource leak")
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +8 -1
@@ -5191,6 +5191,8 @@ static struct pci_driver iavf_driver = {**/ static int __init iavf_init_module (void ) { +int ret; +pr_info ("iavf: %s\n" , iavf_driver_string);pr_info ("%s\n" , iavf_copyright);
@@ -5201,7 +5203,12 @@ static int __init iavf_init_module(void)pr_err ("%s: Failed to create workqueue\n" , iavf_driver_name);return -ENOMEM ; } -return pci_register_driver (&iavf_driver); + + ret =pci_register_driver (&iavf_driver); +if (ret) +destroy_workqueue (iavf_wq); + +return ret; }module_init (iavf_init_module);
Signature · 1 line
2.17.1
RE: [Intel-wired-lan] [PATCH 2/2] iavf: Fix error handling in iavf_init_module()
Quoted 33 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Yuan Can
Sent: Monday, November 14, 2022 9:27 AM
To: Brandeburg, Jesse <[email protected]>; Nguyen, Anthony L <[email protected]>; [email protected];
[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Vick, Matthew <[email protected]>; Keller, Jacob E <[email protected]>; intel- [email protected]; [email protected]
Cc: [email protected]
Subject: [Intel-wired-lan] [PATCH 2/2] iavf: Fix error handling iniavf_init_module()The
iavf_init_module()won't destroy workqueue whenpci_register_driver()failed. Calldestroy_workqueue()whenpci_register_driver()failed to prevent the resource leak.Similar to the handling of
u132_hcd_initin commitf276e002793c("usb: u132-hcd: fix resource leak")Fixes 2803b16c10ea ("i40e/i40evf: Use private workqueue")Signed-off-by Yuan Can <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/net/ethernet/intel/iavf/iavf_main.c +0
-0