diff options
author | YueHaibing <yuehaibing@huawei.com> | 2019-05-16 22:36:26 +0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-07-14 08:11:07 +0200 |
commit | 473a75c7fab5cdc90129795cc2581ac325b3d473 (patch) | |
tree | 7473b5213df22af88f4f681a77453ebaacb97052 /net/can | |
parent | 486954277fc1e18da5cf6c3110296b443cdecbaa (diff) | |
download | linux-stable-473a75c7fab5cdc90129795cc2581ac325b3d473.tar.gz linux-stable-473a75c7fab5cdc90129795cc2581ac325b3d473.tar.bz2 linux-stable-473a75c7fab5cdc90129795cc2581ac325b3d473.zip |
can: af_can: Fix error path of can_init()
[ Upstream commit c5a3aed1cd3152429348ee1fe5cdcca65fe901ce ]
This patch add error path for can_init() to avoid possible crash if some
error occurs.
Fixes: 0d66548a10cb ("[CAN]: Add PF_CAN core module")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net/can')
-rw-r--r-- | net/can/af_can.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/net/can/af_can.c b/net/can/af_can.c index e386d654116d..04132b0b5d36 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c @@ -959,6 +959,8 @@ static struct pernet_operations can_pernet_ops __read_mostly = { static __init int can_init(void) { + int err; + /* check for correct padding to be able to use the structs similarly */ BUILD_BUG_ON(offsetof(struct can_frame, can_dlc) != offsetof(struct canfd_frame, len) || @@ -972,15 +974,31 @@ static __init int can_init(void) if (!rcv_cache) return -ENOMEM; - register_pernet_subsys(&can_pernet_ops); + err = register_pernet_subsys(&can_pernet_ops); + if (err) + goto out_pernet; /* protocol register */ - sock_register(&can_family_ops); - register_netdevice_notifier(&can_netdev_notifier); + err = sock_register(&can_family_ops); + 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(&canfd_packet); 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) |