[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <lsq.1570043211.670489694@decadent.org.uk>
Date: Wed, 02 Oct 2019 20:06:51 +0100
From: Ben Hutchings <ben@...adent.org.uk>
To: linux-kernel@...r.kernel.org, stable@...r.kernel.org
CC: akpm@...ux-foundation.org, Denis Kirjanov <kda@...ux-powerpc.org>,
"Oliver Hartkopp" <socketcan@...tkopp.net>,
"YueHaibing" <yuehaibing@...wei.com>,
"Marc Kleine-Budde" <mkl@...gutronix.de>
Subject: [PATCH 3.16 50/87] can: af_can: Fix error path of can_init()
3.16.75-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: YueHaibing <yuehaibing@...wei.com>
commit c5a3aed1cd3152429348ee1fe5cdcca65fe901ce upstream.
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@...wei.com>
Acked-by: Oliver Hartkopp <socketcan@...tkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@...gutronix.de>
[bwh: Backported to 3.16:
- af_can doesn't register any pernet_operations
- It does start a global timer and add procfs entries that need to be
cleaned up on the error path]
Signed-off-by: Ben Hutchings <ben@...adent.org.uk>
---
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -899,6 +899,8 @@ static struct notifier_block can_netdev_
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) ||
@@ -924,12 +926,29 @@ static __init int can_init(void)
can_init_proc();
/* 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:
+ kmem_cache_destroy(rcv_cache);
+
+ if (stats_timer)
+ del_timer_sync(&can_stattimer);
+
+ can_remove_proc();
+
+ return err;
}
static __exit void can_exit(void)
Powered by blists - more mailing lists