From 53a9ba132c0cec168dc7ffcf07506326afeccb0e Mon Sep 17 00:00:00 2001 From: Yong Wang Date: Thu, 14 Sep 2017 08:03:56 -0400 Subject: [PATCH] net/ark: add null pointer check 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 Acked-by: Ed Czeck --- drivers/net/ark/ark_ethdev.c | 6 ++++++ drivers/net/ark/ark_pktchkr.c | 4 ++++ drivers/net/ark/ark_pktdir.c | 5 +++++ drivers/net/ark/ark_pktgen.c | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/drivers/net/ark/ark_ethdev.c b/drivers/net/ark/ark_ethdev.c index 5069159bd2..ba25a9d297 100644 --- a/drivers/net/ark/ark_ethdev.c +++ b/drivers/net/ark/ark_ethdev.c @@ -451,10 +451,16 @@ ark_config_device(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 c3040af3c7..202a1d9be8 100644 --- a/drivers/net/ark/ark_pktchkr.c +++ b/drivers/net/ark/ark_pktchkr.c @@ -112,6 +112,10 @@ ark_pktchkr_init(void *addr, int ord, int l2_mode) 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 66e5ce244d..eb47dedb04 100644 --- a/drivers/net/ark/ark_pktdir.c +++ b/drivers/net/ark/ark_pktdir.c @@ -36,6 +36,7 @@ #include "ark_pktdir.h" #include "ark_global.h" +#include "ark_logs.h" ark_pkt_dir_t @@ -45,6 +46,10 @@ ark_pktdir_init(void *base) 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 8c7a8a2d74..018f37b697 100644 --- a/drivers/net/ark/ark_pktgen.c +++ b/drivers/net/ark/ark_pktgen.c @@ -110,6 +110,10 @@ ark_pktgen_init(void *adr, int ord, int l2_mode) 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; -- 2.20.1