]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
can: isotp: check register_netdevice_notifier() error in module init
authorMinhong He <heminhong@kylinos.cn>
Wed, 29 Jul 2026 08:56:56 +0000 (16:56 +0800)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 29 Jul 2026 09:26:41 +0000 (11:26 +0200)
Register the netdevice notifier before can_proto_register() and check the
return value. If protocol registration fails, unregister the notifier
before returning the error.

Align isotp_module_init() with the reordering already done for raw.c
(commit c28b3bffe49e ("can: raw: process optimization in raw_init()")) and
bcm.c (commit edd1a7e42f1d ("can: bcm: registration process optimization
in bcm_module_init()")).

Fixes: 8d0caedb7596 ("can: bcm/raw/isotp: use per module netdevice notifier")
Signed-off-by: Minhong He <heminhong@kylinos.cn>
Link: https://patch.msgid.link/20260729085656.134523-1-heminhong@kylinos.cn
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
net/can/isotp.c

index 1f11c66b343c86d1cfef375ca077c3ad997f0e9d..155530aedce2e366fc92f7eeec99ec3718c08596 100644 (file)
@@ -2050,13 +2050,18 @@ static __init int isotp_module_init(void)
 
        pr_info("can: isotp protocol (max_pdu_size %d)\n", max_pdu_size);
 
+       err = register_netdevice_notifier(&canisotp_notifier);
+       if (err)
+               return err;
+
        err = can_proto_register(&isotp_can_proto);
-       if (err < 0)
+       if (err < 0) {
                pr_err("can: registration of isotp protocol failed %pe\n", ERR_PTR(err));
-       else
-               register_netdevice_notifier(&canisotp_notifier);
+               unregister_netdevice_notifier(&canisotp_notifier);
+               return err;
+       }
 
-       return err;
+       return 0;
 }
 
 static __exit void isotp_module_exit(void)