Netdev List
 help / color / mirror / Atom feed
* [PATCH net] ipv4: nexthop: handle errors in nexthop_init()
@ 2026-07-28  3:10 Minhong He
  2026-07-29 11:10 ` Ido Schimmel
  0 siblings, 1 reply; 2+ messages in thread
From: Minhong He @ 2026-07-28  3:10 UTC (permalink / raw)
  To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, netdev
  Cc: linux-kernel

nexthop_init() ignores errors from register_pernet_subsys(),
register_netdevice_notifier() and rtnl_register_many(), so a partial
initialization can appear successful.

Check each step and unwind the registrations that already succeeded.

Signed-off-by: Minhong He <heminhong@kylinos.cn>
---
 net/ipv4/nexthop.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 6205bd57aa85..0ad40d93e3b5 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -4192,12 +4192,26 @@ static const struct rtnl_msg_handler nexthop_rtnl_msg_handlers[] __initconst = {
 
 static int __init nexthop_init(void)
 {
-	register_pernet_subsys(&nexthop_net_ops);
+	int err;
+
+	err = register_pernet_subsys(&nexthop_net_ops);
+	if (err)
+		return err;
 
-	register_netdevice_notifier(&nh_netdev_notifier);
+	err = register_netdevice_notifier(&nh_netdev_notifier);
+	if (err)
+		goto err_unregister_pernet;
 
-	rtnl_register_many(nexthop_rtnl_msg_handlers);
+	err = rtnl_register_many(nexthop_rtnl_msg_handlers);
+	if (err)
+		goto err_unregister_notifier;
 
 	return 0;
+
+err_unregister_notifier:
+	unregister_netdevice_notifier(&nh_netdev_notifier);
+err_unregister_pernet:
+	unregister_pernet_subsys(&nexthop_net_ops);
+	return err;
 }
 subsys_initcall(nexthop_init);
-- 
2.25.1


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

end of thread, other threads:[~2026-07-29 11:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28  3:10 [PATCH net] ipv4: nexthop: handle errors in nexthop_init() Minhong He
2026-07-29 11:10 ` Ido Schimmel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox