Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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")
Signed-off-by: Yuan Can <yuancan@huawei.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Link: https://lore.kernel.org/r/20221110021642.80378-1-yuancan@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Yuan Can and committed by
Jakub Kicinski
8eab9be5 98a2ac1c

+8 -1
+8 -1
drivers/net/ethernet/huawei/hinic/hinic_main.c
··· 1474 1474 1475 1475 static int __init hinic_module_init(void) 1476 1476 { 1477 + int ret; 1478 + 1477 1479 hinic_dbg_register_debugfs(HINIC_DRV_NAME); 1478 - return pci_register_driver(&hinic_driver); 1480 + 1481 + ret = pci_register_driver(&hinic_driver); 1482 + if (ret) 1483 + hinic_dbg_unregister_debugfs(); 1484 + 1485 + return ret; 1479 1486 } 1480 1487 1481 1488 static void __exit hinic_module_exit(void)