diff mbox series

net: ionic: Fix error handling in ionic_init_module()

Message ID 20221113092929.19161-1-yuancan@huawei.com (mailing list archive)
State Accepted
Commit 280c0f7cd0aa4d190619b18243110e052a90775c
Delegated to: Netdev Maintainers
Headers show
Series net: ionic: Fix error handling in ionic_init_module() | 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 Single patches do not need cover letters
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 8 of 8 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, 15 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. 13, 2022, 9:29 a.m. UTC
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")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/net/ethernet/pensando/ionic/ionic_main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Shannon Nelson Nov. 14, 2022, 6:29 p.m. UTC | #1
On 11/13/22 1:29 AM, Yuan Can 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.
> 
>   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")
> Signed-off-by: Yuan Can <yuancan@huawei.com>

Acked-by: Shannon Nelson <snelson@pensando.io>


> ---
>   drivers/net/ethernet/pensando/ionic/ionic_main.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_main.c b/drivers/net/ethernet/pensando/ionic/ionic_main.c
> index 56f93b030551..5456c2b15d9b 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_main.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_main.c
> @@ -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
>
patchwork-bot+netdevbpf@kernel.org Nov. 15, 2022, 5:40 a.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

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!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_main.c b/drivers/net/ethernet/pensando/ionic/ionic_main.c
index 56f93b030551..5456c2b15d9b 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_main.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_main.c
@@ -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)