Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/config avoid creating infinite loops.



details:   https://anonhg.NetBSD.org/src/rev/be4da32e9b68
branches:  trunk
changeset: 827915:be4da32e9b68
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Nov 18 01:11:05 2017 +0000

description:
avoid creating infinite loops.

diffstat:

 usr.bin/config/main.c |  21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diffs (49 lines):

diff -r 160c3bd3b24b -r be4da32e9b68 usr.bin/config/main.c
--- a/usr.bin/config/main.c     Sat Nov 18 00:25:43 2017 +0000
+++ b/usr.bin/config/main.c     Sat Nov 18 01:11:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.92 2017/11/16 17:08:07 christos Exp $       */
+/*     $NetBSD: main.c,v 1.93 2017/11/18 01:11:05 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: main.c,v 1.92 2017/11/16 17:08:07 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.93 2017/11/18 01:11:05 christos Exp $");
 
 #ifndef MAKE_BOOTSTRAP
 #include <sys/cdefs.h>
@@ -1878,6 +1878,20 @@
 }
 
 static void
+addlevelparent(struct devbase *d, struct devbase *parent)
+{
+       struct devbase *p;
+
+       if (d->d_levelparent)
+               return;
+
+       for (p = parent; p != NULL; p = p->d_levelparent)
+               if (d == p)
+                       return;
+       d->d_levelparent = p;
+}
+
+static void
 do_kill_orphans(struct devbase *d, struct attr *at, struct devbase *parent,
     int state)
 {
@@ -1888,8 +1902,7 @@
        struct pspec *p;
        int active = 0;
 
-       if (d->d_levelparent == NULL)
-               d->d_levelparent = parent;
+       addlevelparent(d, parent);
 
        /*
         * A pseudo-device will always attach at root, and if it has an



Home | Main Index | Thread Index | Old Index