[RFC PATCH 22/28] env: Add a priv pointer to hwalk_r

Sean Anderson seanga2 at gmail.com
Thu Jul 1 08:16:05 CEST 2021


This allows callers of hwalk_r to pass data to their callback. This mirrors
e.g. env_attr_walk.

Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---

 cmd/nvedit.c     | 8 ++++----
 env/callback.c   | 4 ++--
 env/flags.c      | 4 ++--
 include/search.h | 2 +-
 lib/hashtable.c  | 5 +++--
 5 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index d14ba10cef..b855e502c0 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -481,7 +481,7 @@ static int print_static_binding(const char *var_name, const char *callback_name,
 	return 0;
 }
 
-static int print_active_callback(struct env_entry *entry)
+static int print_active_callback(struct env_entry *entry, void *priv)
 {
 	struct env_clbk_tbl *clbkp;
 	int i;
@@ -544,7 +544,7 @@ int do_env_callback(struct cmd_tbl *cmdtp, int flag, int argc,
 	puts("Active callback bindings:\n");
 	printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
 	printf("\t%-20s %-20s\n", "-------------", "-------------");
-	hwalk_r(&env_htab, print_active_callback);
+	hwalk_r(&env_htab, print_active_callback, NULL);
 	return 0;
 }
 #endif
@@ -563,7 +563,7 @@ static int print_static_flags(const char *var_name, const char *flags,
 	return 0;
 }
 
-static int print_active_flags(struct env_entry *entry)
+static int print_active_flags(struct env_entry *entry, void *priv)
 {
 	enum env_flags_vartype type;
 	enum env_flags_varaccess access;
@@ -617,7 +617,7 @@ int do_env_flags(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		"Variable Access");
 	printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
 		"---------------");
-	hwalk_r(&env_htab, print_active_flags);
+	hwalk_r(&env_htab, print_active_flags, NULL);
 	return 0;
 }
 #endif
diff --git a/env/callback.c b/env/callback.c
index 638a02b28f..47075acb92 100644
--- a/env/callback.c
+++ b/env/callback.c
@@ -83,7 +83,7 @@ void env_callback_init(struct env_entry *var_entry)
  * Called on each existing env var prior to the blanket update since removing
  * a callback association should remove its callback.
  */
-static int clear_callback(struct env_entry *entry)
+static int clear_callback(struct env_entry *entry, void *priv)
 {
 	entry->callback = NULL;
 
@@ -127,7 +127,7 @@ static int on_callbacks(const char *name, const char *value, enum env_op op,
 	int flags)
 {
 	/* remove all callbacks */
-	hwalk_r(&env_htab, clear_callback);
+	hwalk_r(&env_htab, clear_callback, NULL);
 
 	/* configure any static callback bindings */
 	env_attr_walk(ENV_CALLBACK_LIST_STATIC, set_callback, NULL);
diff --git a/env/flags.c b/env/flags.c
index e3e833c433..f2e36e3dd3 100644
--- a/env/flags.c
+++ b/env/flags.c
@@ -468,7 +468,7 @@ void env_flags_init(struct env_entry *var_entry)
  * Called on each existing env var prior to the blanket update since removing
  * a flag in the flag list should remove its flags.
  */
-static int clear_flags(struct env_entry *entry)
+static int clear_flags(struct env_entry *entry, void *priv)
 {
 	entry->flags = 0;
 
@@ -503,7 +503,7 @@ static int on_flags(const char *name, const char *value, enum env_op op,
 	int flags)
 {
 	/* remove all flags */
-	hwalk_r(&env_htab, clear_flags);
+	hwalk_r(&env_htab, clear_flags, NULL);
 
 	/* configure any static flags */
 	env_attr_walk(ENV_FLAGS_LIST_STATIC, set_flags, NULL);
diff --git a/include/search.h b/include/search.h
index d0bb44388e..4a0828fb8d 100644
--- a/include/search.h
+++ b/include/search.h
@@ -105,7 +105,7 @@ int himport_r(struct hsearch_data *htab, const char *env, size_t size,
 
 /* Walk the whole table calling the callback on each element */
 int hwalk_r(struct hsearch_data *htab,
-	    int (*callback)(struct env_entry *entry));
+	    int (*callback)(struct env_entry *entry, void *priv), void *priv);
 
 /* Flags for himport_r(), hexport_r(), hdelete_r(), and hsearch_r() */
 #define H_NOCLEAR	(1 << 0) /* do not clear hash table before importing */
diff --git a/lib/hashtable.c b/lib/hashtable.c
index ff5ff72639..425a880222 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -998,14 +998,15 @@ end:
  * Walk all of the entries in the hash, calling the callback for each one.
  * this allows some generic operation to be performed on each element.
  */
-int hwalk_r(struct hsearch_data *htab, int (*callback)(struct env_entry *entry))
+int hwalk_r(struct hsearch_data *htab,
+	    int (*callback)(struct env_entry *entry, void *priv), void *priv)
 {
 	int i;
 	int retval;
 
 	for (i = 1; i <= htab->size; ++i) {
 		if (htab->table[i].used > 0) {
-			retval = callback(&htab->table[i].entry);
+			retval = callback(&htab->table[i].entry, priv);
 			if (retval)
 				return retval;
 		}
-- 
2.32.0



More information about the U-Boot mailing list