Skip to content

Commit 7cd3430

Browse files
sergey-senozhatskymasahir0y
authored andcommitted
kconfig: add warn-unknown-symbols sanity check
Introduce KCONFIG_WARN_UNKNOWN_SYMBOLS environment variable, which makes Kconfig warn about unknown config symbols. This is especially useful for continuous kernel uprevs when some symbols can be either removed or renamed between kernel releases (which can go unnoticed otherwise). By default KCONFIG_WARN_UNKNOWN_SYMBOLS generates warnings, which are non-terminal. There is an additional environment variable KCONFIG_WERROR that overrides this behaviour and turns warnings into errors. Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent bfb41e4 commit 7cd3430

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Documentation/kbuild/kconfig.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ KCONFIG_OVERWRITECONFIG
5454
If you set KCONFIG_OVERWRITECONFIG in the environment, Kconfig will not
5555
break symlinks when .config is a symlink to somewhere else.
5656

57+
KCONFIG_WARN_UNKNOWN_SYMBOLS
58+
----------------------------
59+
This environment variable makes Kconfig warn about all unrecognized
60+
symbols in the config input.
61+
62+
KCONFIG_WERROR
63+
--------------
64+
If set, Kconfig treats warnings as errors.
65+
5766
`CONFIG_`
5867
---------
5968
If you set `CONFIG_` in the environment, Kconfig will prefix all symbols

scripts/kconfig/confdata.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,11 @@ int conf_read_simple(const char *name, int def)
349349
char *p, *p2;
350350
struct symbol *sym;
351351
int i, def_flags;
352+
const char *warn_unknown;
353+
const char *werror;
352354

355+
warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS");
356+
werror = getenv("KCONFIG_WERROR");
353357
if (name) {
354358
in = zconf_fopen(name);
355359
} else {
@@ -437,6 +441,10 @@ int conf_read_simple(const char *name, int def)
437441
if (def == S_DEF_USER) {
438442
sym = sym_find(line + 2 + strlen(CONFIG_));
439443
if (!sym) {
444+
if (warn_unknown)
445+
conf_warning("unknown symbol: %s",
446+
line + 2 + strlen(CONFIG_));
447+
440448
conf_set_changed(true);
441449
continue;
442450
}
@@ -471,16 +479,21 @@ int conf_read_simple(const char *name, int def)
471479

472480
sym = sym_find(line + strlen(CONFIG_));
473481
if (!sym) {
474-
if (def == S_DEF_AUTO)
482+
if (def == S_DEF_AUTO) {
475483
/*
476484
* Reading from include/config/auto.conf
477485
* If CONFIG_FOO previously existed in
478486
* auto.conf but it is missing now,
479487
* include/config/FOO must be touched.
480488
*/
481489
conf_touch_dep(line + strlen(CONFIG_));
482-
else
490+
} else {
491+
if (warn_unknown)
492+
conf_warning("unknown symbol: %s",
493+
line + strlen(CONFIG_));
494+
483495
conf_set_changed(true);
496+
}
484497
continue;
485498
}
486499

@@ -519,6 +532,10 @@ int conf_read_simple(const char *name, int def)
519532
}
520533
free(line);
521534
fclose(in);
535+
536+
if (conf_warnings && werror)
537+
exit(1);
538+
522539
return 0;
523540
}
524541

0 commit comments

Comments
 (0)