DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 1/2] rte_ethdev: fix crash if malloc fails in rte_eth_dev_callback_register
Date: Thu, 16 Jul 2015 16:47:23 -0700	[thread overview]
Message-ID: <1437090444-24953-2-git-send-email-stephen@networkplumber.org> (raw)
In-Reply-To: <1437090444-24953-1-git-send-email-stephen@networkplumber.org>

Found by coccinelle script.  If rte_zmalloc() failed in rte_eth_dev_callback_register
then NULL pointer would be dereferenced.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_ether/rte_ethdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index ddf3658..aa363be 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -2929,9 +2929,10 @@ rte_eth_dev_callback_register(uint8_t port_id,
 	}
 
 	/* create a new callback. */
-	if (user_cb == NULL &&
-	    (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
-				   sizeof(struct rte_eth_dev_callback), 0))) {
+	if (!user_cb)
+	    user_cb = rte_zmalloc("INTR_USER_CALLBACK",
+				  sizeof(struct rte_eth_dev_callback), 0);
+	if (user_cb) {
 		user_cb->cb_fn = cb_fn;
 		user_cb->cb_arg = cb_arg;
 		user_cb->event = event;
-- 
2.1.4

  reply	other threads:[~2015-07-16 23:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-16 23:47 [dpdk-dev] [PATCH 0/2] static matcher cleanups Stephen Hemminger
2015-07-16 23:47 ` Stephen Hemminger [this message]
2015-07-17  8:16   ` [dpdk-dev] [PATCH 1/2] rte_ethdev: fix crash if malloc fails in rte_eth_dev_callback_register Bruce Richardson
2015-07-22 13:54     ` Thomas Monjalon
2015-07-16 23:47 ` [dpdk-dev] [PATCH 2/2] kni: fix coccinelle warnings Stephen Hemminger
2015-07-22 14:25 ` [dpdk-dev] [PATCH 0/2] static matcher cleanups Thomas Monjalon

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=1437090444-24953-2-git-send-email-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).