From e0b21313b6ff9efca69da270533ce582636f231d Mon Sep 17 00:00:00 2001 From: dyoung Date: Tue, 8 Jan 2008 06:27:46 +0000 Subject: [PATCH] In device_foreach_child(), use a safe idiom for walking a list whose elements we might be deleting. This stops us from crashing in config_detach_children(). --- sys/kern/subr_autoconf.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c index 330b4e02bdb8..b15648ccdee8 100644 --- a/sys/kern/subr_autoconf.c +++ b/sys/kern/subr_autoconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_autoconf.c,v 1.127 2008/01/04 21:18:12 ad Exp $ */ +/* $NetBSD: subr_autoconf.c,v 1.128 2008/01/08 06:27:46 dyoung Exp $ */ /* * Copyright (c) 1996, 2000 Christopher G. Demetriou @@ -77,7 +77,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.127 2008/01/04 21:18:12 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.128 2008/01/08 06:27:46 dyoung Exp $"); #include "opt_multiprocessor.h" #include "opt_ddb.h" @@ -1738,9 +1738,10 @@ device_parent(device_t dev) bool device_foreach_child(device_t parent, bool (*func)(device_t, void *), void *arg) { - device_t curdev; + device_t curdev, nextdev; - TAILQ_FOREACH(curdev, &alldevs, dv_list) { + for (curdev = TAILQ_FIRST(&alldevs); curdev != NULL; curdev = nextdev) { + nextdev = TAILQ_NEXT(curdev, dv_list); if (device_parent(curdev) != parent) continue; if (!(*func)(curdev, arg))