Re: [PATCH net] batman-adv: check register_netdevice_notifier() and rtnl_link_register() errors
Sven Eckelmann <[email protected]> Tue, 28 Jul 2026 09:04:37 +0200
| Newsgroups | org.open-mesh.lists.batman,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <14518281.RDIVbhacDa@sven-l14> |
--nextPart14061147.dW097sEU6C Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8"; protected-headers="v1" From: Sven Eckelmann <[email protected]> Date: Tue, 28 Jul 2026 09:04:37 +0200 Message-ID: <14518281.RDIVbhacDa@sven-l14> In-Reply-To: <[email protected]> References: <[email protected]> MIME-Version: 1.0 On Tuesday, 28 July 2026 05:10:50 CEST Minhong He wrote: > batadv_init() ignores errors from register_netdevice_notifier() and > rtnl_link_register(), so the module can load without those registrations > in place. > > Check both return values and unwind prior initialization in reverse order > of acquisition on failure. > > Signed-off-by: Minhong He <[email protected]> > --- > net/batman-adv/main.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) This is not for the net tree/repo. So please don't mark it as such. You must target the batadv tree/repo. > > diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c > index 73becb054948..e6bcaf2d14ed 100644 > --- a/net/batman-adv/main.c > +++ b/net/batman-adv/main.c > @@ -108,8 +108,14 @@ static int __init batadv_init(void) > if (ret < 0) > goto err_init_wifi; > > - register_netdevice_notifier(&batadv_hard_if_notifier); > - rtnl_link_register(&batadv_link_ops); > + ret = register_netdevice_notifier(&batadv_hard_if_notifier); > + if (ret < 0) > + goto err_reg_notifier; > + > + ret = rtnl_link_register(&batadv_link_ops); > + if (ret < 0) > + goto err_rtnl_link; > + > batadv_netlink_register(); You missed the error handling for: * batadv_netlink_register() - doesn't require a cleanup call now but it would be batadv_netlink_unregister() - the error must be returned from this function * batadv_iv_init() - no special cleanup call - but if you want to add one, please add a deinit wrapper around batadv_recv_handler_unregister(BATADV_IV_OGM); in bat_iv_ogm.c * batadv_v_init() - no special cleanup call - but if you want to add one, please add a deinit wrapper around batadv_recv_handler_unregister(BATADV_OGM2); batadv_recv_handler_unregister(BATADV_ELP); in bat_v.c and make sure you have a dummy variant in bat_v.h And please adjust the subject to something which doesn't list all the new things you check for errors. > > pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n", > @@ -117,6 +123,10 @@ static int __init batadv_init(void) > > return 0; > > +err_rtnl_link: > + unregister_netdevice_notifier(&batadv_hard_if_notifier); > +err_reg_notifier: > + batadv_wifi_net_devices_deinit(); There must be an rcu_barrier() before batadv_wifi_net_devices_deinit(). > err_init_wifi: > destroy_workqueue(batadv_event_workqueue); > batadv_event_workqueue = NULL; > See: * https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/[email protected]/ * https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/[email protected]/ * https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/[email protected]/ Regards, Sven --nextPart14061147.dW097sEU6C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQS81G/PswftH/OW8cVND3cr0xT1ywUCamhUhQAKCRBND3cr0xT1 y9xPAP0TcOwhSmzGpyEm/Y0L2luIuJwREfWzXXhBYoGRrXsClgEA04aThrUmH4Vl rUZiwjTomCo/LIw96MOl/rpIf4YM/QI= =nCo3 -----END PGP SIGNATURE----- --nextPart14061147.dW097sEU6C--