All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, linux-can@vger.kernel.org,
	kernel@pengutronix.de, Marc Kleine-Budde <mkl@pengutronix.de>,
	linux-stable <stable@vger.kernel.org>
Subject: [PATCH 09/11] can: af_can: can_pernet_init(): add missing error handling for kzalloc returning NULL
Date: Thu, 19 Oct 2017 13:19:43 +0200	[thread overview]
Message-ID: <20171019111945.13580-10-mkl@pengutronix.de> (raw)
In-Reply-To: <20171019111945.13580-1-mkl@pengutronix.de>

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>
---
 net/can/af_can.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

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)
 	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)
-- 
2.14.2

  parent reply	other threads:[~2017-10-19 11:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 01/11] can: flexcan: fix state transition regression Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 02/11] can: flexcan: rename legacy error state quirk Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 03/11] can: flexcan: implement error passive " Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 04/11] can: flexcan: fix i.MX6 state transition issue Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 05/11] can: flexcan: fix i.MX28 " Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 06/11] can: flexcan: fix p1010 " Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 07/11] can: bcm: check for null sk before deferencing it via the call to sock_net Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 08/11] can: af_can: do not access proto_tab directly use rcu_access_pointer instead Marc Kleine-Budde
2017-10-19 11:19 ` Marc Kleine-Budde [this message]
2017-10-19 11:19 ` [PATCH 10/11] can: esd_usb2: Fix can_dlc value for received RTR, frames Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 11/11] can: gs_usb: fix busy loop if no more TX context is available Marc Kleine-Budde
2017-10-21  1:30 ` pull-request: can 2017-10-19 David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171019111945.13580-10-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.