summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZiyang Xuan <william.xuanziyang@huawei.com>2022-09-15 03:55:55 +0200
committerMarc Kleine-Budde <mkl@pengutronix.de>2022-09-23 13:53:02 +0200
commitedd1a7e42f1d2d09c5f79ecef05ae19dc669bf34 (patch)
tree2e8318214c8989c304c3364beaaab56bff0f49a6
parentMerge branch 'net-dsa-remove-unnecessary-set_drvdata' (diff)
downloadlinux-edd1a7e42f1d2d09c5f79ecef05ae19dc669bf34.tar.xz
linux-edd1a7e42f1d2d09c5f79ecef05ae19dc669bf34.zip
can: bcm: registration process optimization in bcm_module_init()
Now, register_netdevice_notifier() and register_pernet_subsys() are both after can_proto_register(). It can create CAN_BCM socket and process socket once can_proto_register() successfully, so it is possible missing notifier event or proc node creation because notifier or bcm proc directory is not registered or created yet. Although this is a low probability scenario, it is not impossible. Move register_pernet_subsys() and register_netdevice_notifier() to the front of can_proto_register(). In addition, register_pernet_subsys() and register_netdevice_notifier() may fail, check their results are necessary. Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com> Link: https://lore.kernel.org/all/823cff0ebec33fa9389eeaf8b8ded3217c32cb38.1663206163.git.william.xuanziyang@huawei.com Acked-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r--net/can/bcm.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/net/can/bcm.c b/net/can/bcm.c
index e5d179ba6f7d..0a2adb844280 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -1749,15 +1749,27 @@ static int __init bcm_module_init(void)
pr_info("can: broadcast manager protocol\n");
+ err = register_pernet_subsys(&canbcm_pernet_ops);
+ if (err)
+ return err;
+
+ err = register_netdevice_notifier(&canbcm_notifier);
+ if (err)
+ goto register_notifier_failed;
+
err = can_proto_register(&bcm_can_proto);
if (err < 0) {
printk(KERN_ERR "can: registration of bcm protocol failed\n");
- return err;
+ goto register_proto_failed;
}
- register_pernet_subsys(&canbcm_pernet_ops);
- register_netdevice_notifier(&canbcm_notifier);
return 0;
+
+register_proto_failed:
+ unregister_netdevice_notifier(&canbcm_notifier);
+register_notifier_failed:
+ unregister_pernet_subsys(&canbcm_pernet_ops);
+ return err;
}
static void __exit bcm_module_exit(void)