netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: thunderbolt: Fix error handling in tbnet_init()
@ 2022-11-14  8:19 Yuan Can
  2022-11-14 10:09 ` Mika Westerberg
  0 siblings, 1 reply; 3+ messages in thread
From: Yuan Can @ 2022-11-14  8:19 UTC (permalink / raw)
  To: michael.jamet, mika.westerberg, YehezkelShB, davem, edumazet,
	kuba, pabeni, andriy.shevchenko, amir.jer.levy, netdev
  Cc: yuancan

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>
---
 drivers/net/thunderbolt.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/thunderbolt.c b/drivers/net/thunderbolt.c
index 83fcaeb2ac5e..fe6a9881cc75 100644
--- a/drivers/net/thunderbolt.c
+++ b/drivers/net/thunderbolt.c
@@ -1396,7 +1396,14 @@ static int __init tbnet_init(void)
 		return ret;
 	}
 
-	return tb_register_service_driver(&tbnet_driver);
+	ret = tb_register_service_driver(&tbnet_driver);
+	if (ret) {
+		tb_unregister_property_dir("network", tbnet_dir);
+		tb_property_free_dir(tbnet_dir);
+		return ret;
+	}
+
+	return 0;
 }
 module_init(tbnet_init);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-14 12:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-14  8:19 [PATCH] net: thunderbolt: Fix error handling in tbnet_init() Yuan Can
2022-11-14 10:09 ` Mika Westerberg
2022-11-14 12:06   ` Yuan Can

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).