Skip to contentSkip to conversation

net: hinic: Fix error handling in hinic_module_init()

PATCH Applied Yuan Can 3 participants 3 messages Nov 10, 2022 – Nov 12, 2022

Subsystems (3)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH v2 1/1 net: hinic: Fix error handling in hinic_module_init()

A problem about hinic create debugfs failed is triggered with the following log given:

 [  931.419023] debugfs: Directory 'hinic' with parent '/' already present!

The reason is that hinic_module_init() returns pci_register_driver() directly without checking its return value, if pci_register_driver() failed, it returns without destroy the newly created debugfs, resulting the debugfs of hinic can never be created later.

hinic_module_init()
hinic_dbg_register_debugfs() # create debugfs directory pci_register_driver()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened

   # return without destroy debugfs directory

Fix by removing debugfs when pci_register_driver() returns error.

Fixes 253ac3a97921 ("hinic: add support to query sq info")

---
Changes in v2:
- Change to simpler error handling style

 drivers/net/ethernet/huawei/hinic/hinic_main.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/huawei/hinic/hinic_main.c +8 -1
index e1f54a2f28b2..2d6906aba2a2 100644
@@ -1474,8 +1474,15 @@ static struct pci_driver hinic_driver = {
 
 static int __init hinic_module_init(void)
 {
+	int ret;
+
 	hinic_dbg_register_debugfs(HINIC_DRV_NAME);
-	return pci_register_driver(&hinic_driver);
+
+	ret = pci_register_driver(&hinic_driver);
+	if (ret)
+		hinic_dbg_unregister_debugfs();
+
+	return ret;
 }
 
 static void __exit hinic_module_exit(void)
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 18 lines · Yuan Can

A problem about hinic create debugfs failed is triggered with the following log given:

 [  931.419023] debugfs: Directory 'hinic' with parent '/' already present!

The reason is that hinic_module_init() returns pci_register_driver() directly without checking its return value, if pci_register_driver() failed, it returns without destroy the newly created debugfs, resulting the debugfs of hinic can never be created later.

hinic_module_init()
hinic_dbg_register_debugfs() # create debugfs directory pci_register_driver()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened

   # return without destroy debugfs directory
Quoted 8 lines

Fix by removing debugfs when pci_register_driver() returns error.

Fixes 253ac3a97921 ("hinic: add support to query sq info")

---
Changes in v2:
- Change to simpler error handling style

Thanks,

#2 lore raw
In reply to Yuan Can
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Thu, 10 Nov 2022 02:16:42 +0000 you wrote:

A problem about hinic create debugfs failed is triggered with the following log given:

 [  931.419023] debugfs: Directory 'hinic' with parent '/' already present!

The reason is that hinic_module_init() returns pci_register_driver() directly without checking its return value, if pci_register_driver() failed, it returns without destroy the newly created debugfs, resulting the debugfs of hinic can never be created later.

[...]

Here is the summary with links:
- [v2] net: hinic: Fix error handling in hinic_module_init()

    https://git.kernel.org/netdev/net/c/8eab9be56cc6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html