[PATCH] net/tap: check for fd == -1 on failure path

Vladimir Sementsov-Ogievskiy posted 1 patch 3 weeks, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260629152234.847885-1-vsementsov@yandex-team.ru
Maintainers: Jason Wang <jasowang@redhat.com>
net/tap.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] net/tap: check for fd == -1 on failure path
Posted by Vladimir Sementsov-Ogievskiy 3 weeks, 5 days ago
Coverity doesn't like closing invalid fds, let's satisfy it.
We initialize fd to -1 at function start, and don't set it
on some failure paths, so Coverity is right actually.

CID: 160042
Fixes: 11d0e070a6 ("net/tap: net_init_tap(): common fail label")
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 net/tap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/tap.c b/net/tap.c
index 57ffb09885..64d6e8e82d 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -968,7 +968,9 @@ int net_init_tap(const Netdev *netdev, const char *name,
     return 0;
 
 fail:
-    close(fd);
+    if (fd != -1) {
+        close(fd);
+    }
     net_free_fds(fds, queues);
     net_free_fds(vhost_fds, queues);
     return -1;
-- 
2.43.0