Source-Changes-HG archive

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

[src/thorpej-cfargs]: src/sys/kern In config_search(), we already asserted th...



details:   https://anonhg.NetBSD.org/src/rev/f76bfd56df1d
branches:  thorpej-cfargs
changeset: 960442:f76bfd56df1d
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Mar 21 17:58:40 2021 +0000

description:
In config_search(), we already asserted that either an interface
attribute is not specified, or the specified attribute is carried
by the parent.

Add an additional assertion: That an interface attribute is specified
or that the parent has fewer than 2 interface attributes (i.e. lack of
interface attribute specification would be ambiguous).

Yes, "fewer than 2".  Zero interface attributes doesn't really make sense,
because a device cannot then be a parent of another device by definition.
But cfparent_match() would already catch this situation gracefully, and
there is obviously no ambiguity when a device has no interface attributes.

diffstat:

 sys/kern/subr_autoconf.c |  22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diffs (50 lines):

diff -r 0f4233d38fa8 -r f76bfd56df1d sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Sun Mar 21 17:35:39 2021 +0000
+++ b/sys/kern/subr_autoconf.c  Sun Mar 21 17:58:40 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.277.2.1 2021/03/20 19:33:41 thorpej Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.277.2.2 2021/03/21 17:58:40 thorpej Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.277.2.1 2021/03/20 19:33:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.277.2.2 2021/03/21 17:58:40 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -809,6 +809,23 @@
        return 0;
 }
 
+#if defined(DIAGNOSTIC)
+static int
+cfdriver_iattr_count(const struct cfdriver *cd)
+{
+       const struct cfiattrdata * const *cpp;
+       int i;
+
+       if (cd->cd_attrs == NULL)
+               return 0;
+
+       for (i = 0, cpp = cd->cd_attrs; *cpp; cpp++) {
+               i++;
+       }
+       return i;
+}
+#endif /* DIAGNOSTIC */
+
 /*
  * Lookup an interface attribute description by name.
  * If the driver is given, consider only its supported attributes.
@@ -1071,6 +1088,7 @@
 
        KASSERT(config_initialized);
        KASSERT(!ifattr || cfdriver_get_iattr(parent->dv_cfdriver, ifattr));
+       KASSERT(ifattr || cfdriver_iattr_count(parent->dv_cfdriver) < 2);
 
        m.fn = fn;
        m.parent = parent;



Home | Main Index | Thread Index | Old Index