From: Yunjian Wang Date: Sat, 8 Jan 2022 07:52:31 +0000 (+0800) Subject: net/virtio-user: check FD flags getting failure X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=6abf10a21b293cb427ef21c59f490592717cb211;p=dpdk.git 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 Reviewed-by: Chenbo Xia --- 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;