[v2] drivers: ifpga_rawdev: fix fd leak in rte_fpga_do_pr

Message ID 20190410134313.5815-1-liq3ea@163.com
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • [v2] drivers: ifpga_rawdev: fix fd leak in rte_fpga_do_pr
Related show

Checks

Context Check Description
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Li Qiang April 10, 2019, 1:43 p.m.
In rte_fpga_do_pr() function, if 'stat' return error the
'file_fd' is never closed thus leading a fd leak. This patch
avoids this.

Spotted by Coverity: CID 27441

Signed-off-by: Li Qiang <liq3ea@163.com>
---
Changes since v1: fill ret before goto close_fd per Rosen's review

 drivers/raw/ifpga_rawdev/ifpga_rawdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Xu, Rosen April 11, 2019, 12:28 a.m. | #1
> -----Original Message-----
> From: Li Qiang [mailto:liq3ea@163.com]
> Sent: Wednesday, April 10, 2019 21:43
> To: Xu, Rosen <rosen.xu@intel.com>; Zhang, Tianfei
> <tianfei.zhang@intel.com>
> Cc: dev@dpdk.org; liq3ea@gmail.com; Li Qiang <liq3ea@163.com>
> Subject: [PATCH v2] drivers: ifpga_rawdev: fix fd leak in rte_fpga_do_pr
> 
> In rte_fpga_do_pr() function, if 'stat' return error the 'file_fd' is never closed
> thus leading a fd leak. This patch avoids this.

It's a bug fix, so pls add 'Fix XXX'.
 
> Spotted by Coverity: CID 27441

It should be Coverity issue: 279441

> Signed-off-by: Li Qiang <liq3ea@163.com>

pls add:
Cc: stable@dpdk.org

> ---
> Changes since v1: fill ret before goto close_fd per Rosen's review
> 
>  drivers/raw/ifpga_rawdev/ifpga_rawdev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
> b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
> index da772d026..eff001b59 100644
> --- a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
> +++ b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
> @@ -244,7 +244,8 @@ rte_fpga_do_pr(struct rte_rawdev *rawdev, int
> port_id,
>  	if (ret) {
>  		IFPGA_RAWDEV_PMD_ERR("stat on bitstream file
> failed: %s\n",
>  				file_name);
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto close_fd;
>  	}
>  	buffer_size = file_stat.st_size;
>  	IFPGA_RAWDEV_PMD_INFO("bitstream file size: %zu\n", buffer_size);
> --
> 2.17.1
>

Patch

diff --git a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
index da772d026..eff001b59 100644
--- a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
+++ b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
@@ -244,7 +244,8 @@  rte_fpga_do_pr(struct rte_rawdev *rawdev, int port_id,
 	if (ret) {
 		IFPGA_RAWDEV_PMD_ERR("stat on bitstream file failed: %s\n",
 				file_name);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto close_fd;
 	}
 	buffer_size = file_stat.st_size;
 	IFPGA_RAWDEV_PMD_INFO("bitstream file size: %zu\n", buffer_size);