Skip to contentSkip to conversation

net: ionic: Fix error handling in ionic_init_module()

PATCH Applied Yuan Can 3 participants 3 messages Nov 13, 2022 – Nov 15, 2022

Subsystems (3)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 net: ionic: Fix error handling in ionic_init_module()

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

 [  415.799514] debugfs: Directory 'ionic' with parent '/' already present!

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

ionic_init_module()
ionic_debugfs_create() # create debugfs directory ionic_bus_register_driver()
pci_register_driver()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened

   # return without destroy debugfs directory

Fix by removing debugfs when ionic_bus_register_driver() returns error.

Fixes fbfb8031533c ("ionic: Add hardware init and device commands")
---
 drivers/net/ethernet/pensando/ionic/ionic_main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_main.c +7 -1
index 56f93b030551..5456c2b15d9b 100644
@@ -687,8 +687,14 @@ int ionic_port_reset(struct ionic *ionic)
 
 static int __init ionic_init_module(void)
 {
+	int ret;
+
 	ionic_debugfs_create();
-	return ionic_bus_register_driver();
+	ret = ionic_bus_register_driver();
+	if (ret)
+		ionic_debugfs_destroy();
+
+	return ret;
 }
 
 static void __exit ionic_cleanup_module(void)
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Yuan Can

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

  [  415.799514] debugfs: Directory 'ionic' with parent '/' already present!

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

ionic_init_module()
ionic_debugfs_create() # create debugfs directory ionic_bus_register_driver()
pci_register_driver()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened
# return without destroy debugfs directory

Quoted 4 lines

Fix by removing debugfs when ionic_bus_register_driver() returns error.

Fixes fbfb8031533c ("ionic: Add hardware init and device commands")
Quoted 27 lines
---
  drivers/net/ethernet/pensando/ionic/ionic_main.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_main.c +7 -2
index 56f93b030551..5456c2b15d9b 100644
@@ -687,8 +687,14 @@ int ionic_port_reset(struct ionic *ionic)
 
  static int __init ionic_init_module(void)
  {
+       int ret;
+
         ionic_debugfs_create();
-       return ionic_bus_register_driver();
+       ret = ionic_bus_register_driver();
+       if (ret)
+               ionic_debugfs_destroy();
+
+       return ret;
  }
 
  static void __exit ionic_cleanup_module(void)
--

2.17.1

#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 Sun, 13 Nov 2022 09:29:29 +0000 you wrote:

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

 [  415.799514] debugfs: Directory 'ionic' with parent '/' already present!

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

[...]

Here is the summary with links:
- net: ionic: Fix error handling in ionic_init_module()

    https://git.kernel.org/netdev/net/c/280c0f7cd0aa

You are awesome, thank you!

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