Index: subr_hints.c =================================================================== --- subr_hints.c (revision 240251) +++ subr_hints.c (working copy) @@ -28,12 +28,12 @@ __FBSDID("$FreeBSD$"); #include +#include +#include #include #include #include #include -#include -#include /* * Access functions for device resources. @@ -45,7 +45,7 @@ static char *hintp; /* * Define kern.hintmode sysctl, which only accept value 2, that cause to - * switch from Static KENV mode to Dynamic KENV. So systems that have hints + * switch from Static KENV mode to Dynamic KENV. So systems that have hints * compiled into kernel will be able to see/modify KENV (and hints too). */ @@ -60,21 +60,20 @@ sysctl_hintmode(SYSCTL_HANDLER_ARGS) cp = kern_envp; value = hintmode; - /* Fetch candidate for new hintmode value */ + /* Fetch candidate for new hintmode value. */ error = sysctl_handle_int(oidp, &value, 0, req); - if (error || req->newptr == NULL) + if (error != 0 || req->newptr == NULL) return (error); - if (value != 2) - /* Only accept swithing to hintmode 2 */ + if (value != 2) /* Only accept swithing to hintmode 2 */ return (EINVAL); - /* Migrate from static to dynamic hints */ + /* Migrate from static to dynamic hints. */ switch (hintmode) { case 0: if (dynamic_kenv) { /* - * Already here. But assign hintmode to 2, to not + * Already here. But assign hintmode to 2, to not * check it in the future. */ hintmode = 2; @@ -87,22 +86,30 @@ sysctl_hintmode(SYSCTL_HANDLER_ARGS) cp = static_hints; break; case 2: - /* Nothing to do, hintmode already 2 */ + /* Nothing to do, if hintmode already 2. */ return (0); } - while (cp) { + /* + * We have no source to copy from, so just update hintmode/use_kenv + * and return. + */ + if (cp == NULL) { + hintmode = value; + use_kenv = 1; + return (0); + } + + /* While next line is not empty. */ + while (*cp != '\0') { i = strlen(cp); - if (i == 0) - break; if (from_kenv) { if (strncmp(cp, "hint.", 5) != 0) - /* kenv can have not only hints */ + /* kenv can have not only hints. */ continue; } eq = strchr(cp, '='); - if (eq == NULL) - /* Bad hint value */ + if (eq == NULL) /* Bad hint value */ continue; eqidx = eq - cp;