tools/xenstore: simplify loop handling connection I/O
authorJuergen Gross <jgross@suse.com>
Wed, 15 Jun 2022 08:22:38 +0000 (10:22 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 15 Jun 2022 08:22:38 +0000 (10:22 +0200)
The loop handling input and output of connections of xenstored is
open coding list_for_each_entry_safe() in an incredibly complicated
way.

Use list_for_each_entry_safe() instead, making it much more clear how
the code is working.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
tools/xenstore/xenstored_core.c

index 6e4022e5da48548a2858216bcfa47a6b6723bf95..fa733e714e9a3911819aa0734d54f6fcde17f2b0 100644 (file)
@@ -2368,16 +2368,8 @@ int main(int argc, char *argv[])
                        }
                }
 
-               next = list_entry(connections.next, typeof(*conn), list);
-               if (&next->list != &connections)
-                       talloc_increase_ref_count(next);
-               while (&next->list != &connections) {
-                       conn = next;
-
-                       next = list_entry(conn->list.next,
-                                         typeof(*conn), list);
-                       if (&next->list != &connections)
-                               talloc_increase_ref_count(next);
+               list_for_each_entry_safe(conn, next, &connections, list) {
+                       talloc_increase_ref_count(conn);
 
                        if (conn_can_read(conn))
                                handle_input(conn);