diff mbox series

net/virtio-user: check fd flags getting failure

Message ID 3fac6dba701731df12ea8cce82a539036b1f5e70.1641626365.git.wangyunjian@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers show
Series net/virtio-user: check fd flags getting failure | expand

Checks

Context Check Description
ci/intel-Testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/github-robot: build success github build: passed
ci/checkpatch success coding style OK

Commit Message

wangyunjian Jan. 8, 2022, 7:52 a.m. UTC
The function fcntl() could return errors,
the return value need to be checked.

Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/virtio/virtio_user/vhost_user.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Xia, Chenbo Jan. 17, 2022, 3:22 a.m. UTC | #1
> -----Original Message-----
> From: Yunjian Wang <wangyunjian@huawei.com>
> Sent: Saturday, January 8, 2022 3:53 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>;
> dingxiaoxiong@huawei.com; xudingke@huawei.com; Yunjian Wang
> <wangyunjian@huawei.com>; stable@dpdk.org
> Subject: [dpdk-dev] [PATCH] net/virtio-user: check fd flags getting failure
> 
> The function fcntl() could return errors,
> the return value need to be checked.
> 
> Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  drivers/net/virtio/virtio_user/vhost_user.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_user/vhost_user.c
> b/drivers/net/virtio/virtio_user/vhost_user.c
> index cc830a660f..0a39393c45 100644
> --- a/drivers/net/virtio/virtio_user/vhost_user.c
> +++ b/drivers/net/virtio/virtio_user/vhost_user.c
> @@ -840,8 +840,10 @@ vhost_user_setup(struct virtio_user_dev *dev)
>  	}
> 
>  	flag = fcntl(fd, F_GETFD);
> -	if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0)
> -		PMD_DRV_LOG(WARNING, "fcntl failed, %s", strerror(errno));
> +	if (flag == -1)
> +		PMD_DRV_LOG(WARNING, "fcntl get fd failed, %s", strerror(errno));
> +	else if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0)
> +		PMD_DRV_LOG(WARNING, "fcntl set fd failed, %s", strerror(errno));
> 
>  	memset(&un, 0, sizeof(un));
>  	un.sun_family = AF_UNIX;
> --
> 2.27.0

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
Xia, Chenbo Jan. 27, 2022, 5:26 a.m. UTC | #2
> -----Original Message-----
> From: Yunjian Wang <wangyunjian@huawei.com>
> Sent: Saturday, January 8, 2022 3:53 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>;
> dingxiaoxiong@huawei.com; xudingke@huawei.com; Yunjian Wang
> <wangyunjian@huawei.com>; stable@dpdk.org
> Subject: [dpdk-dev] [PATCH] net/virtio-user: check fd flags getting failure
> 
> The function fcntl() could return errors,
> the return value need to be checked.
> 
> Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  drivers/net/virtio/virtio_user/vhost_user.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_user/vhost_user.c
> b/drivers/net/virtio/virtio_user/vhost_user.c
> index cc830a660f..0a39393c45 100644
> --- a/drivers/net/virtio/virtio_user/vhost_user.c
> +++ b/drivers/net/virtio/virtio_user/vhost_user.c
> @@ -840,8 +840,10 @@ vhost_user_setup(struct virtio_user_dev *dev)
>  	}
> 
>  	flag = fcntl(fd, F_GETFD);
> -	if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0)
> -		PMD_DRV_LOG(WARNING, "fcntl failed, %s", strerror(errno));
> +	if (flag == -1)
> +		PMD_DRV_LOG(WARNING, "fcntl get fd failed, %s", strerror(errno));
> +	else if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0)
> +		PMD_DRV_LOG(WARNING, "fcntl set fd failed, %s", strerror(errno));
> 
>  	memset(&un, 0, sizeof(un));
>  	un.sun_family = AF_UNIX;
> --
> 2.27.0

Applied to next-virtio/main with headline fixed (fd -> FD).

Thanks.
diff mbox series

Patch

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c
index cc830a660f..0a39393c45 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -840,8 +840,10 @@  vhost_user_setup(struct virtio_user_dev *dev)
 	}
 
 	flag = fcntl(fd, F_GETFD);
-	if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0)
-		PMD_DRV_LOG(WARNING, "fcntl failed, %s", strerror(errno));
+	if (flag == -1)
+		PMD_DRV_LOG(WARNING, "fcntl get fd failed, %s", strerror(errno));
+	else if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0)
+		PMD_DRV_LOG(WARNING, "fcntl set fd failed, %s", strerror(errno));
 
 	memset(&un, 0, sizeof(un));
 	un.sun_family = AF_UNIX;