From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36A461DDC2B for ; Mon, 27 Jul 2026 00:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785111393; cv=none; b=kCrfE0HI8QG4YHWHMRhg6bDc79jRlpu5td1w1Zf4MRHprab7UYGAr45sJYAtJoRYFVw1UeBAVTqXvIReVunUKTe0ZNStdpgYO3T2Sew5/C4TQADlqXZkSch4ayGIwQx1o0P1A2YX2tNXYFNMGI9x23cUXu7alwDSibkadifSOWA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785111393; c=relaxed/simple; bh=pmxL9+hOehI9g0heQQ26Ixv9tv6ssgP2T5QpyiPRXYo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pHkFhzLQ5wLgvbNnJYu0WjMxiQ11WUvZ6469BqbqOvUrCYen4kt/2oUF/PoEyFofIWqxSvBz4wrtNHT6IUxwUoLuJv84nYxey4WCev2pxuXvNvciWvGZXtDobxOSKErq+UyA3NCNEKeKRWtbaFv3lQ/RMnR12Mbu1QkL0H242zw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GfSH/aU4; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GfSH/aU4" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-49545ba3d4eso12357615e9.3 for ; Sun, 26 Jul 2026 17:16:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785111390; x=1785716190; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xh/3Pl721PFhB4JhF2fGID/z/BCCds8YijN/rARhrb8=; b=GfSH/aU4LzxwCqpka7VS3O/jomlXidZhUZZ5XBaFNsq8/Bzklsf+iJ52Do+0RLroLG 3WYHkpZ6omHwzwUmn1xNP82jX/2ja1tV9J1GLF8qgl2GIFIJojaJzrQdCeblJa92cc90 xWzxkFck1Sk04dcXCCrEFHKcG6HwI3QvUoHOIvOCfzh4/zIkUhFxbBj86wFoNlizK04w 1MBiojYC+8MSbqKufiK6JD7bgUUZ88OzCGHH2GujHYrpTnmgpEvzOU0vRGdb540kehD4 Umd8X6y/JoLCg0DsjrZb5h4YT0ZHzFFXEduZUSRCQHrVotcxngDeVjASJpdkqflJXcIE G2NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785111390; x=1785716190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xh/3Pl721PFhB4JhF2fGID/z/BCCds8YijN/rARhrb8=; b=IW0ND++sOQNY0/Kott/Elv/8g7PMhMrsxq+1NV5ndagkQB2bnohIFKCPUBQxjA5lLw RW142qv+rTvIU4aBLr4LwKv3bLk6dyk3qhPhVME4Il5pN90/rG0y/y1pEOJ8+iF+SM9e F7TlebnrDUj/LKcZPtrYrhWOKHNSk5J/+u6kwbLqZLi0Gx0o6eO9WRk+p+Xj3LZVTuk2 Vvukz3D4CKBXFKgCt98RgOYqcoyj7yk8GS9OBF1L5T+AcrybH5RH2hTZigKlw/FhCNP+ 8rlZdC2vUSj1aN5L/MythFsykMsEXL1/qbwSZafCA4TFkQnZqaHbA7zzZyJc4YOD1s0D 0KSg== X-Forwarded-Encrypted: i=1; AHgh+Ro3y83bXZ2NfUsSJPYtH2mVfyuJ6B/HM5/Qb3EDQc9XZAn93ytYnE1g1rexdx6Oh0eLb1tqB4o2aEPzyRs=@vger.kernel.org X-Gm-Message-State: AOJu0Yyk+my+TngPA4b+0dUoMOHz6OybxI4xJgF7noaMS1qxNvEyBmY6 2h5XR9ypfp63i4oNnvZQcuqudzefZf4DoFg9Rb4pFoFc0VdnVdzZXQD4 X-Gm-Gg: AR+sD12RiIOfvaGh0KH6X9o70kiacFaksbgzVXnUzoPY9Cu3WtfuCxzIfoyY1eznokV B9nWHHEGhZjVgQbItMp3KbB73gYwtEFZdcLvLpoy4/4+MoK3OQEA+wd6S9rztnOAAxSuI+2uXBR Vqxs1fK8/v4l6axHT0JAoITb81hLNtap4VvrlV25u1JskCM8uPUQvonc92i3FzWeyo1F9x0lgoQ LjU/1FVO4NVNbn6R3Eghye+Vq3CPvHVuQbrDLk5N7NzQV6XQsxhLf2ApVbgBxz5dPrLDeRvekru MS5djf3yg3EG3P1AvY5XnOxw5bkLbhTdtbOSH2BPaIJphlXL7rU9ZOO2Fi9aKM7d6x4kaPWzTbk ukQE9c7JTb85G0rleKMheZtIgKkoMKDmdmKg7SCS4Vyr6jEZfQAELpPZztbZMYI4lMGfXvB/pqu BSQ3iy+9E/wapP4D4KpY+ypWpx63QR5ObfmLtomT6SIuVqluE8RzVPaacdV7oOB6FAxg== X-Received: by 2002:a05:600c:6296:b0:494:282:106c with SMTP id 5b1f17b1804b1-496b56fb438mr74540935e9.16.1785111390266; Sun, 26 Jul 2026 17:16:30 -0700 (PDT) Received: from nixos-office (195-23-151-163.net.novis.pt. [195.23.151.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-496b485f65csm176403555e9.5.2026.07.26.17.16.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jul 2026 17:16:29 -0700 (PDT) Sender: Julian Braha From: Julian Braha 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 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 Message-ID: <20260727001623.2794156-2-julianbraha@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260727001623.2794156-1-julianbraha@gmail.com> References: <20260727001623.2794156-1-julianbraha@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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