Skip to contentSkip to conversation

system/win32: Remove unused Error argument in qemu_socket_[un]select()

RFC PATCH In review Philippe Mathieu-Daudé 4 participants 11 messages Jul 15, 2025 – Jul 16, 2025

lore
Share & tools
lore
#0 lore raw

cover system/win32: Remove unused Error argument in qemu_socket_[un]select()

We should use Error** more, but in this case it is always NULL so we never really care. Remove the argument...

Philippe Mathieu-Daudé (2):
system/os-win32: Remove unused Error** argument in
qemu_socket_unselect
system/os-win32: Remove unused Error** argument in qemu_socket_select

 include/system/os-win32.h |  4 ++--
 io/channel-socket.c       |  4 ++--
 util/aio-win32.c          |  2 +-
 util/oslib-win32.c        | 17 +++++++----------
 4 files changed, 12 insertions(+), 15 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

RFC PATCH 1/2 system/os-win32: Remove unused Error** argument in qemu_socket_unselect

@errp is always NULL. Remove it, as unused.

---
 include/system/os-win32.h | 2 +-
 io/channel-socket.c       | 4 ++--
 util/oslib-win32.c        | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
include/system/os-win32.h +1 -1
index 3aa6cee4c23..40712a948c3 100644
@@ -172,7 +172,7 @@ static inline void qemu_funlockfile(FILE *f)
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
                         long lNetworkEvents, Error **errp);
 
-bool qemu_socket_unselect(int sockfd, Error **errp);
+bool qemu_socket_unselect(int sockfd);
 
 /* We wrap all the sockets functions so that we can set errno based on
  * WSAGetLastError(), and use file-descriptors instead of SOCKET.
io/channel-socket.c +2 -2
index 3b7ca924ff3..6ee6217e7ac 100644
@@ -454,7 +454,7 @@ static void qio_channel_socket_finalize(Object *obj)
             }
         }
 #ifdef WIN32
-        qemu_socket_unselect(ioc->fd, NULL);
+        qemu_socket_unselect(ioc->fd);
 #endif
         close(ioc->fd);
         ioc->fd = -1;
@@ -890,7 +890,7 @@ qio_channel_socket_close(QIOChannel *ioc,
 
     if (sioc->fd != -1) {
 #ifdef WIN32
-        qemu_socket_unselect(sioc->fd, NULL);
+        qemu_socket_unselect(sioc->fd);
 #endif
         if (qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_LISTEN)) {
             socket_listen_cleanup(sioc->fd, errp);
util/oslib-win32.c +3 -3
index b7351634ece..7ac3482d449 100644
@@ -180,7 +180,7 @@ static int socket_error(void)
 void qemu_socket_set_block(int fd)
 {
     unsigned long opt = 0;
-    qemu_socket_unselect(fd, NULL);
+    qemu_socket_unselect(fd);
     ioctlsocket(fd, FIONBIO, &opt);
 }
 
@@ -313,9 +313,9 @@ bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
     return true;
 }
 
-bool qemu_socket_unselect(int sockfd, Error **errp)
+bool qemu_socket_unselect(int sockfd)
 {
-    return qemu_socket_select(sockfd, NULL, 0, errp);
+    return qemu_socket_select(sockfd, NULL, 0, NULL);
 }
 
 int qemu_socketpair(int domain, int type, int protocol, int sv[2])
Signature · 1 line
2.49.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [RFC PATCH 1/2] system/os-win32: Remove unused Error** argument in qemu_socket_unselect

Quoted 71 lines · Philippe Mathieu-Daudé

@errp is always NULL. Remove it, as unused.

---
 include/system/os-win32.h | 2 +-
 io/channel-socket.c       | 4 ++--
 util/oslib-win32.c        | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
include/system/os-win32.h +1 -1
index 3aa6cee4c23..40712a948c3 100644
@@ -172,7 +172,7 @@ static inline void qemu_funlockfile(FILE *f)
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
                         long lNetworkEvents, Error **errp);
 
-bool qemu_socket_unselect(int sockfd, Error **errp);
+bool qemu_socket_unselect(int sockfd);
 
 /* We wrap all the sockets functions so that we can set errno based on
  * WSAGetLastError(), and use file-descriptors instead of SOCKET.
io/channel-socket.c +2 -2
index 3b7ca924ff3..6ee6217e7ac 100644
@@ -454,7 +454,7 @@ static void qio_channel_socket_finalize(Object *obj)
             }
         }
 #ifdef WIN32
-        qemu_socket_unselect(ioc->fd, NULL);
+        qemu_socket_unselect(ioc->fd);
 #endif
         close(ioc->fd);
         ioc->fd = -1;
@@ -890,7 +890,7 @@ qio_channel_socket_close(QIOChannel *ioc,
 
     if (sioc->fd != -1) {
 #ifdef WIN32
-        qemu_socket_unselect(sioc->fd, NULL);
+        qemu_socket_unselect(sioc->fd);
 #endif
         if (qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_LISTEN)) {
             socket_listen_cleanup(sioc->fd, errp);
util/oslib-win32.c +3 -4
index b7351634ece..7ac3482d449 100644
@@ -180,7 +180,7 @@ static int socket_error(void)
 void qemu_socket_set_block(int fd)
 {
     unsigned long opt = 0;
-    qemu_socket_unselect(fd, NULL);
+    qemu_socket_unselect(fd);
     ioctlsocket(fd, FIONBIO, &opt);
 }
 
@@ -313,9 +313,9 @@ bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
     return true;
 }
 
-bool qemu_socket_unselect(int sockfd, Error **errp)
+bool qemu_socket_unselect(int sockfd)
 {
-    return qemu_socket_select(sockfd, NULL, 0, errp);
+    return qemu_socket_select(sockfd, NULL, 0, NULL);
 }
 
 int qemu_socketpair(int domain, int type, int protocol, int sv[2])
--
Quoted 3 lines

2.49.0

#3 lore raw

Re: [RFC PATCH 1/2] system/os-win32: Remove unused Error** argument in qemu_socket_unselect

In reply to Philippe Mathieu-Daudé
Quoted 27 lines · Philippe Mathieu-Daudé

@errp is always NULL. Remove it, as unused.

---
 include/system/os-win32.h | 2 +-
 io/channel-socket.c       | 4 ++--
 util/oslib-win32.c        | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
include/system/os-win32.h +1 -1
index 3aa6cee4c23..40712a948c3 100644
@@ -172,7 +172,7 @@ static inline void qemu_funlockfile(FILE *f)
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
                         long lNetworkEvents, Error **errp);
 
-bool qemu_socket_unselect(int sockfd, Error **errp);
+bool qemu_socket_unselect(int sockfd);
 
 /* We wrap all the sockets functions so that we can set errno based on
  * WSAGetLastError(), and use file-descriptors instead of SOCKET.
io/channel-socket.c +0 -0
index 3b7ca924ff3..6ee6217e7ac 100644

io/channel-socket.c static void qio_channel_socket_finalize(Object *obj) · line 458

Quoted 6 lines
io/channel-socket.c +1 -1
@@ -454,7 +454,7 @@ static void qio_channel_socket_finalize(Object *obj)
             }
         }
 #ifdef WIN32
-        qemu_socket_unselect(ioc->fd, NULL);
+        qemu_socket_unselect(ioc->fd);
 #endif

It seems to me like this code should instead be using &error_warn, because the errors are still relevant and potentially a sign of a bug, but we don't want to stop this finalization path.

io/channel-socket.c qio_channel_socket_close(QIOChannel *ioc, · line 894

Quoted 9 lines
io/channel-socket.c +1 -1
         close(ioc->fd);
         ioc->fd = -1;
@@ -890,7 +890,7 @@ qio_channel_socket_close(QIOChannel *ioc,
 
     if (sioc->fd != -1) {
 #ifdef WIN32
-        qemu_socket_unselect(sioc->fd, NULL);
+        qemu_socket_unselect(sioc->fd);
 #endif

Here too, we don't want to stop the close operation early, as we need to 'close()' the FD, but we should diagnose the failure none the less

Quoted 30 lines
io/channel-socket.c +0 -0
         if (qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_LISTEN)) {
             socket_listen_cleanup(sioc->fd, errp);
util/oslib-win32.c +3 -3
index b7351634ece..7ac3482d449 100644
@@ -180,7 +180,7 @@ static int socket_error(void)
 void qemu_socket_set_block(int fd)
 {
     unsigned long opt = 0;
-    qemu_socket_unselect(fd, NULL);
+    qemu_socket_unselect(fd);
     ioctlsocket(fd, FIONBIO, &opt);
 }
 
@@ -313,9 +313,9 @@ bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
     return true;
 }
 
-bool qemu_socket_unselect(int sockfd, Error **errp)
+bool qemu_socket_unselect(int sockfd)
 {
-    return qemu_socket_select(sockfd, NULL, 0, errp);
+    return qemu_socket_select(sockfd, NULL, 0, NULL);
 }
 
 int qemu_socketpair(int domain, int type, int protocol, int sv[2])
Signature · 1 line
2.49.0

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#4 lore raw

Re: [RFC PATCH 1/2] system/os-win32: Remove unused Error** argument in qemu_socket_unselect

Quoted 21 lines · Daniel P. Berrangé
Quoted 20 lines · Philippe Mathieu-Daudé

@errp is always NULL. Remove it, as unused.

---
 include/system/os-win32.h | 2 +-
 io/channel-socket.c       | 4 ++--
 util/oslib-win32.c        | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
include/system/os-win32.h +1 -1
index 3aa6cee4c23..40712a948c3 100644
@@ -172,7 +172,7 @@ static inline void qemu_funlockfile(FILE *f)
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
                         long lNetworkEvents, Error **errp);
 
-bool qemu_socket_unselect(int sockfd, Error **errp);
+bool qemu_socket_unselect(int sockfd);
 
Quoted 7 lines

io/channel-socket.c static void qio_channel_socket_finalize(Object *obj)

Quoted 7 lines
include/system/os-win32.h +0 -0
 /* We wrap all the sockets functions so that we can set errno based on
  * WSAGetLastError(), and use file-descriptors instead of SOCKET.
io/channel-socket.c +0 -0
index 3b7ca924ff3..6ee6217e7ac 100644
@@ -454,7 +454,7 @@ static void qio_channel_socket_finalize(Object *obj)
    static void qio_channel_socket_finalize(Object *obj)
    {
        QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(obj);

        if (ioc->fd != -1) {
            QIOChannel *ioc_local = QIO_CHANNEL(ioc);
            if (qio_channel_has_feature(ioc_local, QIO_CHANNEL_FEATURE_LISTEN)) {
                Error *err = NULL;

                socket_listen_cleanup(ioc->fd, &err);
                if (err) {
                    error_report_err(err);
                    err = NULL;
Quoted 11 lines

io/channel-socket.c static void qio_channel_socket_finalize(Object *obj) · line 458

Quoted 6 lines
io/channel-socket.c +1 -1
             }
         }
 #ifdef WIN32
-        qemu_socket_unselect(ioc->fd, NULL);
+        qemu_socket_unselect(ioc->fd);
 #endif

It seems to me like this code should instead be using &error_warn, because the errors are still relevant and potentially a sign of a bug, but we don't want to stop this finalization path.

Would such a warning be actionable for the user?

Why is this failure a warning, but the failure right above is an error?

What are the possible failures?

On reporting errors with error_report() & friends: doing so within a function that uses an Error **errp parameter to return errors is almost always wrong. Can qio_channel_socket_finalize() run within such a function?

Quoted 5 lines
Quoted 5 lines
io/channel-socket.c +0 -0
         close(ioc->fd);
         ioc->fd = -1;
@@ -890,7 +890,7 @@ qio_channel_socket_close(QIOChannel *ioc,
 
Quoted 9 lines

io/channel-socket.c qio_channel_socket_close(QIOChannel *ioc, · line 894

Quoted 5 lines
io/channel-socket.c +1 -1
     if (sioc->fd != -1) {
 #ifdef WIN32
-        qemu_socket_unselect(sioc->fd, NULL);
+        qemu_socket_unselect(sioc->fd);
 #endif

Here too, we don't want to stop the close operation early, as we need to 'close()' the FD, but we should diagnose the failure none the less

Same questions.

Quoted 2 lines
Quoted 2 lines
io/channel-socket.c +0 -0
         if (qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_LISTEN)) {
             socket_listen_cleanup(sioc->fd, errp);

[...]

#5 lore raw

Re: [RFC PATCH 1/2] system/os-win32: Remove unused Error** argument in qemu_socket_unselect

Quoted 58 lines · Markus Armbruster
Quoted 21 lines · Daniel P. Berrangé
Quoted 20 lines · Philippe Mathieu-Daudé

@errp is always NULL. Remove it, as unused.

---
 include/system/os-win32.h | 2 +-
 io/channel-socket.c       | 4 ++--
 util/oslib-win32.c        | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
include/system/os-win32.h +1 -1
index 3aa6cee4c23..40712a948c3 100644
@@ -172,7 +172,7 @@ static inline void qemu_funlockfile(FILE *f)
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
                         long lNetworkEvents, Error **errp);
 
-bool qemu_socket_unselect(int sockfd, Error **errp);
+bool qemu_socket_unselect(int sockfd);
 
Quoted 7 lines

io/channel-socket.c static void qio_channel_socket_finalize(Object *obj)

Quoted 7 lines
include/system/os-win32.h +0 -0
 /* We wrap all the sockets functions so that we can set errno based on
  * WSAGetLastError(), and use file-descriptors instead of SOCKET.
io/channel-socket.c +0 -0
index 3b7ca924ff3..6ee6217e7ac 100644
@@ -454,7 +454,7 @@ static void qio_channel_socket_finalize(Object *obj)
    static void qio_channel_socket_finalize(Object *obj)
    {
        QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(obj);

        if (ioc->fd != -1) {
            QIOChannel *ioc_local = QIO_CHANNEL(ioc);
            if (qio_channel_has_feature(ioc_local, QIO_CHANNEL_FEATURE_LISTEN)) {
                Error *err = NULL;

                socket_listen_cleanup(ioc->fd, &err);
                if (err) {
                    error_report_err(err);
                    err = NULL;
Quoted 11 lines

io/channel-socket.c static void qio_channel_socket_finalize(Object *obj) · line 458

Quoted 6 lines
io/channel-socket.c +1 -1
             }
         }
 #ifdef WIN32
-        qemu_socket_unselect(ioc->fd, NULL);
+        qemu_socket_unselect(ioc->fd);
 #endif

It seems to me like this code should instead be using &error_warn, because the errors are still relevant and potentially a sign of a bug, but we don't want to stop this finalization path.

Would such a warning be actionable for the user?

Quoted 8 lines

Why is this failure a warning, but the failure right above is an error?

What are the possible failures?

On reporting errors with error_report() & friends: doing so within a function that uses an Error **errp parameter to return errors is almost always wrong. Can qio_channel_socket_finalize() run within such a function?

No finalize() function can ever propagate errors - these are run transparently when the "unref" drops the last reference count. So error_report is the best we can manage in finalize functions.

It is actionable for the user in so much as if they see such warnings, it is sign of a code bug somewhere and this will be a useful diagnostic to receive in the bug report.

Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
io/channel-socket.c +0 -0
         close(ioc->fd);
         ioc->fd = -1;
@@ -890,7 +890,7 @@ qio_channel_socket_close(QIOChannel *ioc,
 
Quoted 9 lines

io/channel-socket.c qio_channel_socket_close(QIOChannel *ioc, · line 894

Quoted 5 lines
io/channel-socket.c +1 -1
     if (sioc->fd != -1) {
 #ifdef WIN32
-        qemu_socket_unselect(sioc->fd, NULL);
+        qemu_socket_unselect(sioc->fd);
 #endif

Here too, we don't want to stop the close operation early, as we need to 'close()' the FD, but we should diagnose the failure none the less

Quoted 1 line

Same questions.

Close can propagate errors, but we need a little more careful dance. We really really really want to still successfully close the underlying socket FD, and if that causes an error too, we'll prefer to see the latter error, over this earlier error IMHO. So we should propagate an error here, but delay propagation until the rest of this method has run.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
io/channel-socket.c +0 -0
         if (qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_LISTEN)) {
             socket_listen_cleanup(sioc->fd, errp);

[...]

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#6 lore raw

Re: [RFC PATCH 1/2] system/os-win32: Remove unused Error** argument in qemu_socket_unselect

Quoted 68 lines · Daniel P. Berrangé
Quoted 58 lines · Markus Armbruster
Quoted 21 lines · Daniel P. Berrangé
Quoted 20 lines · Philippe Mathieu-Daudé

@errp is always NULL. Remove it, as unused.

---
 include/system/os-win32.h | 2 +-
 io/channel-socket.c       | 4 ++--
 util/oslib-win32.c        | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
include/system/os-win32.h +1 -1
index 3aa6cee4c23..40712a948c3 100644
@@ -172,7 +172,7 @@ static inline void qemu_funlockfile(FILE *f)
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
                         long lNetworkEvents, Error **errp);
 
-bool qemu_socket_unselect(int sockfd, Error **errp);
+bool qemu_socket_unselect(int sockfd);
 
Quoted 7 lines

io/channel-socket.c static void qio_channel_socket_finalize(Object *obj)

Quoted 7 lines
include/system/os-win32.h +0 -0
 /* We wrap all the sockets functions so that we can set errno based on
  * WSAGetLastError(), and use file-descriptors instead of SOCKET.
io/channel-socket.c +0 -0
index 3b7ca924ff3..6ee6217e7ac 100644
@@ -454,7 +454,7 @@ static void qio_channel_socket_finalize(Object *obj)
    static void qio_channel_socket_finalize(Object *obj)
    {
        QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(obj);

        if (ioc->fd != -1) {
            QIOChannel *ioc_local = QIO_CHANNEL(ioc);
            if (qio_channel_has_feature(ioc_local, QIO_CHANNEL_FEATURE_LISTEN)) {
                Error *err = NULL;

                socket_listen_cleanup(ioc->fd, &err);
                if (err) {
                    error_report_err(err);
                    err = NULL;
Quoted 11 lines

io/channel-socket.c static void qio_channel_socket_finalize(Object *obj) · line 458

Quoted 6 lines
io/channel-socket.c +1 -1
             }
         }
 #ifdef WIN32
-        qemu_socket_unselect(ioc->fd, NULL);
+        qemu_socket_unselect(ioc->fd);
 #endif

It seems to me like this code should instead be using &error_warn, because the errors are still relevant and potentially a sign of a bug, but we don't want to stop this finalization path.

Would such a warning be actionable for the user?

Quoted 8 lines

Why is this failure a warning, but the failure right above is an error?

What are the possible failures?

On reporting errors with error_report() & friends: doing so within a function that uses an Error **errp parameter to return errors is almost always wrong. Can qio_channel_socket_finalize() run within such a function?

Quoted 7 lines

No finalize() function can ever propagate errors - these are run transparently when the "unref" drops the last reference count. So error_report is the best we can manage in finalize functions.

It is actionable for the user in so much as if they see such warnings, it is sign of a code bug somewhere and this will be a useful diagnostic to receive in the bug report.

Then the diagnostic should tell the user this is a bug!

Messages like

warning: failed to WSAEventSelect()

show cavalier disregard for users. What is WSAEventSelect, why should I care, is my data safe, and what am I supposed to do with this now?

[...]

#7 lore raw

RFC PATCH 2/2 system/os-win32: Remove unused Error** argument in qemu_socket_select

In reply to Philippe Mathieu-Daudé

@errp is always NULL. Remove it, as unused.

---
 include/system/os-win32.h |  2 +-
 util/aio-win32.c          |  2 +-
 util/oslib-win32.c        | 13 +++++--------
 3 files changed, 7 insertions(+), 10 deletions(-)
include/system/os-win32.h +1 -1
index 40712a948c3..47882bc2f49 100644
@@ -170,7 +170,7 @@ static inline void qemu_funlockfile(FILE *f)
 
 /* Helper for WSAEventSelect, to report errors */
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
-                        long lNetworkEvents, Error **errp);
+                        long lNetworkEvents);
 
 bool qemu_socket_unselect(int sockfd);
 
util/aio-win32.c +1 -1
index 6583d5c5f31..9c2f0fb86e7 100644
@@ -121,7 +121,7 @@ void aio_set_fd_handler(AioContext *ctx,
 
         QLIST_INSERT_HEAD_RCU(&ctx->aio_handlers, node, node);
         event = event_notifier_get_handle(&ctx->notifier);
-        qemu_socket_select(fd, event, bitmask, NULL);
+        qemu_socket_select(fd, event, bitmask);
     }
     if (old_node) {
         aio_remove_fd_handler(ctx, old_node);
util/oslib-win32.c +5 -8
index 7ac3482d449..fed5ab14efb 100644
@@ -292,21 +292,18 @@ char *qemu_get_pid_name(pid_t pid)
 
 
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
-                        long lNetworkEvents, Error **errp)
+                        long lNetworkEvents)
 {
     SOCKET s = _get_osfhandle(sockfd);
 
-    if (errp == NULL) {
-        errp = &error_warn;
-    }
-
     if (s == INVALID_SOCKET) {
-        error_setg(errp, "invalid socket fd=%d", sockfd);
+        error_setg(&error_warn, "invalid socket fd=%d", sockfd);
         return false;
     }
 
     if (WSAEventSelect(s, hEventObject, lNetworkEvents) != 0) {
-        error_setg_win32(errp, WSAGetLastError(), "failed to WSAEventSelect()");
+        error_setg_win32(&error_warn, WSAGetLastError(),
+                         "failed to WSAEventSelect()");
         return false;
     }
 
@@ -315,7 +312,7 @@ bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
 
 bool qemu_socket_unselect(int sockfd)
 {
-    return qemu_socket_select(sockfd, NULL, 0, NULL);
+    return qemu_socket_select(sockfd, NULL, 0);
 }
 
 int qemu_socketpair(int domain, int type, int protocol, int sv[2])
Signature · 1 line
2.49.0
Reviewed-by on v1 2/2
#8 lore raw

Re: [RFC PATCH 2/2] system/os-win32: Remove unused Error** argument in qemu_socket_select

Quoted 76 lines · Philippe Mathieu-Daudé

@errp is always NULL. Remove it, as unused.

---
 include/system/os-win32.h |  2 +-
 util/aio-win32.c          |  2 +-
 util/oslib-win32.c        | 13 +++++--------
 3 files changed, 7 insertions(+), 10 deletions(-)
include/system/os-win32.h +1 -1
index 40712a948c3..47882bc2f49 100644
@@ -170,7 +170,7 @@ static inline void qemu_funlockfile(FILE *f)
 
 /* Helper for WSAEventSelect, to report errors */
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
-                        long lNetworkEvents, Error **errp);
+                        long lNetworkEvents);
 
 bool qemu_socket_unselect(int sockfd);
 
util/aio-win32.c +1 -1
index 6583d5c5f31..9c2f0fb86e7 100644
@@ -121,7 +121,7 @@ void aio_set_fd_handler(AioContext *ctx,
 
         QLIST_INSERT_HEAD_RCU(&ctx->aio_handlers, node, node);
         event = event_notifier_get_handle(&ctx->notifier);
-        qemu_socket_select(fd, event, bitmask, NULL);
+        qemu_socket_select(fd, event, bitmask);
     }
     if (old_node) {
         aio_remove_fd_handler(ctx, old_node);
util/oslib-win32.c +5 -9
index 7ac3482d449..fed5ab14efb 100644
@@ -292,21 +292,18 @@ char *qemu_get_pid_name(pid_t pid)
 
 
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
-                        long lNetworkEvents, Error **errp)
+                        long lNetworkEvents)
 {
     SOCKET s = _get_osfhandle(sockfd);
 
-    if (errp == NULL) {
-        errp = &error_warn;
-    }
-
     if (s == INVALID_SOCKET) {
-        error_setg(errp, "invalid socket fd=%d", sockfd);
+        error_setg(&error_warn, "invalid socket fd=%d", sockfd);
         return false;
     }
 
     if (WSAEventSelect(s, hEventObject, lNetworkEvents) != 0) {
-        error_setg_win32(errp, WSAGetLastError(), "failed to WSAEventSelect()");
+        error_setg_win32(&error_warn, WSAGetLastError(),
+                         "failed to WSAEventSelect()");
         return false;
     }
 
@@ -315,7 +312,7 @@ bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
 
 bool qemu_socket_unselect(int sockfd)
 {
-    return qemu_socket_select(sockfd, NULL, 0, NULL);
+    return qemu_socket_select(sockfd, NULL, 0);
 }
 
 int qemu_socketpair(int domain, int type, int protocol, int sv[2])
--
Quoted 3 lines

2.49.0

#9 lore raw

Re: [RFC PATCH 2/2] system/os-win32: Remove unused Error** argument in qemu_socket_select

In reply to Philippe Mathieu-Daudé
Quoted 27 lines · Philippe Mathieu-Daudé

@errp is always NULL. Remove it, as unused.

---
 include/system/os-win32.h |  2 +-
 util/aio-win32.c          |  2 +-
 util/oslib-win32.c        | 13 +++++--------
 3 files changed, 7 insertions(+), 10 deletions(-)
include/system/os-win32.h +1 -1
index 40712a948c3..47882bc2f49 100644
@@ -170,7 +170,7 @@ static inline void qemu_funlockfile(FILE *f)
 
 /* Helper for WSAEventSelect, to report errors */
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
-                        long lNetworkEvents, Error **errp);
+                        long lNetworkEvents);
 
 bool qemu_socket_unselect(int sockfd);
 
util/aio-win32.c +0 -0
index 6583d5c5f31..9c2f0fb86e7 100644

util/aio-win32.c void aio_set_fd_handler(AioContext *ctx, · line 124

Quoted 5 lines
util/aio-win32.c +1 -1
@@ -121,7 +121,7 @@ void aio_set_fd_handler(AioContext *ctx,
 
         QLIST_INSERT_HEAD_RCU(&ctx->aio_handlers, node, node);
         event = event_notifier_get_handle(&ctx->notifier);
-        qemu_socket_select(fd, event, bitmask, NULL);
+        qemu_socket_select(fd, event, bitmask);

This should likely be &error_abort, as we never expect this to fail AFAICT.

Quoted 6 lines
util/oslib-win32.c +0 -0
index 7ac3482d449..fed5ab14efb 100644
@@ -292,21 +292,18 @@ char *qemu_get_pid_name(pid_t pid)
 

util/oslib-win32.c char *qemu_get_pid_name(pid_t pid) · line 301

Quoted 10 lines
util/oslib-win32.c +1 -4
 
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
-                        long lNetworkEvents, Error **errp)
+                        long lNetworkEvents)
 {
     SOCKET s = _get_osfhandle(sockfd);
 
-    if (errp == NULL) {
-        errp = &error_warn;
-    }

This pre-existing code should never have existed - the caller should have decided this reporting policy by passing in &error_warn.

util/oslib-win32.c bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,

Quoted 15 lines
util/oslib-win32.c +3 -3
-
     if (s == INVALID_SOCKET) {
-        error_setg(errp, "invalid socket fd=%d", sockfd);
+        error_setg(&error_warn, "invalid socket fd=%d", sockfd);
         return false;
     }
 
     if (WSAEventSelect(s, hEventObject, lNetworkEvents) != 0) {
-        error_setg_win32(errp, WSAGetLastError(), "failed to WSAEventSelect()");
+        error_setg_win32(&error_warn, WSAGetLastError(),
+                         "failed to WSAEventSelect()");
         return false;
     }
 
@@ -315,7 +312,7 @@ bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#10 lore raw

Re: [RFC PATCH 2/2] system/os-win32: Remove unused Error** argument in qemu_socket_select

Quoted 51 lines · Daniel P. Berrangé
Quoted 27 lines · Philippe Mathieu-Daudé

@errp is always NULL. Remove it, as unused.

---
 include/system/os-win32.h |  2 +-
 util/aio-win32.c          |  2 +-
 util/oslib-win32.c        | 13 +++++--------
 3 files changed, 7 insertions(+), 10 deletions(-)
include/system/os-win32.h +1 -1
index 40712a948c3..47882bc2f49 100644
@@ -170,7 +170,7 @@ static inline void qemu_funlockfile(FILE *f)
 
 /* Helper for WSAEventSelect, to report errors */
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
-                        long lNetworkEvents, Error **errp);
+                        long lNetworkEvents);
 
 bool qemu_socket_unselect(int sockfd);
 
util/aio-win32.c +0 -0
index 6583d5c5f31..9c2f0fb86e7 100644

util/aio-win32.c void aio_set_fd_handler(AioContext *ctx, · line 124

Quoted 5 lines
util/aio-win32.c +1 -1
@@ -121,7 +121,7 @@ void aio_set_fd_handler(AioContext *ctx,
 
         QLIST_INSERT_HEAD_RCU(&ctx->aio_handlers, node, node);
         event = event_notifier_get_handle(&ctx->notifier);
-        qemu_socket_select(fd, event, bitmask, NULL);
+        qemu_socket_select(fd, event, bitmask);

This should likely be &error_abort, as we never expect this to fail AFAICT.

Quoted 13 lines
util/oslib-win32.c +1 -1
index 7ac3482d449..fed5ab14efb 100644
@@ -292,21 +292,18 @@ char *qemu_get_pid_name(pid_t pid)
 
 
 bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
-                        long lNetworkEvents, Error **errp)
+                        long lNetworkEvents)
 {
     SOCKET s = _get_osfhandle(sockfd);
 
Quoted 6 lines

util/oslib-win32.c char *qemu_get_pid_name(pid_t pid) · line 301

Quoted 3 lines
util/oslib-win32.c +0 -3
-    if (errp == NULL) {
-        errp = &error_warn;
-    }

This pre-existing code should never have existed - the caller should have decided this reporting policy by passing in &error_warn.

Yes.

A function that uses an Error **errp parameter to return errors leaves handling the error to the caller. The code you remove violates this principle.

Quoted 5 lines

util/oslib-win32.c char *qemu_get_pid_name(pid_t pid) · line 300

Quoted 5 lines
util/oslib-win32.c +1 -2
-
     if (s == INVALID_SOCKET) {
-        error_setg(errp, "invalid socket fd=%d", sockfd);
+        error_setg(&error_warn, "invalid socket fd=%d", sockfd);

From error_setg()'s contract:

* Please don't error_setg(&error_fatal, ...), use error_report() and
* exit(), because that's more obvious.
* Likewise, don't error_setg(&error_abort, ...), use assert().

Not said: use warn_report() instead of error_set(&error_warn). Should've been added in commit 3ffef1a55ca (error: add global &error_warn destination).

I consider &error_warn a mistake.

Quoted 15 lines

util/oslib-win32.c bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,

Quoted 11 lines
util/oslib-win32.c +2 -1
         return false;
     }
 
     if (WSAEventSelect(s, hEventObject, lNetworkEvents) != 0) {
-        error_setg_win32(errp, WSAGetLastError(), "failed to WSAEventSelect()");
+        error_setg_win32(&error_warn, WSAGetLastError(),
+                         "failed to WSAEventSelect()");
         return false;
     }
 
@@ -315,7 +312,7 @@ bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,

With regards,
Daniel