summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinhong He <heminhong@kylinos.cn>2026-07-31 10:52:49 +0800
committerJakub Kicinski <kuba@kernel.org>2026-08-04 18:33:17 -0700
commitc0fd47726c9460fbdd1bf26cd0bfcd7dcce8f80b (patch)
treeddfa6f78e3788f7a5f21f7b174f3b96bc2162806
parent30ce0cb576b622f8fb5c5c9ebe43e28365374a3a (diff)
ipv4: nexthop: handle errors in nexthop_init()
nexthop_init() ignores errors from register_pernet_subsys() and register_netdevice_notifier(), so a partial initialization can appear successful. Check those steps and unwind prior registrations on failure. Do not check rtnl_register_many(): for built-in code it panics on failure, so the call cannot return an error to nexthop_init(). Cc: stable+noautosel@kernel.org # untested fix to unlikely error path Signed-off-by: Minhong He <heminhong@kylinos.cn> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20260731025249.80026-1-heminhong@kylinos.cn Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r--net/ipv4/nexthop.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index af1dcb8ea427..a7c2b8dced4e 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -4219,12 +4219,22 @@ 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;
- register_netdevice_notifier(&nh_netdev_notifier);
+ err = register_pernet_subsys(&nexthop_net_ops);
+ if (err)
+ return err;
+
+ err = register_netdevice_notifier(&nh_netdev_notifier);
+ if (err)
+ goto err_unregister_pernet;
rtnl_register_many(nexthop_rtnl_msg_handlers);
return 0;
+
+err_unregister_pernet:
+ unregister_pernet_subsys(&nexthop_net_ops);
+ return err;
}
subsys_initcall(nexthop_init);