Commit c5a3aed1 authored by YueHaibing's avatar YueHaibing Committed by Marc Kleine-Budde

can: af_can: Fix error path of can_init()

This patch add error path for can_init() to avoid possible crash if some
error occurs.

Fixes: 0d66548a ("[CAN]: Add PF_CAN core module")
Signed-off-by: default avatarYueHaibing <yuehaibing@huawei.com>
Acked-by: default avatarOliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 3e82f2f3
...@@ -952,6 +952,8 @@ static struct pernet_operations can_pernet_ops __read_mostly = { ...@@ -952,6 +952,8 @@ static struct pernet_operations can_pernet_ops __read_mostly = {
static __init int can_init(void) static __init int can_init(void)
{ {
int err;
/* check for correct padding to be able to use the structs similarly */ /* check for correct padding to be able to use the structs similarly */
BUILD_BUG_ON(offsetof(struct can_frame, can_dlc) != BUILD_BUG_ON(offsetof(struct can_frame, can_dlc) !=
offsetof(struct canfd_frame, len) || offsetof(struct canfd_frame, len) ||
...@@ -965,15 +967,31 @@ static __init int can_init(void) ...@@ -965,15 +967,31 @@ static __init int can_init(void)
if (!rcv_cache) if (!rcv_cache)
return -ENOMEM; return -ENOMEM;
register_pernet_subsys(&can_pernet_ops); err = register_pernet_subsys(&can_pernet_ops);
if (err)
goto out_pernet;
/* protocol register */ /* protocol register */
sock_register(&can_family_ops); err = sock_register(&can_family_ops);
register_netdevice_notifier(&can_netdev_notifier); if (err)
goto out_sock;
err = register_netdevice_notifier(&can_netdev_notifier);
if (err)
goto out_notifier;
dev_add_pack(&can_packet); dev_add_pack(&can_packet);
dev_add_pack(&canfd_packet); dev_add_pack(&canfd_packet);
return 0; return 0;
out_notifier:
sock_unregister(PF_CAN);
out_sock:
unregister_pernet_subsys(&can_pernet_ops);
out_pernet:
kmem_cache_destroy(rcv_cache);
return err;
} }
static __exit void can_exit(void) static __exit void can_exit(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment