qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tap: fix net_init_tap() return code
@ 2025-07-14 20:36 Steve Sistare
  2025-07-14 22:31 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 8+ messages in thread
From: Steve Sistare @ 2025-07-14 20:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jason Wang, Steve Sistare

net_init_tap intends to return 0 for success and -1 on error.  However,
when net_init_tap() succeeds for a multi-queue device, it returns 1,
because of this code where ret becomes 1 when g_unix_set_fd_nonblocking
succeeds:

        ret = g_unix_set_fd_nonblocking(fd, true, NULL);
        if (!ret) {
            ... error ...
    free_fail:
        ...
        return ret;

Luckily, the only current call site checks for negative, rather than non-zero:

  net_client_init1()
      if (net_client_init_fun[](...) < 0)

Also, in the unlikely case that g_unix_set_fd_nonblocking fails and returns
false, ret=0 is returned, and net_client_init1 will use a broken interface.

Fix it to be future proof.

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

diff --git a/net/tap.c b/net/tap.c
index ae1c7e3..35552c4 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -854,8 +854,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;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH] tap: fix net_init_tap() return code
@ 2023-04-04 16:00 Steve Sistare
  2023-04-04 22:00 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 8+ messages in thread
From: Steve Sistare @ 2023-04-04 16:00 UTC (permalink / raw)
  To: qemu-devel, Jason Wang; +Cc: Steve Sistare

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.

Fixes: a8208626ba89.. ("net: replace qemu_set_nonblock()")
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 net/tap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index 1bf085d..1f3e927 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -906,8 +906,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;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-07-14 22:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-14 20:36 [PATCH] tap: fix net_init_tap() return code Steve Sistare
2025-07-14 22:31 ` Philippe Mathieu-Daudé
  -- strict thread matches above, loose matches on Subject: below --
2023-04-04 16:00 Steve Sistare
2023-04-04 22:00 ` Philippe Mathieu-Daudé
2023-04-05 15:38   ` Steven Sistare
2023-04-11  6:32     ` Jason Wang
2023-04-11 13:10       ` Steven Sistare
2023-04-13  6:57         ` Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).