提交 51cb8cb3 编写于 作者: Y Yuan Can 提交者: sanglipeng

net: thunderbolt: Fix error handling in tbnet_init()

stable inclusion
from stable-v5.10.156
commit 0aeb0de528eccc2b7ff487390a68d2a2bb1083ba
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7MCG1

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0aeb0de528eccc2b7ff487390a68d2a2bb1083ba

--------------------------------

[ Upstream commit f524b728 ]

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: e69b6c02 ("net: Add support for networking over Thunderbolt cable")
Signed-off-by: NYuan Can <yuancan@huawei.com>
Acked-by: NMika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: Nsanglipeng <sanglipeng1@jd.com>
上级 ca5052f7
...@@ -1343,12 +1343,21 @@ static int __init tbnet_init(void) ...@@ -1343,12 +1343,21 @@ static int __init tbnet_init(void)
TBNET_MATCH_FRAGS_ID); TBNET_MATCH_FRAGS_ID);
ret = tb_register_property_dir("network", tbnet_dir); ret = tb_register_property_dir("network", tbnet_dir);
if (ret) { if (ret)
goto err_free_dir;
ret = tb_register_service_driver(&tbnet_driver);
if (ret)
goto err_unregister;
return 0;
err_unregister:
tb_unregister_property_dir("network", tbnet_dir);
err_free_dir:
tb_property_free_dir(tbnet_dir); tb_property_free_dir(tbnet_dir);
return ret;
}
return tb_register_service_driver(&tbnet_driver); return ret;
} }
module_init(tbnet_init); module_init(tbnet_init);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册