From patchwork Sun Apr 21 09:02:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13637309 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 DB491DDA6; Sun, 21 Apr 2024 09:02:58 +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=1713690179; cv=none; b=rljYB/RoYZf6+Hg1T+WBAotZuKeElD5U5XZDUCh26UdXhgkxPS2YG+ENdS6wDpRDGFWBPLHzM7HWwA3rvWmR4Rvm5AxkHX4tm+Hu3+juTWv4Xo/URF9YCNBVp29r+uAxuZxyWqRi/ptIwh0sjQa35PKO2BIU9GxiqCzbtDCGAXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713690179; c=relaxed/simple; bh=zlw4QwpoCgMvxjEIvSbcsPVdEQPaECLZAx6t1pVEAPE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=RFtuKQguD/Daij9+7BxB8isgp6Cu7/ChLh9gb9k+ftrV+Ec//IWWqQZvXia4hjh+i62Q+c49kQSixWsVRMcnRTSddtJ0Zg6WJgR3jzQKd+1pS3FKZnm5+JNbAa51i1k1izRhQbm0QxdMFDXuqIxg26mu6Vaz92d159qOp1r2DSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LEAYOryr; 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="LEAYOryr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B47B5C113CE; Sun, 21 Apr 2024 09:02:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713690178; bh=zlw4QwpoCgMvxjEIvSbcsPVdEQPaECLZAx6t1pVEAPE=; h=From:To:Cc:Subject:Date:From; b=LEAYOryr3lT+RONfhWFOeSRG2G7OjwXBvOaco0fC7BQe8x/3APylzONctWedzpas/ yLXgLlJJjXI15RkLV06IL8yBQ5B54xYzqIqBdvQrP0ldNLI3zkgPjXfhRNFV1mgvCT a5RwKWaadbVuVDfg8P9b4ZTm6CaiEP2D7YvvvKFHixXVrlhQqTWVWktyjzvD6o8UUC cbJvEXcAUWCnDHj12kB6W/m2Lnm0rB0+YZuhJt8HCSLp4drT/s4GL6fXwnNwArhsiU itgU1/STPnJOeC/lvSUDir4OgNp6euJvZJqtIZfq88Zm0Ti0e3nVfM7hAkjIAip7bB IQ0uNS6ibokww== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 1/2] kconfig: add menu_next() function and menu_for_each(_sub)_entry macros Date: Sun, 21 Apr 2024 18:02:51 +0900 Message-Id: <20240421090252.2700867-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 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 | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index e7cc9e985c4f..cfb7e9ac41a3 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, struct menu *root); +#define menu_for_each_sub_entry(menu, root) \ + for (menu = menu_next(root, root); menu; menu = menu_next(menu, root)) +#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 3b822cd110f4..fe6af8700622 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -17,6 +17,27 @@ 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: pointer to the current menu + * @root: root of the sub-tree to traverse. If NULL is given, the traveral + * continues until it reaches the end of the entire menu tree. + * return: the menu to visit next, or NULL when it reaches the end. + */ +struct menu *menu_next(struct menu *menu, struct menu *root) +{ + if (menu->list) + return menu->list; + + while (menu != root && !menu->next) + menu = menu->parent; + + if (menu == root) + return NULL; + + return menu->next; +} + void menu_warn(struct menu *menu, const char *fmt, ...) { va_list ap; From patchwork Sun Apr 21 09:02:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13637310 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 7D87710940; Sun, 21 Apr 2024 09:03:00 +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=1713690180; cv=none; b=Ckjbwrg4NBD1X0pyrlwvmPVpM1kEZDxwKsCf3Zv8uuaWpakOMkWkQ/T+rAVWcZ+tE0CbFhpRGjz/F3tjyDy6eO5KQqg10LsUbHaVGatz4yWWEIJkkxZHPfUl26wbgMngoSVXPzFAA2cOYrjOyt4BBSaX1WzNEmeRuP4LOiJ8Gu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713690180; c=relaxed/simple; bh=sMkrcyPFZTw4unEKDwixdGVUFlnihGpjujBV9mFCGbQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Iffr2votfDW/asOLnjk3jeMaeAAKjyyDSoh+LxdrI4SEdwGNrGbXaweyJeVGYNI56vWQqTr1SeVhbDPd8aywRBWwhf/XkIzbu34BQUPC7dxbxVlS05NnVtnXoOWbUDOnuTQ0FrWZw0cilD3hspwDiw4JZ0pUCsDlxv69C4TQB1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n4JmH+p8; 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="n4JmH+p8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC01AC32782; Sun, 21 Apr 2024 09:02:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713690179; bh=sMkrcyPFZTw4unEKDwixdGVUFlnihGpjujBV9mFCGbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n4JmH+p8TO6KXue3YwPkzv9oVhTcp8QLZPr0YdFT9HSAeFaAqun3T/ys3uMpL90tH Mwic9NsnkVnK8pQjfCcw6ouKToQ1f+lyAbnI6UouxXBvGptwKh25aHzyV6QQxmhY7x sslV/4kjAlqGDL8gKJa1EnS+VYUCrRjbsm6s22ICTvnyRNL1bIX/qL6wqc0a8ymgAn av0wFNoslOAcawwrAu4N5OV5svRiwusiouJNiHUVYNMebUfBVloDdhtl2ye3yiEwkA 0wXYQOOdqQ6Ng1nTKKZpLpCAEkPkQD3D2+Oyz0c+ZPC2sGmc6Z15nCJF5n74ZoG3/V n7WxrhpYdWrQA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 2/2] kconfig: use menu_for_each_entry() to traverse menu tree Date: Sun, 21 Apr 2024 18:02:52 +0900 Message-Id: <20240421090252.2700867-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240421090252.2700867-1-masahiroy@kernel.org> References: <20240421090252.2700867-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 | 28 +++++----------------------- scripts/kconfig/parser.y | 13 +------------ 2 files changed, 6 insertions(+), 35 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 0e35c4819cf1..ce0ef417b71b 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -793,23 +793,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 +823,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 7fb996612c96..8f339b47fe8d 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -517,20 +517,9 @@ void conf_parse(const char *name) menu_finalize(); - 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)