Message ID | 20221114142225.74124-1-yuancan@huawei.com (mailing list archive) |
---|---|
State | Accepted |
Commit | f524b7289bbb0c8ffaa2ba3c34c146e43da54fb2 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [v2] net: thunderbolt: Fix error handling in tbnet_init() | expand |
On Mon, Nov 14, 2022 at 02:22:25PM +0000, Yuan Can wrote: > A problem about insmod thunderbolt-net failed is triggered with following > log given while lsmod does not show thunderbolt_net: > > insmod: ERROR: could not insert module thunderbolt-net.ko: File exists > > The reason is that tbnet_init() returns tb_register_service_driver() > directly without checking its return value, if tb_register_service_driver() > failed, it returns without removing property directory, resulting the > property directory can never be created later. > > tbnet_init() > tb_register_property_dir() # register property directory > tb_register_service_driver() > driver_register() > bus_add_driver() > priv = kzalloc(...) # OOM happened > # return without remove property directory > > Fix by remove property directory when tb_register_service_driver() returns > error. > > Fixes: e69b6c02b4c3 ("net: Add support for networking over Thunderbolt cable") > Signed-off-by: Yuan Can <yuancan@huawei.com> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Hello: This patch was applied to netdev/net.git (master) by David S. Miller <davem@davemloft.net>: On Mon, 14 Nov 2022 14:22:25 +0000 you wrote: > A problem about insmod thunderbolt-net failed is triggered with following > log given while lsmod does not show thunderbolt_net: > > insmod: ERROR: could not insert module thunderbolt-net.ko: File exists > > The reason is that tbnet_init() returns tb_register_service_driver() > directly without checking its return value, if tb_register_service_driver() > failed, it returns without removing property directory, resulting the > property directory can never be created later. > > [...] Here is the summary with links: - [v2] net: thunderbolt: Fix error handling in tbnet_init() https://git.kernel.org/netdev/net/c/f524b7289bbb You are awesome, thank you!
diff --git a/drivers/net/thunderbolt.c b/drivers/net/thunderbolt.c index 83fcaeb2ac5e..a52ee2bf5575 100644 --- a/drivers/net/thunderbolt.c +++ b/drivers/net/thunderbolt.c @@ -1391,12 +1391,21 @@ static int __init tbnet_init(void) tb_property_add_immediate(tbnet_dir, "prtcstns", flags); ret = tb_register_property_dir("network", tbnet_dir); - if (ret) { - tb_property_free_dir(tbnet_dir); - return ret; - } + if (ret) + goto err_free_dir; + + ret = tb_register_service_driver(&tbnet_driver); + if (ret) + goto err_unregister; - return tb_register_service_driver(&tbnet_driver); + return 0; + +err_unregister: + tb_unregister_property_dir("network", tbnet_dir); +err_free_dir: + tb_property_free_dir(tbnet_dir); + + return ret; } module_init(tbnet_init);
A problem about insmod thunderbolt-net failed is triggered with following log given while lsmod does not show thunderbolt_net: insmod: ERROR: could not insert module thunderbolt-net.ko: File exists The reason is that tbnet_init() returns tb_register_service_driver() directly without checking its return value, if tb_register_service_driver() failed, it returns without removing property directory, resulting the property directory can never be created later. tbnet_init() tb_register_property_dir() # register property directory tb_register_service_driver() driver_register() bus_add_driver() priv = kzalloc(...) # OOM happened # return without remove property directory Fix by remove property directory when tb_register_service_driver() returns error. Fixes: e69b6c02b4c3 ("net: Add support for networking over Thunderbolt cable") Signed-off-by: Yuan Can <yuancan@huawei.com> --- Changes in v2: - Change to suggested error handling style drivers/net/thunderbolt.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)