* [PATCH v2] net: hinic: Fix error handling in hinic_module_init()
@ 2022-11-10 2:16 Yuan Can
2022-11-10 9:46 ` Leon Romanovsky
2022-11-12 5:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Yuan Can @ 2022-11-10 2:16 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, mqaio, shaozhengchao,
christophe.jaillet, gustavoars, luobin9, netdev
Cc: yuancan
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>
---
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(-)
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_main.c b/drivers/net/ethernet/huawei/hinic/hinic_main.c
index e1f54a2f28b2..2d6906aba2a2 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_main.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_main.c
@@ -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)
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] net: hinic: Fix error handling in hinic_module_init()
2022-11-10 2:16 [PATCH v2] net: hinic: Fix error handling in hinic_module_init() Yuan Can
@ 2022-11-10 9:46 ` Leon Romanovsky
2022-11-12 5:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2022-11-10 9:46 UTC (permalink / raw)
To: Yuan Can
Cc: davem, edumazet, kuba, pabeni, mqaio, shaozhengchao,
christophe.jaillet, gustavoars, luobin9, netdev
On Thu, Nov 10, 2022 at 02:16:42AM +0000, Yuan Can 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.
>
> 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>
> ---
> Changes in v2:
> - Change to simpler error handling style
>
Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] net: hinic: Fix error handling in hinic_module_init()
2022-11-10 2:16 [PATCH v2] net: hinic: Fix error handling in hinic_module_init() Yuan Can
2022-11-10 9:46 ` Leon Romanovsky
@ 2022-11-12 5:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-12 5:10 UTC (permalink / raw)
To: Yuan Can
Cc: davem, edumazet, kuba, pabeni, mqaio, shaozhengchao,
christophe.jaillet, gustavoars, luobin9, netdev
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-12 5:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-10 2:16 [PATCH v2] net: hinic: Fix error handling in hinic_module_init() Yuan Can
2022-11-10 9:46 ` Leon Romanovsky
2022-11-12 5:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).