All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: "Sjur Brændeland" <sjurbren@gmail.com>,
	"David Miller" <davem@davemloft.net>
Cc: netdev <netdev@vger.kernel.org>
Subject: [PATCH]  caif: fix a potential NULL dereference
Date: Fri, 02 Sep 2011 14:19:23 +0200	[thread overview]
Message-ID: <1314965963.2573.23.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC> (raw)
In-Reply-To: <CAJK669Yb6V=xr9ZvQGOKGEvmzO1JGhrHD+sR69b04EQxUjOOrQ@mail.gmail.com>

Commit bd30ce4bc0b7 (caif: Use RCU instead of spin-lock in caif_dev.c)
added a potential NULL dereference in case alloc_percpu() fails.

caif_device_alloc() can also use GFP_KERNEL instead of GFP_ATOMIC.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
CC: Sjur Brændeland <sjur.brandeland@stericsson.com>
---
 net/caif/caif_dev.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c
index 7c2fa0a..7f9ac07 100644
--- a/net/caif/caif_dev.c
+++ b/net/caif/caif_dev.c
@@ -93,10 +93,14 @@ static struct caif_device_entry *caif_device_alloc(struct net_device *dev)
 	caifdevs = caif_device_list(dev_net(dev));
 	BUG_ON(!caifdevs);
 
-	caifd = kzalloc(sizeof(*caifd), GFP_ATOMIC);
+	caifd = kzalloc(sizeof(*caifd), GFP_KERNEL);
 	if (!caifd)
 		return NULL;
 	caifd->pcpu_refcnt = alloc_percpu(int);
+	if (!caifd->pcpu_refcnt) {
+		kfree(caifd);
+		return NULL;
+	}
 	caifd->netdev = dev;
 	dev_hold(dev);
 	return caifd;

  reply	other threads:[~2011-09-02 12:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-02  8:07 [patch -next] caif: add error handling for allocation Dan Carpenter
2011-09-02  8:07 ` Dan Carpenter
2011-09-02  9:40 ` Sjur Brændeland
2011-09-02  9:40   ` Sjur Brændeland
2011-09-02 12:19   ` Eric Dumazet [this message]
2011-09-02 13:13     ` [PATCH] caif: fix a potential NULL dereference Sjur Brændeland
2011-09-16 22:56     ` David Miller
2011-09-02 15:51   ` [patch -next] caif: add error handling for allocation Dan Carpenter
2011-09-02 15:51     ` Dan Carpenter
2011-09-21  7:21   ` [patch v2] " Dan Carpenter
2011-09-21  7:21     ` Dan Carpenter
2011-09-23 10:38     ` Sjur BRENDELAND
2011-09-23 10:38       ` Sjur BRENDELAND
2011-10-03 17:46       ` David Miller
2011-10-03 17:46         ` 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=1314965963.2573.23.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=sjurbren@gmail.com \
    /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.