diff options
author | Marc Kleine-Budde <mkl@pengutronix.de> | 2017-07-29 05:51:01 -0400 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2017-10-19 07:05:54 -0400 |
commit | 5a606223c6b5b7560da253ed52e62c67fa18e29b (patch) | |
tree | 098958487eea2734994cbb5131508fa575c8d20e | |
parent | cae1d5b78fb4874086170ad07921bca59ea2e893 (diff) |
can: af_can: can_pernet_init(): add missing error handling for kzalloc returning NULL
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>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | net/can/af_can.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/net/can/af_can.c b/net/can/af_can.c index eb1ad74b40f4..ecd5c703d11e 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) | |||
875 | spin_lock_init(&net->can.can_rcvlists_lock); | 875 | spin_lock_init(&net->can.can_rcvlists_lock); |
876 | net->can.can_rx_alldev_list = | 876 | net->can.can_rx_alldev_list = |
877 | kzalloc(sizeof(struct dev_rcv_lists), GFP_KERNEL); | 877 | kzalloc(sizeof(struct dev_rcv_lists), GFP_KERNEL); |
878 | 878 | if (!net->can.can_rx_alldev_list) | |
879 | goto out; | ||
879 | net->can.can_stats = kzalloc(sizeof(struct s_stats), GFP_KERNEL); | 880 | net->can.can_stats = kzalloc(sizeof(struct s_stats), GFP_KERNEL); |
881 | if (!net->can.can_stats) | ||
882 | goto out_free_alldev_list; | ||
880 | net->can.can_pstats = kzalloc(sizeof(struct s_pstats), GFP_KERNEL); | 883 | net->can.can_pstats = kzalloc(sizeof(struct s_pstats), GFP_KERNEL); |
884 | if (!net->can.can_pstats) | ||
885 | goto out_free_can_stats; | ||
881 | 886 | ||
882 | if (IS_ENABLED(CONFIG_PROC_FS)) { | 887 | if (IS_ENABLED(CONFIG_PROC_FS)) { |
883 | /* the statistics are updated every second (timer triggered) */ | 888 | /* the statistics are updated every second (timer triggered) */ |
@@ -892,6 +897,13 @@ static int can_pernet_init(struct net *net) | |||
892 | } | 897 | } |
893 | 898 | ||
894 | return 0; | 899 | return 0; |
900 | |||
901 | out_free_can_stats: | ||
902 | kfree(net->can.can_stats); | ||
903 | out_free_alldev_list: | ||
904 | kfree(net->can.can_rx_alldev_list); | ||
905 | out: | ||
906 | return -ENOMEM; | ||
895 | } | 907 | } |
896 | 908 | ||
897 | static void can_pernet_exit(struct net *net) | 909 | static void can_pernet_exit(struct net *net) |