Skip to contentSkip to conversation

kconfig: remove unneeded code for user-supplied values being out of range

PATCH New Masahiro Yamada 1 participant 6 messages Jun 1, 2024

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

PATCH 1/6 kconfig: remove unneeded code for user-supplied values being out of range

This is a leftover from commit ce1fc9345a59 ("kconfig: do not clear SYMBOL_DEF_USER when the value is out of range").

This code is now redundant because if a user-supplied value is out of range, the value adjusted by sym_validate_range() differs, and conf_unsaved has already been incremented a few lines above.

---

 scripts/kconfig/confdata.c | 13 -------------
 1 file changed, 13 deletions(-)
scripts/kconfig/confdata.c +0 -13
index 387503daf0f7..85b53069ba7a 100644
@@ -533,19 +533,6 @@ int conf_read(const char *name)
 			 */
 			if (sym->visible == no && !conf_unsaved)
 				sym->flags &= ~SYMBOL_DEF_USER;
-			switch (sym->type) {
-			case S_STRING:
-			case S_INT:
-			case S_HEX:
-				/* Reset a string value if it's out of range */
-				if (sym_string_within_range(sym, sym->def[S_DEF_USER].val))
-					break;
-				sym->flags &= ~SYMBOL_VALID;
-				conf_unsaved++;
-				break;
-			default:
-				break;
-			}
 		}
 	}
 
Signature · 1 line
2.40.1
#1 lore raw

PATCH 2/6 kconfig: qconf: remove initial call to conf_changed()

If any CONFIG option is changed while loading the .config file, conf_read() calls conf_set_changed(true) and then the conf_changed() callback.

With conf_read() moved after window initialization, the explicit conf_changed() call can be removed.

---

 scripts/kconfig/qconf.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/kconfig/qconf.cc +3 -3
index c6c42c0f4e5d..e62e862ea283 100644
@@ -1397,8 +1397,6 @@ ConfigMainWindow::ConfigMainWindow(void)
 
 	conf_set_changed_callback(conf_changed);
 
-	// Set saveAction's initial state
-	conf_changed();
 	configname = xstrdup(conf_get_configname());
 
 	QAction *saveAsAction = new QAction("Save &As...", this);
@@ -1904,7 +1902,6 @@ int main(int ac, char** av)
 
 	conf_parse(name);
 	fixup_rootmenu(&rootmenu);
-	conf_read(NULL);
 	//zconfdump(stdout);
 
 	configApp = new QApplication(ac, av);
@@ -1916,6 +1913,9 @@ int main(int ac, char** av)
 	//zconfdump(stdout);
 	configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
 	configApp->connect(configApp, SIGNAL(aboutToQuit()), v, SLOT(saveSettings()));
+
+	conf_read(NULL);
+
 	v->show();
 	configApp->exec();
 
Signature · 1 line
2.40.1
#2 lore raw

PATCH 3/6 kconfig: gconf: give a proper initial state to the Save button

In reply to Masahiro Yamada

Currently, the initial state of the "Save" button is always active.

If none of the CONFIG options are changed while loading the .config file, the "Save" button should be greyed out.

This can be fixed by calling conf_read() after widget initialization.

---

 scripts/kconfig/gconf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/gconf.c +2 -1
index cc400ffe6615..e04dbafd3add 100644
@@ -1422,7 +1422,6 @@ int main(int ac, char *av[])
 
 	conf_parse(name);
 	fixup_rootmenu(&rootmenu);
-	conf_read(NULL);
 
 	/* Load the interface and connect signals */
 	init_main_window(glade_file);
@@ -1430,6 +1429,8 @@ int main(int ac, char *av[])
 	init_left_tree();
 	init_right_tree();
 
+	conf_read(NULL);
+
 	switch (view_mode) {
 	case SINGLE_VIEW:
 		display_tree_part();
Signature · 1 line
2.40.1
#3 lore raw

PATCH 4/6 kconfig: gconf: remove unnecessary forward declarations

In reply to Masahiro Yamada

These are defined before their call sites.

---

 scripts/kconfig/gconf.c | 2 --
 1 file changed, 2 deletions(-)
scripts/kconfig/gconf.c +0 -2
index e04dbafd3add..3dc459d9840c 100644
@@ -65,8 +65,6 @@ static void display_list(void);
 static void display_tree(struct menu *menu);
 static void display_tree_part(void);
 static void update_tree(struct menu *src, GtkTreeIter * dst);
-static void set_node(GtkTreeIter * node, struct menu *menu, gchar ** row);
-static gchar **fill_row(struct menu *menu);
 static void conf_changed(void);
 
 static void replace_button_icon(GladeXML *xml, GdkDrawable *window,
Signature · 1 line
2.40.1
#4 lore raw

PATCH 5/6 kconfig: gconf: move conf_changed() definition up

In reply to Masahiro Yamada

Define conf_changed() before its call site to remove the forward declaration.

---

 scripts/kconfig/gconf.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
scripts/kconfig/gconf.c +7 -8
index 3dc459d9840c..2bf74aee5eff 100644
@@ -65,7 +65,6 @@ static void display_list(void);
 static void display_tree(struct menu *menu);
 static void display_tree_part(void);
 static void update_tree(struct menu *src, GtkTreeIter * dst);
-static void conf_changed(void);
 
 static void replace_button_icon(GladeXML *xml, GdkDrawable *window,
 				GtkStyle *style, gchar *btn_name, gchar **xpm)
@@ -85,6 +84,13 @@ static void replace_button_icon(GladeXML *xml, GdkDrawable *window,
 	gtk_tool_button_set_icon_widget(button, image);
 }
 
+static void conf_changed(void)
+{
+	bool changed = conf_get_changed();
+	gtk_widget_set_sensitive(save_btn, changed);
+	gtk_widget_set_sensitive(save_menu_item, changed);
+}
+
 /* Main Window Initialization */
 static void init_main_window(const gchar *glade_file)
 {
@@ -1445,10 +1451,3 @@ int main(int ac, char *av[])
 
 	return 0;
 }
-
-static void conf_changed(void)
-{
-	bool changed = conf_get_changed();
-	gtk_widget_set_sensitive(save_btn, changed);
-	gtk_widget_set_sensitive(save_menu_item, changed);
-}
Signature · 1 line
2.40.1
#5 lore raw

PATCH 6/6 kconfig: pass new the conf_changed value to the callback

In reply to Masahiro Yamada

Commit ee06a3ef7e3c ("kconfig: Update config changed flag before calling callback") pointed out that conf_updated flag must be updated before calling the callback because it needs to know the new value.

If so, it makes sense to pass the new value to the callback.

---

 scripts/kconfig/confdata.c  | 10 ++++------
 scripts/kconfig/gconf.c     |  7 +++----
 scripts/kconfig/lkc_proto.h |  2 +-
 scripts/kconfig/qconf.cc    |  4 ++--
 scripts/kconfig/qconf.h     |  2 +-
 5 files changed, 11 insertions(+), 14 deletions(-)
scripts/kconfig/confdata.c +4 -6
index 85b53069ba7a..946185506380 100644
@@ -1141,16 +1141,14 @@ int conf_write_autoconf(int overwrite)
 }
 
 static bool conf_changed;
-static void (*conf_changed_callback)(void);
+static void (*conf_changed_callback)(bool);
 
 void conf_set_changed(bool val)
 {
-	bool changed = conf_changed != val;
+	if (conf_changed_callback && conf_changed != val)
+		conf_changed_callback(val);
 
 	conf_changed = val;
-
-	if (conf_changed_callback && changed)
-		conf_changed_callback();
 }
 
 bool conf_get_changed(void)
@@ -1158,7 +1156,7 @@ bool conf_get_changed(void)
 	return conf_changed;
 }
 
-void conf_set_changed_callback(void (*fn)(void))
+void conf_set_changed_callback(void (*fn)(bool))
 {
 	conf_changed_callback = fn;
 }
scripts/kconfig/gconf.c +3 -4
index 2bf74aee5eff..baa1c512de3c 100644
@@ -84,11 +84,10 @@ static void replace_button_icon(GladeXML *xml, GdkDrawable *window,
 	gtk_tool_button_set_icon_widget(button, image);
 }
 
-static void conf_changed(void)
+static void conf_changed(bool dirty)
 {
-	bool changed = conf_get_changed();
-	gtk_widget_set_sensitive(save_btn, changed);
-	gtk_widget_set_sensitive(save_menu_item, changed);
+	gtk_widget_set_sensitive(save_btn, dirty);
+	gtk_widget_set_sensitive(save_menu_item, dirty);
 }
 
 /* Main Window Initialization */
scripts/kconfig/lkc_proto.h +1 -1
index d76aaf4ea117..c663fd8b35d2 100644
@@ -13,7 +13,7 @@ int conf_write(const char *name);
 int conf_write_autoconf(int overwrite);
 void conf_set_changed(bool val);
 bool conf_get_changed(void);
-void conf_set_changed_callback(void (*fn)(void));
+void conf_set_changed_callback(void (*fn)(bool));
 void conf_set_message_callback(void (*fn)(const char *s));
 bool conf_errors(void);
 
scripts/kconfig/qconf.cc +2 -2
index e62e862ea283..03fa096074b4 100644
@@ -1849,10 +1849,10 @@ void ConfigMainWindow::saveSettings(void)
 	configSettings->writeSizes("/split2", split2->sizes());
 }
 
-void ConfigMainWindow::conf_changed(void)
+void ConfigMainWindow::conf_changed(bool dirty)
 {
 	if (saveAction)
-		saveAction->setEnabled(conf_get_changed());
+		saveAction->setEnabled(dirty);
 }
 
 void fixup_rootmenu(struct menu *menu)
scripts/kconfig/qconf.h +1 -1
index 78b0a1dfcd53..53373064d90a 100644
@@ -239,7 +239,7 @@ class ConfigMainWindow : public QMainWindow {
 
 	char *configname;
 	static QAction *saveAction;
-	static void conf_changed(void);
+	static void conf_changed(bool);
 public:
 	ConfigMainWindow(void);
 public slots:
Signature · 1 line
2.40.1