From mboxrd@z Thu Jan 1 00:00:00 1970 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) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BjUT1psUT8wZx66PRGIVPHJMwdE14ifr91VT5VtxL5w=; b=YNYoL6qR0mdQF1CAyggC5MPcmrRiXoD/AxoS2k7iCrXl5HUzsIwF9s1UDEGz3TzHor eJTpvZKnBv8pCYMagajSQnZlwkCOHY5A/kvO3DKD0mOfJ6yfV4ld+7kuJvd1aED8AZHl U0VdOoz8pvrixFT7+Enuoq6eIQyrsfwIPqSPJ2mqroazxQBPBY14Iei2RyqCZRQL0qTg rHmMab4lihgTKqq/PzrmQ4JVkyDC+jE1RrM0P+rI2WR+gqR7MIMqoaw+CN2f/1Blk/pS IWcRITA5bY27JoAVpNeWjFTfpTc89+jK6V2gNu1s197ORRWoCYkaFcMKyAtCEyoQbuk8 ltfQ== X-Gm-Message-State: ALoCoQmk+XAN2jm3lcsJ1XKymDNOchhfWcLamKoS2l/Vjo1VVR3vcJQdG1MuyR4Af2xxqCLv+APX X-Received: by 10.70.131.73 with SMTP id ok9mr23349655pdb.109.1437090440872; Thu, 16 Jul 2015 16:47:20 -0700 (PDT) Received: from urahara.home.lan (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by smtp.gmail.com with ESMTPSA id sd7sm9059134pbb.93.2015.07.16.16.47.18 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Jul 2015 16:47:19 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Date: Thu, 16 Jul 2015 16:47:23 -0700 Message-Id: <1437090444-24953-2-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1437090444-24953-1-git-send-email-stephen@networkplumber.org> References: <1437090444-24953-1-git-send-email-stephen@networkplumber.org> Subject: [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: Thu, 16 Jul 2015 23:47:22 -0000 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