From patchwork Sun Mar 10 14:16:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13588136 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 610CF219E9; Sun, 10 Mar 2024 14:16:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710080185; cv=none; b=oASdNh9XV7e2r2l3yH6A4iYrUi4S+5dbRO6rHKv5o3jRIDqqV7a8+8MKpznAfrDn3dCye3I31qXEut4cqRMD+DeSmQs5NUZPY9JdAdUS5+VnpDw1HtOWobXImuJh32nXlfT/wfQOEW//zgNumK31RRia7x9JdejZeQI/ySZNcyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710080185; c=relaxed/simple; bh=vyUsoJZwUXiUt3No7I9+cObd7fy28lhRp41UtwCxqJY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=mhUsgSrRztzOVgpRdhlkpfOLEowNCRQOwG4YRh9yA9sSndtHaLwC0mS9y2dJklHU669hVY3g8iMh/Mb+p3xrMIqKz35Rl/ExGTkKPWayLrELdHBMCo03847gzyXJF3XohWdNMlStHizqkDmcIYXu+S+Zn39W9UzagPJEhaRWrwk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HFMJZqo8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HFMJZqo8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2384BC433C7; Sun, 10 Mar 2024 14:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710080185; bh=vyUsoJZwUXiUt3No7I9+cObd7fy28lhRp41UtwCxqJY=; h=From:To:Cc:Subject:Date:From; b=HFMJZqo8NovSBYUW6KVuJ+kabC2HJ4ZThfGIVrzziubNHLkwweLsH6dp4l/XO39/p Ft1QNkhJI4iyEeDHX3l8QWYKDj/NptDCPeXlC4TfGenUElikfYy/wfc5m/+mbZsJU/ c7pSzvb+KVi5guKRd79sO7LrwRC04NOSQAwOpiLYt08Qlz7fcgWMMXWPXGvrrnzJls buMgDHPWvOqVYpltUEf8zCmG2joJKTQL5FyoUKrLWrk3XWU0TLif1xTiQYKYKWGh1I YAXJZ7vfOQeqjVkaObK+enw6wTLZbhg9wCBXopQaI9RB/zCQ4EeMp0eyDbqhv3S+7n sp77D5P+/NwiA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 1/3] kconfig: remove unneeded menu_is_visible() call in conf_write_defconfig() Date: Sun, 10 Mar 2024 23:16:17 +0900 Message-Id: <20240310141619.606415-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When the condition 'sym == NULL' is met, the code will reach the 'next_menu' label regardless of the return value from menu_is_visible(). menu_is_visible() calculates some symbol values as a side-effect, for instance by calling expr_calc_value(menu->visibility), but all the symbol values will be calculated eventually. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index c5b6487d68ac..0e35c4819cf1 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -799,10 +799,7 @@ int conf_write_defconfig(const char *filename) while (menu != NULL) { sym = menu->sym; - if (sym == NULL) { - if (!menu_is_visible(menu)) - goto next_menu; - } else if (!sym_is_choice(sym)) { + if (sym && !sym_is_choice(sym)) { sym_calc_value(sym); if (!(sym->flags & SYMBOL_WRITE)) goto next_menu; From patchwork Sun Mar 10 14:16:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13588137 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F179F364A8; Sun, 10 Mar 2024 14:16:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710080187; cv=none; b=OHum3kSXRsN88Sm4ZHIps0A2zDZNXb9BnmqrKaNiqLXSazNlFEkDI0ZWHlYKZ5q5bXqQ822V4Dg93ylW/hDHTQYzzgk9yxMAw98mQ2n9XbfKvF9q3L6NK+4AeE3HeDAaGNTrB0L58BxOGVEMa0rgw2mUFGaaCsGiZTGlLfA8/xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710080187; c=relaxed/simple; bh=/Dth7Oao/M9/4eesqTDyXiBgGgbrahl+e7eHqlVqpEA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jmjfoRaZUUEoGWh+JUXJEeeim9Qvz6bGNzpwwcHvsqc8w4aukFJAMLqMnluvHUc2f10BLd/h6wF1+UOveraE28WT+Q+h8iu6nW2THMT6Y6sg28xw+Gh/exbrh2aaqkbvo+blHoPxYvnVwVi1VR5ebgaGeiM2v4PmIK2in3hN1kg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jHblSTb5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jHblSTb5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89B7BC433C7; Sun, 10 Mar 2024 14:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710080186; bh=/Dth7Oao/M9/4eesqTDyXiBgGgbrahl+e7eHqlVqpEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHblSTb5sPHqVe6cc8nRjcfYpUktPB7R5/xxVKcAN94TDS192tucsuoVxPDs92kIt UB2Ml7YgjhrmCYIqgFNfvL7IED6QjHmbJ7KTs9SeYJgotzc71ALGbJ/4+7nljVA0Qt Qe+23JlpKJufD+kXe59OF4ZsNSXXdZ2iKJlAz3ez77BinpR6I1Pjs8sux5X8YI2b1/ QDjonVHKX5JlmZ5py4HVLx54OgdWLVvN7XAVmNsmW3fR0vxyuekqi5S1y9oulyuKsH VCXpbBgzO3zzb/rY7AVqlYoAumUtqNaWpJsRSErwaEDU/mve/IPcaSedxQuxrL9XIG XYYF9povPAfQw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 2/3] kconfig: add menu_next() function and menu_for_each(_sub)_entry macros Date: Sun, 10 Mar 2024 23:16:18 +0900 Message-Id: <20240310141619.606415-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240310141619.606415-1-masahiroy@kernel.org> References: <20240310141619.606415-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Several functions require traversing menu entries sequentially. This commit introduces some helpers to simplify such operations. The menu_next() function facilitates depth-first traversal: 1. Descend to the child level if the current menu has one 2. Move to the next sibling at the same level if available 3. Ascend to the parent level if there is no more child or sibling The menu_for_each_sub_entry() macro iterates over all submenu entries using depth-first traverse. The menu_for_each_entry() macro is the same, but over all menu entries. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lkc.h | 5 +++++ scripts/kconfig/menu.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index e69d7c59d930..5241dccd559e 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -79,6 +79,11 @@ void str_printf(struct gstr *gs, const char *fmt, ...); char *str_get(struct gstr *gs); /* menu.c */ +struct menu *menu_next(struct menu *menu); +#define menu_for_each_sub_entry(menu, root) \ + for (struct menu *menu = (root)->list; menu != (root)->next && menu != (root)->parent; menu = menu_next(menu)) +#define menu_for_each_entry(menu) \ + menu_for_each_sub_entry(menu, &rootmenu) void _menu_init(void); void menu_warn(struct menu *menu, const char *fmt, ...); struct menu *menu_add_menu(void); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 8498481e6afe..417dc01ac412 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -17,6 +17,21 @@ static const char nohelp_text[] = "There is no help available for this option."; struct menu rootmenu; static struct menu **last_entry_ptr; +/** + * menu_next - return the next menu entry with depth-first traversal + * @menu: the pointer to the current menu + */ +struct menu *menu_next(struct menu *menu) +{ + if (menu->list) + return menu->list; + + while (!menu->next && menu->parent) + menu = menu->parent; + + return menu->next; +} + void menu_warn(struct menu *menu, const char *fmt, ...) { va_list ap; From patchwork Sun Mar 10 14:16:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13588138 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 509F6376FE; Sun, 10 Mar 2024 14:16:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710080188; cv=none; b=Hn5tiMlYTXqeFd5zCzIFvS4oEmBEImnilbz5f2j06gLUN8JiSP/eRIyP4zJrRNo+EsZLjytWc8ZdGBHWqpQQUkD0kSmp6NkNcfaqkG28uspgoc0LoG3j+nOseyCF6bVLFa74qEeiFlnEhGFItFccMQPv07aBCAwGdQbFiZIJESw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710080188; c=relaxed/simple; bh=7vHRaqub7OyWr23f8EkYfPHp+c5k770mXy9fDSYLW7w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=efiomIrhUaPbnbghybKERTORxmRx4k28Vf1jX1bWpbL1+CdNVOSqiD5LfctWbVynp8XSLSOj8w2v4K72ywwC5AHrvtddQtluuec5bufC5q3xwABSRPmb5hxK4vYBGMS1wknJcgu9lL3JDK4AmZ9A6KCP0ly4Spl/mWlnHinWlBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=umV6OlMc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="umV6OlMc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E475FC433F1; Sun, 10 Mar 2024 14:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710080187; bh=7vHRaqub7OyWr23f8EkYfPHp+c5k770mXy9fDSYLW7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=umV6OlMcWsSGI86w0sG3Xcw+0gRNusmwvmRktKRlAhxtM8k8mwVdfEUBi087Zx1fa BPb1z1SzDNv/kC7z6SWhT/DTm2DJ9PbcETLoCUU6bo5bh5EwNUJDblT3MsIkHSPhgf ljt6y4CUTLqJN/qtvCt73tzDZcKUW0FzjvHGrgeRXvnleK+Rm1yJpUsrrvGrtY3AFy pTQTRhjOS2qCa+zhrRdd8ybqDyQyjaFgPUlkHb5Dolal1Lvjzai3RsAhoRdnoAtOuy +pFBDgr2T793Rl/PcHu4fz5FUvEyTi4TSdcik9gm3YaOAL/Ix7bZZvfRbfN662Wmne 8Udf029VIDhSw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 3/3] kconfig: use menu_for_each_entry() to traverse menu tree Date: Sun, 10 Mar 2024 23:16:19 +0900 Message-Id: <20240310141619.606415-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240310141619.606415-1-masahiroy@kernel.org> References: <20240310141619.606415-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use menu_for_each_entry() to traverse the menu tree instead of implementing similar logic in each function. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 29 +++++------------------------ scripts/kconfig/parser.y | 15 +-------------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 0e35c4819cf1..16066730a6a0 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -784,7 +784,6 @@ static void print_symbol_for_rustccfg(FILE *fp, struct symbol *sym) int conf_write_defconfig(const char *filename) { struct symbol *sym; - struct menu *menu; FILE *out; out = fopen(filename, "w"); @@ -793,23 +792,19 @@ int conf_write_defconfig(const char *filename) sym_clear_all_valid(); - /* Traverse all menus to find all relevant symbols */ - menu = rootmenu.list; - - while (menu != NULL) - { + menu_for_each_entry(menu) { sym = menu->sym; if (sym && !sym_is_choice(sym)) { sym_calc_value(sym); if (!(sym->flags & SYMBOL_WRITE)) - goto next_menu; + continue; sym->flags &= ~SYMBOL_WRITE; /* If we cannot change the symbol - skip */ if (!sym_is_changeable(sym)) - goto next_menu; + continue; /* If symbol equals to default value - skip */ if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0) - goto next_menu; + continue; /* * If symbol is a choice value and equals to the @@ -827,25 +822,11 @@ int conf_write_defconfig(const char *filename) if (!sym_is_optional(cs) && sym == ds) { if ((sym->type == S_BOOLEAN) && sym_get_tristate_value(sym) == yes) - goto next_menu; + continue; } } print_symbol_for_dotconfig(out, sym); } -next_menu: - if (menu->list != NULL) { - menu = menu->list; - } - else if (menu->next != NULL) { - menu = menu->next; - } else { - while ((menu = menu->parent)) { - if (menu->next != NULL) { - menu = menu->next; - break; - } - } - } } fclose(out); return 0; diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index b45bfaf0a02b..a69a453e4f44 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -473,8 +473,6 @@ assign_val: void conf_parse(const char *name) { - struct menu *menu; - autoconf_cmd = str_new(); str_printf(&autoconf_cmd, "\ndeps_config := \\\n"); @@ -517,20 +515,9 @@ void conf_parse(const char *name) menu_finalize(&rootmenu); - menu = &rootmenu; - while (menu) { + menu_for_each_entry(menu) { if (menu->sym && sym_check_deps(menu->sym)) yynerrs++; - - if (menu->list) { - menu = menu->list; - continue; - } - - while (!menu->next && menu->parent) - menu = menu->parent; - - menu = menu->next; } if (yynerrs)