Skip to contentSkip to conversation

main_loop: Make main_loop_wait() return void

PATCH Superseded Peter Maydell 2 participants 4 messages Mar 31, 2017 – May 30, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 main_loop: Make main_loop_wait() return void

In commit e330c118f2a5a the last usage of main_loop_wait() that cared about the return value was changed to no longer use it. Drop the now-useless return value and make the function return void.

---
Coverity complains (CID 1372464) about main_loop() calling main_loop_wait() and ignoring its return value. I suspect this change will just displace that to within main_loop_wait() itself since the underlying issue there is "the ppoll() that gets called to poll fds can return an error code, but what do we do if it does?". Suggestions on that point welcome.

I guess this will make the compiler warn about ret being set and never used if CONFIG_SLIRP is not defined, which is irritating. I'm postponing messing about with fixing that in favour of seeing whether anybody has a good answer to the question above (which might make it moot).

---
 include/qemu/main-loop.h | 2 +-
 util/main-loop.c         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
include/qemu/main-loop.h +1 -1
index d7e24af..6b4b60b 100644
@@ -79,7 +79,7 @@ int qemu_init_main_loop(Error **errp);
  *
  * @nonblocking: Whether the caller should block until an event occurs.
  */
-int main_loop_wait(int nonblocking);
+void main_loop_wait(int nonblocking);
 
 /**
  * qemu_get_aio_context: Return the main loop's AioContext
util/main-loop.c +2 -2
index 4534c89..d0e27f3 100644
@@ -476,7 +476,7 @@ static int os_host_main_loop_wait(int64_t timeout)
 }
 #endif
 
-int main_loop_wait(int nonblocking)
+void main_loop_wait(int nonblocking)
 {
     int ret;
     uint32_t timeout = UINT32_MAX;
@@ -513,7 +513,7 @@ int main_loop_wait(int nonblocking)
     qemu_start_warp_timer();
     qemu_clock_run_all_timers();
 
-    return ret;
+    return;
 }
 
 /* Functions to operate on the main QEMU AioContext.  */
Signature · 1 line
2.7.4
#1 lore raw
Quoted 13 lines · Peter Maydell

In commit e330c118f2a5a the last usage of main_loop_wait() that cared about the return value was changed to no longer use it. Drop the now-useless return value and make the function return void.

---
Coverity complains (CID 1372464) about main_loop() calling main_loop_wait() and ignoring its return value. I suspect this change will just displace that to within main_loop_wait() itself since the underlying issue there is "the ppoll() that gets called to poll fds can return an error code, but what do we do if it does?". Suggestions on that point welcome.

Quoted 6 lines

I guess this will make the compiler warn about ret being set and never used if CONFIG_SLIRP is not defined, which is irritating. I'm postponing messing about with fixing that in favour of seeing whether anybody has a good answer to the question above (which might make it moot).
---

...oops, I meant to tag this RFC; never mind.

thanks
-- PMM

#2 lore raw
In reply to Peter Maydell
Quoted 4 lines · Peter Maydell

In commit e330c118f2a5a the last usage of main_loop_wait() that cared about the return value was changed to no longer use it. Drop the now-useless return value and make the function return void.

Quoted 8 lines

---
Coverity complains (CID 1372464) about main_loop() calling main_loop_wait() and ignoring its return value. I suspect this change will just displace that to within main_loop_wait() itself since the underlying issue there is "the ppoll() that gets called to poll fds can return an error code, but what do we do if it does?". Suggestions on that point welcome.

At one point, there was a suggestion to introduce an ignore_value() macro that ignores values that the compiler/coverity would otherwise complain about, in contexts where we really are okay ignoring the value.
If making main_loop_wait() return void shifts where Coverity blames,
then ignore_value(ppoll()) seems like it might help.

Quoted 14 lines

I guess this will make the compiler warn about ret being set and never used if CONFIG_SLIRP is not defined, which is irritating. I'm postponing messing about with fixing that in favour of seeing whether anybody has a good answer to the question above (which might make it moot).
---

util/main-loop.c +1 -1
-int main_loop_wait(int nonblocking)
+void main_loop_wait(int nonblocking)
 {
     int ret;
     uint32_t timeout = UINT32_MAX;

util/main-loop.c int main_loop_wait(int nonblocking) · line 517

Quoted 6 lines
util/main-loop.c +1 -1
@@ -513,7 +513,7 @@ int main_loop_wait(int nonblocking)
     qemu_start_warp_timer();
     qemu_clock_run_all_timers();
 
-    return ret;
+    return;
 }

We generally avoid lone return; at the end of a void function.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw
Quoted 14 lines · Eric Blake
Quoted 4 lines · Peter Maydell

In commit e330c118f2a5a the last usage of main_loop_wait() that cared about the return value was changed to no longer use it. Drop the now-useless return value and make the function return void.

Quoted 8 lines

---
Coverity complains (CID 1372464) about main_loop() calling main_loop_wait() and ignoring its return value. I suspect this change will just displace that to within main_loop_wait() itself since the underlying issue there is "the ppoll() that gets called to poll fds can return an error code, but what do we do if it does?". Suggestions on that point welcome.

Quoted 5 lines

At one point, there was a suggestion to introduce an ignore_value() macro that ignores values that the compiler/coverity would otherwise complain about, in contexts where we really are okay ignoring the value.
If making main_loop_wait() return void shifts where Coverity blames,
then ignore_value(ppoll()) seems like it might help.

Mmm, but my question really is "is ignoring the error code from the syscall the correct thing to do?"... though I'm not sure what else we would want to do (log a warning? abort?).

thanks
-- PMM