Re: [PATCH] kconfig: Error out on duplicated kconfig inclusion
From: Nathan Chancellor
Date: Tue Feb 24 2026 - 01:01:02 EST
Hi Nicolas,
On Fri, Feb 20, 2026 at 07:55:19PM +0100, Nicolas Schier wrote:
> Let kconfig exit with error on duplicated Kconfig file inclusion.
>
> Repeated inclusion of Kbuild files are considered bad-practise with
> regard to maintenance; and Kconfig language is rich enough that there
> should be no need for that.
>
> If repeated inclusion of Kconfig files is detected, error out with
> messages like:
>
> Kconfig.inc1:4: error: Repeated inclusion of Kconfig.inc3
> Kconfig.inc2:3: note: Location of first inclusion of Kconfig.inc3
>
> While commit f094f8a1b273 ("kconfig: allow multiple inclusion of the
> same file") introduced detection of recursive inclusions of Kconfig
> files, it explicitly allowed repeated inclusions, unfortunately w/o
> reasoning.
>
> Reported-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> Closes: https://lore.kernel.org/all/CAHk-=wj03hLzK2D=+OYmjgcmGM+XYymp8GyaEs=C0=rXG2nb7w@xxxxxxxxxxxxxx/
> Signed-off-by: Nicolas Schier <nsc@xxxxxxxxxx>
Nice! That was quite simple in terms of actual implementation and I like
the tests :) I verified that there are errors from the drm/Kconfig state
at ca4ee40bf13d^:
drivers/gpu/drm/Kconfig:427: error: Repeated inclusion of drivers/gpu/drm/adp/Kconfig
drivers/gpu/drm/Kconfig:385: note: Location of first inclusion of drivers/gpu/drm/adp/Kconfig
and that testconfig passes for me locally.
Reviewed-by: Nathan Chancellor <nathan@xxxxxxxxxx>
Tested-by: Nathan Chancellor <nathan@xxxxxxxxxx>
> diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
> index 5cdcee144b58126dcfab50fd709be9fc40e99423..1b69dd9e1872a0671a70e24b45a30e449dd2c75e 100644
> --- a/scripts/kconfig/util.c
> +++ b/scripts/kconfig/util.c
> @@ -18,25 +18,50 @@ static HASHTABLE_DEFINE(file_hashtable, 1U << 11);
...
> +static void die_duplicated_include(struct file *file,
> + const char *parent, int lineno)
> +{
> + fprintf(stderr,
> + "%s:%d: error: Repeated inclusion of %s\n"
> + "%s:%d: note: Location of first inclusion of %s\n",
I think for visual consistency with compiler warnings/errors and the
rest of scripts/kconfig, Repeated and Location should be lowercased in
these prints.
> + parent, lineno, file->name,
> + file->parent.name, file->parent.lineno, file->name);
> + exit(1);
Cheers,
Nathan