From mboxrd@z Thu Jan 1 00:00:00 1970 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) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 17 Jul 2015 01:16:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,494,1432623600"; d="scan'208";a="749176572" Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.208.67]) by fmsmga001.fm.intel.com with SMTP; 17 Jul 2015 01:16:04 -0700 Received: by (sSMTP sendmail emulation); Fri, 17 Jul 2015 09:16:03 +0025 Date: Fri, 17 Jul 2015 09:16:03 +0100 From: Bruce Richardson To: Stephen Hemminger 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 Content-Disposition: inline In-Reply-To: <1437090444-24953-2-git-send-email-stephen@networkplumber.org> Organization: Intel Shannon Ltd. User-Agent: Mutt/1.5.23 (2014-03-12) Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH 1/2] rte_ethdev: fix crash if malloc fails in rte_eth_dev_callback_register X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jul 2015 08:16:07 -0000 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