Skip to contentSkip to conversation

kconfig: factor out common code shared by mconf and nconf

PATCH New Masahiro Yamada 1 participant 6 messages Dec 3, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/6 kconfig: factor out common code shared by mconf and nconf

Separate out the duplicated code to mnconf-common.c.

---

 scripts/kconfig/Makefile        |  4 +--
 scripts/kconfig/mconf.c         | 54 +--------------------------------
 scripts/kconfig/mnconf-common.c | 53 ++++++++++++++++++++++++++++++++
 scripts/kconfig/mnconf-common.h | 18 +++++++++++
 scripts/kconfig/nconf.c         | 53 +-------------------------------
 5 files changed, 75 insertions(+), 107 deletions(-)
 create mode 100644 scripts/kconfig/mnconf-common.c
 create mode 100644 scripts/kconfig/mnconf-common.h
scripts/kconfig/Makefile +2 -2
index 322c061b464d..7c025f82718e 100644
@@ -174,7 +174,7 @@ conf-objs	:= conf.o $(common-objs)
 
 # nconf: Used for the nconfig target based on ncurses
 hostprogs	+= nconf
-nconf-objs	:= nconf.o nconf.gui.o $(common-objs)
+nconf-objs	:= nconf.o nconf.gui.o mnconf-common.o $(common-objs)
 
 HOSTLDLIBS_nconf       = $(call read-file, $(obj)/nconf-libs)
 HOSTCFLAGS_nconf.o     = $(call read-file, $(obj)/nconf-cflags)
@@ -187,7 +187,7 @@ $(obj)/nconf.o $(obj)/nconf.gui.o: | $(obj)/nconf-cflags
 hostprogs	+= mconf
 lxdialog	:= $(addprefix lxdialog/, \
 		     checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
-mconf-objs	:= mconf.o $(lxdialog) $(common-objs)
+mconf-objs	:= mconf.o $(lxdialog) mnconf-common.o $(common-objs)
 
 HOSTLDLIBS_mconf = $(call read-file, $(obj)/mconf-libs)
 $(foreach f, mconf.o $(lxdialog), \
scripts/kconfig/mconf.c +1 -53

72 lines not on this page · raw message

scripts/kconfig/mnconf-common.c new file +53 -0

53 lines not on this page · raw message

scripts/kconfig/mnconf-common.h new file +18 -0
new file mode 100644
index 000000000000..ab6292cc4bf2
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef MNCONF_COMMON_H
+#define MNCONF_COMMON_H
+
+#include <stddef.h>
+
+struct search_data {
+	struct list_head *head;
+	struct menu *target;
+};
+
+extern int jump_key_char;
+
+int next_jump_key(int key);
+int handle_search_keys(int key, size_t start, size_t end, void *_data);
+int get_jump_key_char(void);
+
+#endif /* MNCONF_COMMON_H */
scripts/kconfig/nconf.c +1 -52

71 lines not on this page · raw message

Signature · 1 line
2.40.1
#1 lore raw

PATCH 2/6 kconfig: make menu_warn() static function

This function is only used locally within menu.c.

---

 scripts/kconfig/lkc.h  | 1 -
 scripts/kconfig/menu.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
scripts/kconfig/lkc.h +0 -1
index 471a59acecec..3908741edf8f 100644
@@ -80,7 +80,6 @@ char *str_get(struct gstr *gs);
 
 /* menu.c */
 void _menu_init(void);
-void menu_warn(struct menu *menu, const char *fmt, ...);
 struct menu *menu_add_menu(void);
 void menu_end_menu(void);
 void menu_add_entry(struct symbol *sym);
scripts/kconfig/menu.c +1 -1
index 61c442d84aef..f07c0d8691af 100644
@@ -19,7 +19,7 @@ static struct menu **last_entry_ptr;
 struct file *file_list;
 struct file *current_file;
 
-void menu_warn(struct menu *menu, const char *fmt, ...)
+static void menu_warn(struct menu *menu, const char *fmt, ...)
 {
 	va_list ap;
 	va_start(ap, fmt);
Signature · 1 line
2.40.1
#2 lore raw

PATCH 3/6 kconfig: squash menu_has_help() and menu_get_help()

In reply to Masahiro Yamada

menu_has_help() and menu_get_help() functions are only used within menu_get_ext_help().

Squash them into menu_get_ext_help(). It revealed the if-conditional in menu_get_help() was unneeded, as menu_has_help() has already checked that menu->help is not NULL.

---

 scripts/kconfig/lkc.h  |  2 --
 scripts/kconfig/menu.c | 17 ++---------------
 2 files changed, 2 insertions(+), 17 deletions(-)
scripts/kconfig/lkc.h +0 -2
index 3908741edf8f..8ca5bbc74df1 100644
@@ -98,8 +98,6 @@ bool menu_is_visible(struct menu *menu);
 bool menu_has_prompt(struct menu *menu);
 const char *menu_get_prompt(struct menu *menu);
 struct menu *menu_get_parent_menu(struct menu *menu);
-bool menu_has_help(struct menu *menu);
-const char *menu_get_help(struct menu *menu);
 int get_jump_key_char(void);
 struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head);
 void menu_get_ext_help(struct menu *menu, struct gstr *help);
scripts/kconfig/menu.c +2 -15
index f07c0d8691af..dc60a9ddc5dd 100644
@@ -673,19 +673,6 @@ struct menu *menu_get_parent_menu(struct menu *menu)
 	return menu;
 }
 
-bool menu_has_help(struct menu *menu)
-{
-	return menu->help != NULL;
-}
-
-const char *menu_get_help(struct menu *menu)
-{
-	if (menu->help)
-		return menu->help;
-	else
-		return "";
-}
-
 static void get_def_str(struct gstr *r, struct menu *menu)
 {
 	str_printf(r, "Defined at %s:%d\n",
@@ -856,10 +843,10 @@ void menu_get_ext_help(struct menu *menu, struct gstr *help)
 	struct symbol *sym = menu->sym;
 	const char *help_text = nohelp_text;
 
-	if (menu_has_help(menu)) {
+	if (menu->help) {
 		if (sym->name)
 			str_printf(help, "%s%s:\n\n", CONFIG_, sym->name);
-		help_text = menu_get_help(menu);
+		help_text = menu->help;
 	}
 	str_printf(help, "%s\n", help_text);
 	if (sym)
Signature · 1 line
2.40.1
#3 lore raw

PATCH 4/6 kconfig: add include guard to lkc_proto.h

In reply to Masahiro Yamada

---

 scripts/kconfig/lkc_proto.h | 5 +++++
 1 file changed, 5 insertions(+)
scripts/kconfig/lkc_proto.h +5 -0
index edd1e617b25c..687d8698d801 100644
@@ -1,4 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+#ifndef LKC_PROTO_H
+#define LKC_PROTO_H
+
 #include <stdarg.h>
 
 /* confdata.c */
@@ -50,3 +53,5 @@ char *expand_one_token(const char **str);
 
 /* expr.c */
 void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken);
+
+#endif /* LKC_PROTO_H */
Signature · 1 line
2.40.1
#4 lore raw

PATCH 5/6 kconfig: remove unreachable printf()

In reply to Masahiro Yamada

Remove the unreachable code detected by clang.

  $ make HOSTCC=clang HOSTCFLAGS=-Wunreachable-code defconfig
    [ snip ]
  scripts/kconfig/expr.c:1134:2: warning: code will never be executed [-Wunreachable-code]
          printf("[%dgt%d?]", t1, t2);
          ^~~~~~
  1 warning generated.

---

 scripts/kconfig/expr.c | 1 -
 1 file changed, 1 deletion(-)
scripts/kconfig/expr.c +0 -1
index 81ebf8108ca7..a290de36307b 100644
@@ -1131,7 +1131,6 @@ static int expr_compare_type(enum expr_type t1, enum expr_type t2)
 	default:
 		return -1;
 	}
-	printf("[%dgt%d?]", t1, t2);
 	return 0;
 }
 
Signature · 1 line
2.40.1
#5 lore raw

PATCH 6/6 kconfig: remove redundant NULL pointer check before free()

In reply to Masahiro Yamada

Passing NULL to free() is allowed and is a no-op.

Remove redundant NULL pointer checks.

---

 scripts/kconfig/confdata.c | 3 +--
 scripts/kconfig/util.c     | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
scripts/kconfig/confdata.c +1 -2
index bd14aae1db58..f1197e672431 100644
@@ -432,8 +432,7 @@ int conf_read_simple(const char *name, int def)
 		case S_INT:
 		case S_HEX:
 		case S_STRING:
-			if (sym->def[def].val)
-				free(sym->def[def].val);
+			free(sym->def[def].val);
 			/* fall through */
 		default:
 			sym->def[def].val = NULL;
scripts/kconfig/util.c +1 -2
index b78f114ad48c..92e5b2b9761d 100644
@@ -42,8 +42,7 @@ struct gstr str_new(void)
 /* Free storage for growable string */
 void str_free(struct gstr *gs)
 {
-	if (gs->s)
-		free(gs->s);
+	free(gs->s);
 	gs->s = NULL;
 	gs->len = 0;
 }
Signature · 1 line
2.40.1