From: Bruce Richardson Subject: Re: [PATCH 1/2] rte_ethdev: fix crash if malloc fails in rte_eth_dev_callback_register Date: Fri, 17 Jul 2015 09:16:03 +0100 Message-ID: <20150717081603.GB11996@bricha3-MOBL3> References: <1437090444-24953-1-git-send-email-stephen@networkplumber.org> <1437090444-24953-2-git-send-email-stephen@networkplumber.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: dev@dpdk.org To: Stephen Hemminger Return-path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 65F846942 for ; Fri, 17 Jul 2015 10:16:07 +0200 (CEST) Content-Disposition: inline In-Reply-To: <1437090444-24953-2-git-send-email-stephen@networkplumber.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Thu, Jul 16, 2015 at 04:47:23PM -0700, Stephen Hemminger wrote: > 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 > --- > 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) Minor style issue. Since user_cb is a pointer, not a boolean, the condition should use "== NULL" rather than "!". /Bruce