Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/config - Instead of checking the recursion level bef...
details: https://anonhg.NetBSD.org/src/rev/1001ff191a53
branches: trunk
changeset: 828042:1001ff191a53
user: christos <christos%NetBSD.org@localhost>
date: Fri Nov 24 23:42:36 2017 +0000
description:
- Instead of checking the recursion level before we recurse, check in on
function entry.
- Always decrement the level and reset levelparent on exit.
diffstat:
usr.bin/config/main.c | 49 +++++++++++++++++++++++++------------------------
1 files changed, 25 insertions(+), 24 deletions(-)
diffs (108 lines):
diff -r e485b5e9ff34 -r 1001ff191a53 usr.bin/config/main.c
--- a/usr.bin/config/main.c Fri Nov 24 21:30:43 2017 +0000
+++ b/usr.bin/config/main.c Fri Nov 24 23:42:36 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.94 2017/11/18 18:39:16 christos Exp $ */
+/* $NetBSD: main.c,v 1.95 2017/11/24 23:42:36 christos Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: main.c,v 1.94 2017/11/18 18:39:16 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.95 2017/11/24 23:42:36 christos Exp $");
#ifndef MAKE_BOOTSTRAP
#include <sys/cdefs.h>
@@ -1868,27 +1868,30 @@
return 0;
}
-static int
-is_orphan_loop(const struct devbase *d, const struct devbase *p)
-{
+static struct devbase root;
- for (; p && d != p; p = p->d_levelparent)
- continue;
- return d == p;
-}
-
-static void
+static int
addlevelparent(struct devbase *d, struct devbase *parent)
{
struct devbase *p;
- if (d->d_levelparent)
- return;
+ if (d == parent) {
+ if (d->d_level++ > 1)
+ return 0;
+ return 1;
+ }
+
+ if (d->d_levelparent) {
+ if (d->d_level++ > 1)
+ return 0;
+ return 1;
+ }
for (p = parent; p != NULL; p = p->d_levelparent)
- if (d == p)
- return;
- d->d_levelparent = p;
+ if (d == p && d->d_level++ > 1)
+ return 0;
+ d->d_levelparent = p ? p : &root;
+ return 1;
}
static void
@@ -1902,7 +1905,8 @@
struct pspec *p;
int active = 0;
- addlevelparent(d, parent);
+ if (!addlevelparent(d, parent))
+ return;
/*
* A pseudo-device will always attach at root, and if it has an
@@ -1970,7 +1974,7 @@
* If we've been there but have made no change, stop.
*/
if (seen && active != DEVI_ACTIVE)
- return;
+ goto out;
if (active != DEVI_ACTIVE) {
struct cdd_params cdd = { d, at, parent };
/* Look for a matching dead devi */
@@ -1990,22 +1994,19 @@
CFGDBG(5, "`%s' at '%s' ignored", d->d_name,
parent ? parent->d_name : "(root)");
- } else
- return;
+ }
}
}
for (al = d->d_attrs; al != NULL; al = al->al_next) {
a = al->al_this;
for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next) {
- if (is_orphan_loop(nv1->nv_ptr, d)) {
- if (d->d_level++ > 1)
- continue;
- }
do_kill_orphans(nv1->nv_ptr, a, d, active);
}
}
+out:
d->d_levelparent = NULL;
+ d->d_level--;
}
static int
Home |
Main Index |
Thread Index |
Old Index