]> git.droids-corp.org - dpdk.git/commitdiff
net/virtio-user: check FD flags getting failure
authorYunjian Wang <wangyunjian@huawei.com>
Sat, 8 Jan 2022 07:52:31 +0000 (15:52 +0800)
committerChenbo Xia <chenbo.xia@intel.com>
Thu, 27 Jan 2022 05:08:59 +0000 (06:08 +0100)
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>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
drivers/net/virtio/virtio_user/vhost_user.c

index cc830a660fcbb814cd5723dcc2a7d0aa8b56baf0..0a39393c4533ed3cde2f867f34a934b06bf55c14 100644 (file)
@@ -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;