Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/rump/librump/rumpkern rump_component_init() is called re...



details:   https://anonhg.NetBSD.org/src/rev/7983667bd597
branches:  trunk
changeset: 958734:7983667bd597
user:      chs <chs%NetBSD.org@localhost>
date:      Sun Jan 17 22:32:25 2021 +0000

description:
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.

diffstat:

 sys/rump/librump/rumpkern/rump.c |  16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diffs (43 lines):

diff -r 81bf2872e1fa -r 7983667bd597 sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c  Sun Jan 17 21:56:20 2021 +0000
+++ b/sys/rump/librump/rumpkern/rump.c  Sun Jan 17 22:32:25 2021 +0000
@@ -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 @@
 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;



Home | Main Index | Thread Index | Old Index