From patchwork Thu Sep 14 06:59:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Wang X-Patchwork-Id: 28709 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2726A7D4E; Thu, 14 Sep 2017 09:12:34 +0200 (CEST) Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.217.80.70]) by dpdk.org (Postfix) with ESMTP id 414607CCD for ; Thu, 14 Sep 2017 09:12:32 +0200 (CEST) Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 29756AA819A84FF01C33; Thu, 14 Sep 2017 15:12:31 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v8E7COIh092173; Thu, 14 Sep 2017 15:12:24 +0800 (GMT-8) (envelope-from wang.yong19@zte.com.cn) Received: from localhost.localdomain.localdomain ([10.43.166.165]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017091415122839-2463745 ; Thu, 14 Sep 2017 15:12:28 +0800 From: Yong Wang To: shepard.siegel@atomicrules.com Cc: dev@dpdk.org, Yong Wang Date: Thu, 14 Sep 2017 02:59:13 -0400 Message-Id: <1505372353-24159-1-git-send-email-wang.yong19@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-09-14 15:12:28, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2017-09-14 15:12:11, Serialize complete at 2017-09-14 15:12:11 X-MAIL: mse01.zte.com.cn v8E7COIh092173 Subject: [dpdk-dev] [PATCH] net/ark:add null point check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" In function ark_config_device(), there are several malloc without null point check. Fix it by adding null point check. Signed-off-by: Yong Wang --- drivers/net/ark/ark_ethdev.c | 6 ++++++ drivers/net/ark/ark_pktchkr.c | 4 ++++ drivers/net/ark/ark_pktdir.c | 4 ++++ drivers/net/ark/ark_pktgen.c | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/drivers/net/ark/ark_ethdev.c b/drivers/net/ark/ark_ethdev.c index 6db362b..f5a834a 100644 --- a/drivers/net/ark/ark_ethdev.c +++ b/drivers/net/ark/ark_ethdev.c @@ -452,10 +452,16 @@ static void eth_ark_macaddr_remove(struct rte_eth_dev *dev, */ ark->start_pg = 0; ark->pg = ark_pktgen_init(ark->pktgen.v, 0, 1); + if (ark->pg == NULL) + return -1; ark_pktgen_reset(ark->pg); ark->pc = ark_pktchkr_init(ark->pktchkr.v, 0, 1); + if (ark->pc == NULL) + return -1; ark_pktchkr_stop(ark->pc); ark->pd = ark_pktdir_init(ark->pktdir.v); + if (ark->pd == NULL) + return -1; /* Verify HW */ if (ark_udm_verify(ark->udm.v)) diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c index c3040af..0bc8ae9 100644 --- a/drivers/net/ark/ark_pktchkr.c +++ b/drivers/net/ark/ark_pktchkr.c @@ -112,6 +112,10 @@ struct OPTIONS { struct ark_pkt_chkr_inst *inst = rte_malloc("ark_pkt_chkr_inst", sizeof(struct ark_pkt_chkr_inst), 0); + if (inst == NULL) { + PMD_DRV_LOG(ERR, "Failed to malloc ark_pkt_chkr_inst.\n"); + return inst; + } inst->sregs = (struct ark_pkt_chkr_stat_regs *)addr; inst->cregs = (struct ark_pkt_chkr_ctl_regs *)(((uint8_t *)addr) + 0x100); diff --git a/drivers/net/ark/ark_pktdir.c b/drivers/net/ark/ark_pktdir.c index 66e5ce2..e524fbe 100644 --- a/drivers/net/ark/ark_pktdir.c +++ b/drivers/net/ark/ark_pktdir.c @@ -45,6 +45,10 @@ rte_malloc("ark_pkt_dir_inst", sizeof(struct ark_pkt_dir_inst), 0); + if (inst == NULL) { + PMD_DRV_LOG(ERR, "Failed to malloc ark_pkt_dir_inst.\n"); + return inst; + } inst->regs = (struct ark_pkt_dir_regs *)base; inst->regs->ctrl = 0x00110110; /* POR state */ return inst; diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c index 8c7a8a2..018f37b 100644 --- a/drivers/net/ark/ark_pktgen.c +++ b/drivers/net/ark/ark_pktgen.c @@ -110,6 +110,10 @@ struct OPTIONS { struct ark_pkt_gen_inst *inst = rte_malloc("ark_pkt_gen_inst_pmd", sizeof(struct ark_pkt_gen_inst), 0); + if (inst == NULL) { + PMD_DRV_LOG(ERR, "Failed to malloc ark_pkt_gen_inst.\n"); + return inst; + } inst->regs = (struct ark_pkt_gen_regs *)adr; inst->ordinal = ord; inst->l2_mode = l2_mode;