From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: [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 Message-ID: <1437090444-24953-2-git-send-email-stephen@networkplumber.org> References: <1437090444-24953-1-git-send-email-stephen@networkplumber.org> To: dev@dpdk.org Return-path: Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by dpdk.org (Postfix) with ESMTP id 66F60376D for ; Fri, 17 Jul 2015 01:47:21 +0200 (CEST) Received: by padck2 with SMTP id ck2so50274694pad.0 for ; Thu, 16 Jul 2015 16:47:20 -0700 (PDT) In-Reply-To: <1437090444-24953-1-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" 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) + 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