summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2017-07-29 11:51:01 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-10-27 10:39:11 +0200
commit8f0a7b0262eea5796bc6b9c4c639bf44f395d7ee (patch)
tree3831681f9a476ced5379a0697c1d349d96d6f6ab /net
parent5463bc9a46f2484012ab147c6483aa3973f47665 (diff)
can: af_can: can_pernet_init(): add missing error handling for kzalloc returning NULL
commit 5a606223c6b5b7560da253ed52e62c67fa18e29b upstream. This patch adds the missing check and error handling for out-of-memory situations, when kzalloc cannot allocate memory. Fixes: cb5635a36776 ("can: complete initial namespace support") Acked-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net')
-rw-r--r--net/can/af_can.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/net/can/af_can.c b/net/can/af_can.c
index 88edac0f3e36..df186cdcc2b4 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -875,9 +875,14 @@ static int can_pernet_init(struct net *net)
spin_lock_init(&net->can.can_rcvlists_lock);
net->can.can_rx_alldev_list =
kzalloc(sizeof(struct dev_rcv_lists), GFP_KERNEL);
-
+ if (!net->can.can_rx_alldev_list)
+ goto out;
net->can.can_stats = kzalloc(sizeof(struct s_stats), GFP_KERNEL);
+ if (!net->can.can_stats)
+ goto out_free_alldev_list;
net->can.can_pstats = kzalloc(sizeof(struct s_pstats), GFP_KERNEL);
+ if (!net->can.can_pstats)
+ goto out_free_can_stats;
if (IS_ENABLED(CONFIG_PROC_FS)) {
/* the statistics are updated every second (timer triggered) */
@@ -892,6 +897,13 @@ static int can_pernet_init(struct net *net)
}
return 0;
+
+ out_free_can_stats:
+ kfree(net->can.can_stats);
+ out_free_alldev_list:
+ kfree(net->can.can_rx_alldev_list);
+ out:
+ return -ENOMEM;
}
static void can_pernet_exit(struct net *net)