raw/ifpga: fix fd leak in rte fpga do pr

Message ID 1555483757-48188-1-git-send-email-andy.pei@intel.com
State Superseded, archived
Headers show
Series
  • raw/ifpga: fix fd leak in rte fpga do pr
Related show

Checks

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

Commit Message

Pei, Andy April 17, 2019, 6:49 a.m.
In rte_fpga_do_pr() function, if 'stat' returns error,
rte_fpga_do_pr() returns -EINVAL without closing the
'file_fd' that has been opened.
After this patch, 'file_fd' is closed before rte_fpga_do_pr()
returns -EINVAL when 'stat' returns error

Fixes: ef1e8ede3da5 ("raw/ifpga: add Intel FPGA bus rawdev driver")
Cc: rosen.xu@intel.com
Cc: marko.kovacevic@intel.com
Cc: liq3ea@163.com
Cc: andy.pei@intel.com
Cc: stable@dpdk.org

Signed-off-by: Andy Pei <andy.pei@intel.com>
---
---
 drivers/raw/ifpga_rawdev/ifpga_rawdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Rosen Xu April 17, 2019, 7:14 a.m. | #1
Hi,

> -----Original Message-----
> From: Pei, Andy
> Sent: Wednesday, April 17, 2019 14:49
> To: dev@dpdk.org
> Cc: Pei, Andy <andy.pei@intel.com>; Xu, Rosen <rosen.xu@intel.com>;
> Kovacevic, Marko <marko.kovacevic@intel.com>; liq3ea@163.com;
> stable@dpdk.org
> Subject: [PATCH] raw/ifpga: fix fd leak in rte fpga do pr

Pls use raw/ifpga_rawdev prefix.
I suggest you to run ./devtools/check-git-log.sh -1 before you sending patch.

> In rte_fpga_do_pr() function, if 'stat' returns error,
> rte_fpga_do_pr() returns -EINVAL without closing the 'file_fd' that has been
> opened.
> After this patch, 'file_fd' is closed before rte_fpga_do_pr() returns -EINVAL
> when 'stat' returns error

Pls put this in the commit message:
Coverity issue: 279441
 
> Fixes: ef1e8ede3da5 ("raw/ifpga: add Intel FPGA bus rawdev driver")
> Cc: rosen.xu@intel.com
> Cc: marko.kovacevic@intel.com
> Cc: liq3ea@163.com
> Cc: andy.pei@intel.com
> Cc: stable@dpdk.org
>
> Signed-off-by: Andy Pei <andy.pei@intel.com>
> ---
> ---
>  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 da772d0..eff001b 100644
> --- a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
> +++ b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
> @@ -244,7 +244,8 @@
>  	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);
> --
> 1.8.3.1
Pei, Andy April 17, 2019, 7:17 a.m. | #2
Okay

-----Original Message-----
From: Xu, Rosen 
Sent: Wednesday, April 17, 2019 3:14 PM
To: Pei, Andy <andy.pei@intel.com>; dev@dpdk.org
Cc: Kovacevic, Marko <marko.kovacevic@intel.com>; liq3ea@163.com; stable@dpdk.org
Subject: RE: [PATCH] raw/ifpga: fix fd leak in rte fpga do pr

Hi,

> -----Original Message-----
> From: Pei, Andy
> Sent: Wednesday, April 17, 2019 14:49
> To: dev@dpdk.org
> Cc: Pei, Andy <andy.pei@intel.com>; Xu, Rosen <rosen.xu@intel.com>; 
> Kovacevic, Marko <marko.kovacevic@intel.com>; liq3ea@163.com; 
> stable@dpdk.org
> Subject: [PATCH] raw/ifpga: fix fd leak in rte fpga do pr

Pls use raw/ifpga_rawdev prefix.
I suggest you to run ./devtools/check-git-log.sh -1 before you sending patch.

> In rte_fpga_do_pr() function, if 'stat' returns error,
> rte_fpga_do_pr() returns -EINVAL without closing the 'file_fd' that 
> has been opened.
> After this patch, 'file_fd' is closed before rte_fpga_do_pr() returns 
> -EINVAL when 'stat' returns error

Pls put this in the commit message:
Coverity issue: 279441
 
> Fixes: ef1e8ede3da5 ("raw/ifpga: add Intel FPGA bus rawdev driver")
> Cc: rosen.xu@intel.com
> Cc: marko.kovacevic@intel.com
> Cc: liq3ea@163.com
> Cc: andy.pei@intel.com
> Cc: stable@dpdk.org
>
> Signed-off-by: Andy Pei <andy.pei@intel.com>
> ---
> ---
>  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 da772d0..eff001b 100644
> --- a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
> +++ b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
> @@ -244,7 +244,8 @@
>  	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);
> --
> 1.8.3.1

Patch

diff --git a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
index da772d0..eff001b 100644
--- a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
+++ b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
@@ -244,7 +244,8 @@ 
 	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);