public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Nicolas Schier <nsc@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] kconfig: Error out on duplicated kconfig inclusion
Date: Mon, 23 Feb 2026 23:00:49 -0700	[thread overview]
Message-ID: <20260224060049.GA588195@ax162> (raw)
In-Reply-To: <20260220-kconfig-error-out-on-duplicated-inclusion-v1-1-be78aa241a53@kernel.org>

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@linux-foundation.org>
> Closes: https://lore.kernel.org/all/CAHk-=wj03hLzK2D=+OYmjgcmGM+XYymp8GyaEs=C0=rXG2nb7w@mail.gmail.com/
> Signed-off-by: Nicolas Schier <nsc@kernel.org>

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@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>

> 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

  reply	other threads:[~2026-02-24  6:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-20 18:55 [PATCH] kconfig: Error out on duplicated kconfig inclusion Nicolas Schier
2026-02-24  6:00 ` Nathan Chancellor [this message]
2026-02-27  8:30 ` Nicolas Schier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260224060049.GA588195@ax162 \
    --to=nathan@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nsc@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox