Source-Changes-HG archive

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

[src/thorpej-cfargs]: src/sys Add a CFARG_SEARCH tag, which specifies an indi...



details:   https://anonhg.NetBSD.org/src/rev/1c5ed9b8f3e7
branches:  thorpej-cfargs
changeset: 981721:1c5ed9b8f3e7
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Apr 04 19:12:27 2021 +0000

description:
Add a CFARG_SEARCH tag, which specifies an indirect config search function
(which has the same signature as a direct config submatch function).  This
is a synonym for CFARG_SUBMATCH internally, but this is an implementation
detail; the two things should be distinct to callers, because submatch
and search functions have different behaviors.  Only one SEARCH or SUBMATCH
argument is allowed.

Also, change config_get_cfargs() to panic if an unknown tag is passed
(we don't know what kind of argument to consume after an unknown tag, so
this is fatal).

diffstat:

 sys/kern/subr_autoconf.c |  21 ++++++++++++++-------
 sys/sys/device.h         |  11 ++++++-----
 2 files changed, 20 insertions(+), 12 deletions(-)

diffs (80 lines):

diff -r 461daeecad53 -r 1c5ed9b8f3e7 sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Sun Apr 04 17:43:52 2021 +0000
+++ b/sys/kern/subr_autoconf.c  Sun Apr 04 19:12:27 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.277.2.10 2021/04/03 16:09:44 thorpej Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.277.2.11 2021/04/04 19:12:27 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.10 2021/04/03 16:09:44 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.277.2.11 2021/04/04 19:12:27 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1037,7 +1037,18 @@
 
        while (tag != CFARG_EOL) {
                switch (tag) {
+               /*
+                * CFARG_SUBMATCH and CFARG_SEARCH are synonyms, but this
+                * is merely an implementation detail.  They are distinct
+                * from the caller's point of view.
+                */
                case CFARG_SUBMATCH:
+               case CFARG_SEARCH:
+                       /* Only allow one function to be specified. */
+                       if (fn != NULL) {
+                               panic("%s: caller specified both "
+                                   "SUBMATCH and SEARCH", __func__);
+                       }
                        fn = va_arg(ap, cfsubmatch_t);
                        break;
 
@@ -1054,16 +1065,12 @@
                        break;
 
                default:
-                       /* XXX panic? */
-                       /* XXX dump stack backtrace? */
-                       aprint_error("%s: unknown cfarg tag: %d\n",
+                       panic("%s: unknown cfarg tag: %d\n",
                            __func__, tag);
-                       goto out;
                }
                tag = va_arg(ap, cfarg_t);
        }
 
- out:
        if (fnp != NULL)
                *fnp = fn;
        if (ifattrp != NULL)
diff -r 461daeecad53 -r 1c5ed9b8f3e7 sys/sys/device.h
--- a/sys/sys/device.h  Sun Apr 04 17:43:52 2021 +0000
+++ b/sys/sys/device.h  Sun Apr 04 19:12:27 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.167.2.7 2021/04/03 16:09:44 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.167.2.8 2021/04/04 19:12:28 thorpej Exp $ */
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -529,10 +529,11 @@
  * config_found().
  */
 typedef enum {
-       CFARG_SUBMATCH          = 0,    /* submatch function */
-       CFARG_IATTR             = 1,    /* interface attribute */
-       CFARG_LOCATORS          = 2,    /* locators array */
-       CFARG_DEVHANDLE         = 3,    /* devhandle_t (by value) */
+       CFARG_SUBMATCH          = 0,    /* submatch function (direct config) */
+       CFARG_SEARCH            = 1,    /* search function (indirect config) */
+       CFARG_IATTR             = 2,    /* interface attribute */
+       CFARG_LOCATORS          = 3,    /* locators array */
+       CFARG_DEVHANDLE         = 4,    /* devhandle_t (by value) */
 
        CFARG_EOL               = 0xffffffff
 } cfarg_t;



Home | Main Index | Thread Index | Old Index