From owner-svn-src-stable@freebsd.org Sat Aug 4 22:15:06 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 790F7105523D; Sat, 4 Aug 2018 22:15:06 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2DFC78B2AA; Sat, 4 Aug 2018 22:15:06 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0F1AC1574C; Sat, 4 Aug 2018 22:15:06 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w74MF5F5062766; Sat, 4 Aug 2018 22:15:05 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w74MF5uj062762; Sat, 4 Aug 2018 22:15:05 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808042215.w74MF5uj062762@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 4 Aug 2018 22:15:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r337336 - in stable/11/sys: kern sys X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/11/sys: kern sys X-SVN-Commit-Revision: 337336 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Aug 2018 22:15:06 -0000 Author: kevans Date: Sat Aug 4 22:15:05 2018 New Revision: 337336 URL: https://svnweb.freebsd.org/changeset/base/337336 Log: MFC r336152-r336154, r336157 r336152: subr_hints: Use goto/label instead of series of conditionals r336153: subr_hints: Convert some bool-like ints to bools r336154: subr_hints: Skip static_env and static_hints if they don't contain hints This is possible because, well, they're static. Both the dynamic environment and the MD-environment (generally loader(8) environment) can potentially have room for new variables to be set, and thus do not receive this treatment. r336157: kern_environment: bool'itize dynamic_kenv; fix small style(9) nit Modified: stable/11/sys/kern/kern_environment.c stable/11/sys/kern/subr_hints.c stable/11/sys/sys/systm.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/kern_environment.c ============================================================================== --- stable/11/sys/kern/kern_environment.c Sat Aug 4 22:12:12 2018 (r337335) +++ stable/11/sys/kern/kern_environment.c Sat Aug 4 22:15:05 2018 (r337336) @@ -37,7 +37,6 @@ #include __FBSDID("$FreeBSD$"); -#include #include #include #include @@ -79,7 +78,7 @@ struct mtx kenv_lock; /* * No need to protect this with a mutex since SYSINITS are single threaded. */ -int dynamic_kenv = 0; +bool dynamic_kenv; #define KENV_CHECK if (!dynamic_kenv) \ panic("%s: called before SI_SUB_KMEM", __func__) @@ -98,7 +97,7 @@ sys_kenv(td, uap) size_t len, done, needed, buflen; int error, i; - KASSERT(dynamic_kenv, ("kenv: dynamic_kenv = 0")); + KASSERT(dynamic_kenv, ("kenv: dynamic_kenv = false")); error = 0; if (uap->what == KENV_DUMP) { @@ -352,7 +351,7 @@ init_dynamic_kenv(void *data __unused) kenvp[dynamic_envpos] = NULL; mtx_init(&kenv_lock, "kernel environment", NULL, MTX_DEF); - dynamic_kenv = 1; + dynamic_kenv = true; } SYSINIT(kenv, SI_SUB_KMEM + 1, SI_ORDER_FIRST, init_dynamic_kenv, NULL); @@ -506,7 +505,7 @@ kern_setenv(const char *name, const char *value) char *buf, *cp, *oldenv; int namelen, vallen, i; - if (dynamic_kenv == 0 && md_env_len > 0) + if (!dynamic_kenv && md_env_len > 0) return (setenv_static(name, value)); KENV_CHECK; Modified: stable/11/sys/kern/subr_hints.c ============================================================================== --- stable/11/sys/kern/subr_hints.c Sat Aug 4 22:12:12 2018 (r337335) +++ stable/11/sys/kern/subr_hints.c Sat Aug 4 22:15:05 2018 (r337336) @@ -46,8 +46,10 @@ __FBSDID("$FreeBSD$"); * has already been setup (dynamic_kenv) and that we have added any supplied * static_hints to the dynamic environment. */ -static int hintenv_merged; - +static bool hintenv_merged; +/* Static environment and static hints cannot change, so we'll skip known bad */ +static bool stenv_skip; +static bool sthints_skip; /* * Access functions for device resources. */ @@ -82,7 +84,7 @@ static_hints_to_env(void *data __unused) free(line, M_TEMP); cp += i + 1; } - hintenv_merged = 1; + hintenv_merged = true; } /* Any time after dynamic env is setup */ @@ -122,13 +124,14 @@ res_find(char **hintp_cookie, int *line, int *startln, const char **ret_name, int *ret_namelen, int *ret_unit, const char **ret_resname, int *ret_resnamelen, const char **ret_value) { - int dyn_used = 0, fbacklvl = FBACK_MDENV, hit, i = 0, n = 0; + int fbacklvl = FBACK_MDENV, i = 0, n = 0; char r_name[32]; int r_unit; char r_resname[32]; char r_value[128]; const char *s, *cp; char *hintp, *p; + bool dyn_used = false; /* @@ -155,7 +158,7 @@ res_find(char **hintp_cookie, int *line, int *startln, } } mtx_unlock(&kenv_lock); - dyn_used = 1; + dyn_used = true; } else { /* * We'll have a chance to keep coming back here until @@ -176,17 +179,21 @@ fallback: } fbacklvl++; - if (fbacklvl <= FBACK_STENV && + if (!stenv_skip && fbacklvl <= FBACK_STENV && _res_checkenv(kern_envp)) { hintp = kern_envp; goto found; - } + } else + stenv_skip = true; + fbacklvl++; /* We'll fallback to static_hints if needed/can */ - if (fbacklvl <= FBACK_STATIC && + if (!sthints_skip && fbacklvl <= FBACK_STATIC && _res_checkenv(static_hints)) hintp = static_hints; + else + sthints_skip = true; found: fbacklvl++; } @@ -197,7 +204,7 @@ found: } else { hintp = *hintp_cookie; if (hintenv_merged && hintp == kenvp[0]) - dyn_used = 1; + dyn_used = true; else /* * If we aren't using the dynamic environment, we need @@ -215,34 +222,30 @@ found: cp = hintp; while (cp) { - hit = 1; (*line)++; if (strncmp(cp, "hint.", 5) != 0) - hit = 0; - else - n = sscanf(cp, "hint.%32[^.].%d.%32[^=]=%127s", - r_name, &r_unit, r_resname, r_value); - /* We'll circumvent all of the checks if we already know */ - if (hit) { - if (n != 4) { - printf("CONFIG: invalid hint '%s'\n", cp); - p = strchr(cp, 'h'); - *p = 'H'; - hit = 0; - } - if (hit && startln && *startln >= 0 && *line < *startln) - hit = 0; - if (hit && name && strcmp(name, r_name) != 0) - hit = 0; - if (hit && unit && *unit != r_unit) - hit = 0; - if (hit && resname && strcmp(resname, r_resname) != 0) - hit = 0; - if (hit && value && strcmp(value, r_value) != 0) - hit = 0; - if (hit) - break; + goto nexthint; + n = sscanf(cp, "hint.%32[^.].%d.%32[^=]=%127s", r_name, &r_unit, + r_resname, r_value); + if (n != 4) { + printf("CONFIG: invalid hint '%s'\n", cp); + p = strchr(cp, 'h'); + *p = 'H'; + goto nexthint; } + if (startln && *startln >= 0 && *line < *startln) + goto nexthint; + if (name && strcmp(name, r_name) != 0) + goto nexthint; + if (unit && *unit != r_unit) + goto nexthint; + if (resname && strcmp(resname, r_resname) != 0) + goto nexthint; + if (value && strcmp(value, r_value) != 0) + goto nexthint; + /* Successfully found a hint matching all criteria */ + break; +nexthint: if (dyn_used) { cp = kenvp[++i]; if (cp == NULL) Modified: stable/11/sys/sys/systm.h ============================================================================== --- stable/11/sys/sys/systm.h Sat Aug 4 22:12:12 2018 (r337335) +++ stable/11/sys/sys/systm.h Sat Aug 4 22:15:05 2018 (r337336) @@ -148,7 +148,7 @@ void kassert_panic(const char *fmt, ...) __printflike * XXX most of these variables should be const. */ extern int osreldate; -extern int dynamic_kenv; +extern bool dynamic_kenv; extern struct mtx kenv_lock; extern char *kern_envp; extern char *md_envp;