Linux Documentation
 help / color / mirror / Atom feed
From: Julian Braha <julianbraha@gmail.com>
To: nathan@kernel.org, nsc@kernel.org
Cc: ojeda@kernel.org, akpm@linux-foundation.org,
	jani.nikula@linux.intel.com, gary@garyguo.net,
	gregkh@linuxfoundation.org, arnd@arndb.de, ljs@kernel.org,
	andrew.jones@linux.dev, masahiroy@kernel.org, corbet@lwn.net,
	qingfang.deng@linux.dev, demiobenour@gmail.com, ej@inai.de,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org,
	Julian Braha <julianbraha@gmail.com>
Subject: [PATCH v4 1/5] kconfig: add add another callback to the parser to view raw parse tree
Date: Mon, 27 Jul 2026 01:16:19 +0100	[thread overview]
Message-ID: <20260727001623.2794156-2-julianbraha@gmail.com> (raw)
In-Reply-To: <20260727001623.2794156-1-julianbraha@gmail.com>

The final step of the Kconfig parser is to call menu_finalize(), which
will evaluate the dead code that static code analyzers like kconfirm need
to be able to view.

This patch adds another callback to the parser just before this call to
menu_finalize(), making the raw parse tree viewable as necessary to
callers of conf_set_pre_finalize_callback().

Assisted-by: Claude:claude-fable-5
Signed-off-by: Julian Braha <julianbraha@gmail.com>
---
 scripts/kconfig/lkc_proto.h |  2 ++
 scripts/kconfig/parser.y    | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index 8914b4e8f2a8..f03bcef7b270 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -6,6 +6,8 @@
 
 /* confdata.c */
 void conf_parse(const char *name);
+void conf_set_pre_finalize_callback(void (*fn)(const struct menu *root, void *data),
+				    void *data);
 int conf_read(const char *name);
 int conf_read_simple(const char *name, int);
 int conf_write_defconfig(const char *name);
diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y
index 5fb6f07b6ad2..365ed450e855 100644
--- a/scripts/kconfig/parser.y
+++ b/scripts/kconfig/parser.y
@@ -28,6 +28,9 @@ static void zconf_error(const char *err, ...);
 static bool zconf_endtoken(const char *tokenname,
 			   const char *expected_tokenname);
 
+static void (*conf_pre_finalize_callback)(const struct menu *root, void *data);
+static void *conf_pre_finalize_callback_data;
+
 struct menu *current_menu, *current_entry, *current_choice;
 
 %}
@@ -551,6 +554,20 @@ static int choice_check_sanity(const struct menu *menu)
 	return ret;
 }
 
+/*
+ * Register a callback to be invoked by conf_parse() once parsing has finished,
+ * but before menu_finalize() propagates dependencies and simplifies
+ * expressions. This hands the callback the menu tree as it was written in the
+ * Kconfig source files, which is what static analysis tools like kconfirm
+ * need. Passing NULL unregisters the callback.
+ */
+void conf_set_pre_finalize_callback(void (*fn)(const struct menu *root, void *data),
+				    void *data)
+{
+	conf_pre_finalize_callback = fn;
+	conf_pre_finalize_callback_data = fn ? data : NULL;
+}
+
 void conf_parse(const char *name)
 {
 	struct menu *menu;
@@ -587,6 +604,10 @@ void conf_parse(const char *name)
 		menu_add_prompt(P_MENU, "Main menu", NULL);
 	}
 
+	if (conf_pre_finalize_callback)
+		conf_pre_finalize_callback(&rootmenu,
+					   conf_pre_finalize_callback_data);
+
 	menu_finalize();
 
 	menu_for_each_entry(menu) {
-- 
2.54.0


  reply	other threads:[~2026-07-27  0:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27  0:16 [PATCH v4 0/5] add kconfirm Julian Braha
2026-07-27  0:16 ` Julian Braha [this message]
2026-07-27  0:16 ` [PATCH 2/5] kconfig: " Julian Braha
2026-07-27  0:16 ` [PATCH v4 3/5] kconfirm: add tests Julian Braha
2026-07-27  0:16 ` [PATCH v4 4/5] Documentation: add kconfirm Julian Braha
2026-07-27  0:16 ` [PATCH v4 5/5] MAINTAINERS: add entry for kconfirm Julian Braha

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=20260727001623.2794156-2-julianbraha@gmail.com \
    --to=julianbraha@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrew.jones@linux.dev \
    --cc=arnd@arndb.de \
    --cc=corbet@lwn.net \
    --cc=demiobenour@gmail.com \
    --cc=ej@inai.de \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=qingfang.deng@linux.dev \
    --cc=rust-for-linux@vger.kernel.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