fm10k: Fix error handling in fm10k_init_module()
authorYuan Can <yuancan@huawei.com>
Mon, 14 Nov 2022 08:26:39 +0000 (08:26 +0000)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Wed, 23 Nov 2022 16:36:55 +0000 (08:36 -0800)
commit771a794c0a3c3e7f0d86cc34be4f9537e8c0a20c
treed60bb5801d18ce920a101f52537aa1370800112b
parent479dd06149425b9e00477f52200872587af76a48
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>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/fm10k/fm10k_main.c