Skip to content

Commit

Permalink
can: af_can: can_pernet_init(): add missing error handling for kzallo…
Browse files Browse the repository at this point in the history
…c returning NULL

This patch adds the missing check and error handling for out-of-memory
situations, when kzalloc cannot allocate memory.

Fixes: cb5635a ("can: complete initial namespace support")
Acked-by: Oliver Hartkopp <[email protected]>
Cc: linux-stable <[email protected]>
Signed-off-by: Marc Kleine-Budde <[email protected]>
  • Loading branch information
marckleinebudde committed Oct 19, 2017
1 parent cae1d5b commit 5a60622
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion net/can/af_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand All @@ -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)
Expand Down

0 comments on commit 5a60622

Please sign in to comment.