[dpdk-dev] drivers/bus/ifpga/: fix Coverity issue

Message ID 1526478506-153943-1-git-send-email-rosen.xu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Xu, Rosen May 16, 2018, 1:48 p.m. UTC
  Fix Coverity issue: 279455, 279459 and 279454

Signed-off-by: Rosen Xu <rosen.xu@intel.com>

Fixes: 05fa3d4a6539 ("bus/ifpga: add Intel FPGA bus library")
Coverity issue: 279455, 279459 and 279454
Cc: stable@dpdk.org
---
 drivers/bus/ifpga/ifpga_bus.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
  

Comments

Thomas Monjalon May 21, 2018, 2 p.m. UTC | #1
16/05/2018 15:48, Rosen Xu:
> Fix Coverity issue: 279455, 279459 and 279454
> 
> Signed-off-by: Rosen Xu <rosen.xu@intel.com>
> 
> Fixes: 05fa3d4a6539 ("bus/ifpga: add Intel FPGA bus library")
> Coverity issue: 279455, 279459 and 279454
> Cc: stable@dpdk.org

The commit message should explain what was the issue.

FYI, it should look like this:

"
bus/ifpga: fix <scope of the change>

<explanation of the issue>

Coverity issue: 279455, 279459, 279454
Fixes: 05fa3d4a6539 ("bus/ifpga: add Intel FPGA bus library")
Cc: stable@dpdk.org

Signed-off-by: Rosen Xu <rosen.xu@intel.com>
"
  
Xu, Rosen May 22, 2018, 10:26 a.m. UTC | #2
This patch set fix bus/ifpga coverity issue: 279455, 279459 and 279454

v2 updates:
===========
 - Add more description, devide to 3 patches

v1 updates:
===========
 - Fix Coverity issue: 279455, 279459 and 279454

Rosen Xu (3):
  bus/ifpga: fix error control flow issue
  bus/ifpga: fix resource leaks issue
  bus/ifpga: fix null pointer dereferences issue

 drivers/bus/ifpga/ifpga_bus.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
  
Thomas Monjalon May 22, 2018, 3:15 p.m. UTC | #3
> Rosen Xu (3):
>   bus/ifpga: fix error control flow issue
>   bus/ifpga: fix resource leaks issue
>   bus/ifpga: fix null pointer dereferences issue

Applied, thanks
  
Xu, Rosen May 23, 2018, 12:26 a.m. UTC | #4
Thanks a lot Thomas.

> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Tuesday, May 22, 2018 23:16
> To: Xu, Rosen <rosen.xu@intel.com>
> Cc: dev@dpdk.org; Zhang, Roy Fan <roy.fan.zhang@intel.com>; Doherty,
> Declan <declan.doherty@intel.com>; Richardson, Bruce
> <bruce.richardson@intel.com>; shreyansh.jain@nxp.com; Yigit, Ferruh
> <ferruh.yigit@intel.com>; Ananyev, Konstantin
> <konstantin.ananyev@intel.com>; Zhang, Tianfei <tianfei.zhang@intel.com>;
> Liu, Song <song.liu@intel.com>; Wu, Hao <hao.wu@intel.com>;
> gaetan.rivet@6wind.com
> Subject: Re: [dpdk-dev] [PATCH v2 0/3] Fix bus/ifpga coverity issue: 279455,
> 279459 and 279454
> 
> > Rosen Xu (3):
> >   bus/ifpga: fix error control flow issue
> >   bus/ifpga: fix resource leaks issue
> >   bus/ifpga: fix null pointer dereferences issue
> 
> Applied, thanks
> 
>
  

Patch

diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index 45597a1..b324872 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -156,27 +156,30 @@  void rte_ifpga_driver_unregister(struct rte_afu_driver *driver)
 	if (rawdev->dev_ops &&
 		rawdev->dev_ops->dev_start &&
 		rawdev->dev_ops->dev_start(rawdev))
-		goto free_dev;
+		goto end;
 
 	strlcpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
-	if (rawdev->dev_ops->firmware_load &&
+	if (rawdev->dev_ops &&
+		rawdev->dev_ops->firmware_load &&
 		rawdev->dev_ops->firmware_load(rawdev,
 				&afu_pr_conf)){
 		IFPGA_BUS_ERR("firmware load error %d\n", ret);
-		goto free_dev;
+		goto end;
 	}
 	afu_dev->id.uuid.uuid_low  = afu_pr_conf.afu_id.uuid.uuid_low;
 	afu_dev->id.uuid.uuid_high = afu_pr_conf.afu_id.uuid.uuid_high;
 
+	rte_kvargs_free(kvlist);
+	free(path);
 	return afu_dev;
 
-free_dev:
-	free(afu_dev);
 end:
 	if (kvlist)
 		rte_kvargs_free(kvlist);
 	if (path)
 		free(path);
+	if (afu_dev)
+		free(afu_dev);
 
 	return NULL;
 }
@@ -367,7 +370,7 @@  void rte_ifpga_driver_unregister(struct rte_afu_driver *driver)
 		return -EINVAL;
 
 	afu_dev = RTE_DEV_TO_AFU(dev);
-	if (!dev)
+	if (!afu_dev)
 		return -ENOENT;
 
 	devargs = dev->devargs;