Skip to contentSkip to conversation

tools/xenstore: simplify loop handling connection I/O

PATCH In review Juergen Gross 2 participants 2 messages Jun 14, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/xenstore: simplify loop handling connection I/O

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.

---
 tools/xenstore/xenstored_core.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
tools/xenstore/xenstored_core.c +2 -10
index 6e4022e5da..fa733e714e 100644
@@ -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);
Signature · 1 line
2.35.3
Reviewed-by on v1 1/1
#1 lore raw

Hi Juergen,

Quoted 8 lines · Juergen Gross

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.

Cheers,

Signature · 1 line
Julien Grall