[v3,1/2] eal/bsd: fix possible IOPL fd leak

Message ID 20181123153920.12398-2-i.maximets@samsung.com (mailing list archive)
State Accepted, archived
Headers
Series IOPL related fixes |

Checks

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

Commit Message

Ilya Maximets Nov. 23, 2018, 3:39 p.m. UTC
  If rte_eal_iopl_init() will be called more than once we'll leak
the file descriptor.

Fixes: b46fe31862ec ("eal/bsd: fix virtio on FreeBSD")
Cc: stable@dpdk.org

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
---
 lib/librte_eal/bsdapp/eal/eal.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Maxime Coquelin Nov. 23, 2018, 5:32 p.m. UTC | #1
On 11/23/18 4:39 PM, Ilya Maximets wrote:
> If rte_eal_iopl_init() will be called more than once we'll leak
> the file descriptor.
> 
> Fixes: b46fe31862ec ("eal/bsd: fix virtio on FreeBSD")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
> ---
>   lib/librte_eal/bsdapp/eal/eal.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
> index 508cbc46f..b8152a75c 100644
> --- a/lib/librte_eal/bsdapp/eal/eal.c
> +++ b/lib/librte_eal/bsdapp/eal/eal.c
> @@ -556,9 +556,11 @@ int rte_eal_has_hugepages(void)
>   int
>   rte_eal_iopl_init(void)
>   {
> -	static int fd;
> +	static int fd = -1;
> +
> +	if (fd < 0)
> +		fd = open("/dev/io", O_RDWR);
>   
> -	fd = open("/dev/io", O_RDWR);
>   	if (fd < 0)
>   		return -1;
>   	/* keep fd open for iopl */
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
  

Patch

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 508cbc46f..b8152a75c 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -556,9 +556,11 @@  int rte_eal_has_hugepages(void)
 int
 rte_eal_iopl_init(void)
 {
-	static int fd;
+	static int fd = -1;
+
+	if (fd < 0)
+		fd = open("/dev/io", O_RDWR);
 
-	fd = open("/dev/io", O_RDWR);
 	if (fd < 0)
 		return -1;
 	/* keep fd open for iopl */