diff mbox series

[RFC,V1,3/6] tap: fix net_init_tap() return code

Message ID 1725018997-363706-4-git-send-email-steven.sistare@oracle.com
State New
Headers show
Series Live Update: tap and vhost | expand

Commit Message

Steven Sistare Aug. 30, 2024, 11:56 a.m. UTC
When net_init_tap() succeeds for a multi-queue device, it returns a
non-zero ret=1 code to its caller, because of this code where ret becomes
1 when g_unix_set_fd_nonblocking succeeds.  Luckily, the only current call
site checks for negative, rather than non-zero.

    ret = g_unix_set_fd_nonblocking(fd, true, NULL);
    if (!ret) {
        ...
        goto free_fail;

Also, if g_unix_set_fd_nonblocking fails (though unlikely), ret=0 is
returned, and the caller will use a broken interface.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 net/tap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/net/tap.c b/net/tap.c
index 8deabcb..20e4dae 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -855,8 +855,8 @@  int net_init_tap(const Netdev *netdev, const char *name,
                 goto free_fail;
             }
 
-            ret = g_unix_set_fd_nonblocking(fd, true, NULL);
-            if (!ret) {
+            if (!g_unix_set_fd_nonblocking(fd, true, NULL)) {
+                ret = -1;
                 error_setg_errno(errp, errno, "%s: Can't use file descriptor %d",
                                  name, fd);
                 goto free_fail;