Module Name:    src
Committed By:   chs
Date:           Sun Jan 17 22:32:25 UTC 2021

Modified Files:
        src/sys/rump/librump/rumpkern: rump.c

Log Message:
rump_component_init() is called recursively, so LIST_FOREACH_SAFE is not
actually safe, since the recursive calls can result in elements other than
the current element being removed from the list.  instead use an explicit
marker element to do safe list traversal.


To generate a diff of this commit:
cvs rdiff -u -r1.352 -r1.353 src/sys/rump/librump/rumpkern/rump.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/librump/rumpkern/rump.c
diff -u src/sys/rump/librump/rumpkern/rump.c:1.352 src/sys/rump/librump/rumpkern/rump.c:1.353
--- src/sys/rump/librump/rumpkern/rump.c:1.352	Sat Jan 16 23:50:49 2021
+++ src/sys/rump/librump/rumpkern/rump.c	Sun Jan 17 22:32:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rump.c,v 1.352 2021/01/16 23:50:49 chs Exp $	*/
+/*	$NetBSD: rump.c,v 1.353 2021/01/17 22:32:25 chs Exp $	*/
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.352 2021/01/16 23:50:49 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.353 2021/01/17 22:32:25 chs Exp $");
 
 #include <sys/systm.h>
 #define ELFSIZE ARCH_ELFSIZE
@@ -605,14 +605,22 @@ rump_component_count(enum rump_component
 void
 rump_component_init(enum rump_component_type type)
 {
-	struct rump_component *rc, *rc_safe;
+	struct rump_component *rc, *rc_next, rc_marker;
 
 	KASSERT(curlwp == bootlwp);
 	KASSERT(!compinited[type]);
-	LIST_FOREACH_SAFE(rc, &rchead, rc_entries, rc_safe) {
+
+	rc_marker.rc_type = RUMP_COMPONENT_MAX;
+	rc_marker.rc_init = NULL;
+	for (rc = LIST_FIRST(&rchead); rc != NULL; rc = rc_next) {
 		if (rc->rc_type == type) {
+			LIST_INSERT_AFTER(rc, &rc_marker, rc_entries);
 			rc->rc_init();
 			LIST_REMOVE(rc, rc_entries);
+			rc_next = LIST_NEXT(&rc_marker, rc_entries);
+			LIST_REMOVE(&rc_marker, rc_entries);
+		} else {
+			rc_next = LIST_NEXT(rc, rc_entries);
 		}
 	}
 	compinited[type] = 1;

Reply via email to