[U-Boot] [PATCH v3 31/40] env: Drop the ENTRY typedef

Simon Glass sjg at chromium.org
Fri Aug 2 15:44:18 UTC 2019


U-Boot is not supposed to use typedef for structs anymore. Also this name
is the same as the ENTRY() macro used in assembler files, and 'entry'
itself is widely used in U-Boot (>8k matches).

Drop the typedef and rename the struct to env_entry to reduce confusion.

Signed-off-by: Simon Glass <sjg at chromium.org>
Acked-by: Joe Hershberger <joe.hershberger at ni.com>
---

Changes in v3:
- Move removal of _ENTRY to next patch

Changes in v2:
- Fix typdef typo

 api/api.c              |  2 +-
 cmd/nvedit.c           | 12 +++++------
 drivers/tee/sandbox.c  |  2 +-
 env/callback.c         |  6 +++---
 env/common.c           |  2 +-
 env/flags.c            | 10 +++++-----
 include/env_callback.h |  2 +-
 include/env_flags.h    |  6 +++---
 include/search.h       | 21 +++++++++++---------
 lib/hashtable.c        | 45 +++++++++++++++++++++---------------------
 test/env/hashtable.c   | 12 +++++------
 11 files changed, 62 insertions(+), 58 deletions(-)

diff --git a/api/api.c b/api/api.c
index 8a41b7cce7..a0fc62ca9e 100644
--- a/api/api.c
+++ b/api/api.c
@@ -497,7 +497,7 @@ static int API_env_enum(va_list ap)
 {
 	int i, buflen;
 	char *last, **next, *s;
-	ENTRY *match, search;
+	struct env_entry *match, search;
 	static char *var;
 
 	last = (char *)va_arg(ap, unsigned long);
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index acbe85b8e4..39140c0733 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -94,7 +94,7 @@ static int env_print(char *name, int flag)
 	ssize_t len;
 
 	if (name) {		/* print a single name */
-		ENTRY e, *ep;
+		struct env_entry e, *ep;
 
 		e.key = name;
 		e.data = NULL;
@@ -225,7 +225,7 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
 {
 	int   i, len;
 	char  *name, *value, *s;
-	ENTRY e, *ep;
+	struct env_entry e, *ep;
 
 	debug("Initial value for argc=%d\n", argc);
 
@@ -473,7 +473,7 @@ static int print_static_binding(const char *var_name, const char *callback_name,
 	return 0;
 }
 
-static int print_active_callback(ENTRY *entry)
+static int print_active_callback(struct env_entry *entry)
 {
 	struct env_clbk_tbl *clbkp;
 	int i;
@@ -554,7 +554,7 @@ static int print_static_flags(const char *var_name, const char *flags,
 	return 0;
 }
 
-static int print_active_flags(ENTRY *entry)
+static int print_active_flags(struct env_entry *entry)
 {
 	enum env_flags_vartype type;
 	enum env_flags_varaccess access;
@@ -662,7 +662,7 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
 char *env_get(const char *name)
 {
 	if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
-		ENTRY e, *ep;
+		struct env_entry e, *ep;
 
 		WATCHDOG_RESET();
 
@@ -1262,7 +1262,7 @@ static int do_env_info(cmd_tbl_t *cmdtp, int flag,
 static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
-	ENTRY e, *ep;
+	struct env_entry e, *ep;
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
diff --git a/drivers/tee/sandbox.c b/drivers/tee/sandbox.c
index 2f3355c7b7..4bbcf74967 100644
--- a/drivers/tee/sandbox.c
+++ b/drivers/tee/sandbox.c
@@ -79,7 +79,7 @@ static u32 ta_avb_invoke_func(struct udevice *dev, u32 func, uint num_params,
 			      struct tee_param *params)
 {
 	struct sandbox_tee_state *state = dev_get_priv(dev);
-	ENTRY e, *ep;
+	struct env_entry e, *ep;
 	char *name;
 	u32 res;
 	uint slot;
diff --git a/env/callback.c b/env/callback.c
index 95be80d454..d539da93aa 100644
--- a/env/callback.c
+++ b/env/callback.c
@@ -43,7 +43,7 @@ static const char *callback_list;
  * This is called specifically when the variable did not exist in the hash
  * previously, so the blanket update did not find this variable.
  */
-void env_callback_init(ENTRY *var_entry)
+void env_callback_init(struct env_entry *var_entry)
 {
 	const char *var_name = var_entry->key;
 	char callback_name[256] = "";
@@ -80,7 +80,7 @@ void env_callback_init(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(ENTRY *entry)
+static int clear_callback(struct env_entry *entry)
 {
 	entry->callback = NULL;
 
@@ -92,7 +92,7 @@ static int clear_callback(ENTRY *entry)
  */
 static int set_callback(const char *name, const char *value, void *priv)
 {
-	ENTRY e, *ep;
+	struct env_entry e, *ep;
 	struct env_clbk_tbl *clbkp;
 
 	e.key	= name;
diff --git a/env/common.c b/env/common.c
index 1d9d0f934d..474ea2280b 100644
--- a/env/common.c
+++ b/env/common.c
@@ -250,7 +250,7 @@ void env_relocate(void)
 int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf,
 		 bool dollar_comp)
 {
-	ENTRY *match;
+	struct env_entry *match;
 	int found, idx;
 
 	if (dollar_comp) {
diff --git a/env/flags.c b/env/flags.c
index 7277711594..fdbad7bf33 100644
--- a/env/flags.c
+++ b/env/flags.c
@@ -419,7 +419,7 @@ static const char *flags_list;
  * This is called specifically when the variable did not exist in the hash
  * previously, so the blanket update did not find this variable.
  */
-void env_flags_init(ENTRY *var_entry)
+void env_flags_init(struct env_entry *var_entry)
 {
 	const char *var_name = var_entry->key;
 	char flags[ENV_FLAGS_ATTR_MAX_LEN + 1] = "";
@@ -441,7 +441,7 @@ void env_flags_init(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(ENTRY *entry)
+static int clear_flags(struct env_entry *entry)
 {
 	entry->flags = 0;
 
@@ -453,7 +453,7 @@ static int clear_flags(ENTRY *entry)
  */
 static int set_flags(const char *name, const char *value, void *priv)
 {
-	ENTRY e, *ep;
+	struct env_entry e, *ep;
 
 	e.key	= name;
 	e.data	= NULL;
@@ -496,8 +496,8 @@ U_BOOT_ENV_CALLBACK(flags, on_flags);
  * overwriting of write-once variables.
  */
 
-int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
-	int flag)
+int env_flags_validate(const struct env_entry *item, const char *newval,
+		       enum env_op op, int flag)
 {
 	const char *name;
 	const char *oldval = NULL;
diff --git a/include/env_callback.h b/include/env_callback.h
index 3d30a33f5b..982c07854d 100644
--- a/include/env_callback.h
+++ b/include/env_callback.h
@@ -72,6 +72,6 @@
 	"serial#:serialno," \
 	CONFIG_ENV_CALLBACK_LIST_STATIC
 
-void env_callback_init(ENTRY *var_entry);
+void env_callback_init(struct env_entry *var_entry);
 
 #endif /* __ENV_CALLBACK_H__ */
diff --git a/include/env_flags.h b/include/env_flags.h
index f2306436b4..e5380f2948 100644
--- a/include/env_flags.h
+++ b/include/env_flags.h
@@ -153,13 +153,13 @@ int env_flags_validate_env_set_params(char *name, char *const val[], int count);
  * When adding a variable to the environment, initialize the flags for that
  * variable.
  */
-void env_flags_init(ENTRY *var_entry);
+void env_flags_init(struct env_entry *var_entry);
 
 /*
  * Validate the newval for to conform with the requirements defined by its flags
  */
-int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
-	int flag);
+int env_flags_validate(const struct env_entry *item, const char *newval,
+		       enum env_op op, int flag);
 
 #endif /* USE_HOSTCC */
 
diff --git a/include/search.h b/include/search.h
index f9fb29fdf9..81745a917d 100644
--- a/include/search.h
+++ b/include/search.h
@@ -25,13 +25,14 @@ typedef enum {
 	ENTER
 } ACTION;
 
-typedef struct entry {
+/** struct env_entry - An entry in the environment hashtable */
+struct env_entry {
 	const char *key;
 	char *data;
 	int (*callback)(const char *name, const char *value, enum env_op op,
 		int flags);
 	int flags;
-} ENTRY;
+};
 
 /* Opaque type for internal use.  */
 struct _ENTRY;
@@ -54,8 +55,8 @@ struct hsearch_data {
  * shall force overwriting of write-once variables.
  * Must return 0 for approval, 1 for denial.
  */
-	int (*change_ok)(const ENTRY *__item, const char *newval, enum env_op,
-		int flag);
+	int (*change_ok)(const struct env_entry *__item, const char *newval,
+			 enum env_op, int flag);
 };
 
 /* Create a new hash table which will contain at most "__nel" elements.  */
@@ -70,15 +71,16 @@ extern void hdestroy_r(struct hsearch_data *__htab);
  * NULL.  If ACTION is `ENTER' replace existing data (if any) with
  * __item.data.
  * */
-extern int hsearch_r(ENTRY __item, ACTION __action, ENTRY ** __retval,
-		     struct hsearch_data *__htab, int __flag);
+extern int hsearch_r(struct env_entry __item, ACTION __action,
+		     struct env_entry **__retval, struct hsearch_data *__htab,
+		     int __flag);
 
 /*
  * Search for an entry matching "__match".  Otherwise, Same semantics
  * as hsearch_r().
  */
-extern int hmatch_r(const char *__match, int __last_idx, ENTRY ** __retval,
-		    struct hsearch_data *__htab);
+extern int hmatch_r(const char *__match, int __last_idx,
+		    struct env_entry **__retval, struct hsearch_data *__htab);
 
 /* Search and delete entry matching "__key" in internal hash table. */
 extern int hdelete_r(const char *__key, struct hsearch_data *__htab,
@@ -98,7 +100,8 @@ extern int himport_r(struct hsearch_data *__htab,
 		     char * const vars[]);
 
 /* Walk the whole table calling the callback on each element */
-extern int hwalk_r(struct hsearch_data *__htab, int (*callback)(ENTRY *));
+extern int hwalk_r(struct hsearch_data *__htab,
+		   int (*callback)(struct env_entry *entry));
 
 /* 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 0d288d12d9..c77b68f4e6 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -61,12 +61,12 @@
 
 typedef struct _ENTRY {
 	int used;
-	ENTRY entry;
+	struct env_entry entry;
 } _ENTRY;
 
 
-static void _hdelete(const char *key, struct hsearch_data *htab, ENTRY *ep,
-	int idx);
+static void _hdelete(const char *key, struct hsearch_data *htab,
+		     struct env_entry *ep, int idx);
 
 /*
  * hcreate()
@@ -151,7 +151,7 @@ void hdestroy_r(struct hsearch_data *htab)
 	/* free used memory */
 	for (i = 1; i <= htab->size; ++i) {
 		if (htab->table[i].used > 0) {
-			ENTRY *ep = &htab->table[i].entry;
+			struct env_entry *ep = &htab->table[i].entry;
 
 			free((void *)ep->key);
 			free(ep->data);
@@ -200,7 +200,7 @@ void hdestroy_r(struct hsearch_data *htab)
  *   example for functions like hdelete().
  */
 
-int hmatch_r(const char *match, int last_idx, ENTRY ** retval,
+int hmatch_r(const char *match, int last_idx, struct env_entry **retval,
 	     struct hsearch_data *htab)
 {
 	unsigned int idx;
@@ -224,9 +224,10 @@ int hmatch_r(const char *match, int last_idx, ENTRY ** retval,
  * Compare an existing entry with the desired key, and overwrite if the action
  * is ENTER.  This is simply a helper function for hsearch_r().
  */
-static inline int _compare_and_overwrite_entry(ENTRY item, ACTION action,
-	ENTRY **retval, struct hsearch_data *htab, int flag,
-	unsigned int hval, unsigned int idx)
+static inline int _compare_and_overwrite_entry(struct env_entry item,
+		ACTION action, struct env_entry **retval,
+		struct hsearch_data *htab, int flag, unsigned int hval,
+		unsigned int idx)
 {
 	if (htab->table[idx].used == hval
 	    && strcmp(item.key, htab->table[idx].entry.key) == 0) {
@@ -270,7 +271,7 @@ static inline int _compare_and_overwrite_entry(ENTRY item, ACTION action,
 	return -1;
 }
 
-int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval,
+int hsearch_r(struct env_entry item, ACTION action, struct env_entry **retval,
 	      struct hsearch_data *htab, int flag)
 {
 	unsigned int hval;
@@ -431,10 +432,10 @@ int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval,
  * do that.
  */
 
-static void _hdelete(const char *key, struct hsearch_data *htab, ENTRY *ep,
-	int idx)
+static void _hdelete(const char *key, struct hsearch_data *htab,
+		     struct env_entry *ep, int idx)
 {
-	/* free used ENTRY */
+	/* free used entry */
 	debug("hdelete: DELETING key \"%s\"\n", key);
 	free((void *)ep->key);
 	free(ep->data);
@@ -447,7 +448,7 @@ static void _hdelete(const char *key, struct hsearch_data *htab, ENTRY *ep,
 
 int hdelete_r(const char *key, struct hsearch_data *htab, int flag)
 {
-	ENTRY e, *ep;
+	struct env_entry e, *ep;
 	int idx;
 
 	debug("hdelete: DELETE key \"%s\"\n", key);
@@ -528,8 +529,8 @@ int hdelete_r(const char *key, struct hsearch_data *htab, int flag)
 
 static int cmpkey(const void *p1, const void *p2)
 {
-	ENTRY *e1 = *(ENTRY **) p1;
-	ENTRY *e2 = *(ENTRY **) p2;
+	struct env_entry *e1 = *(struct env_entry **)p1;
+	struct env_entry *e2 = *(struct env_entry **)p2;
 
 	return (strcmp(e1->key, e2->key));
 }
@@ -563,8 +564,8 @@ static int match_string(int flag, const char *str, const char *pat, void *priv)
 	return 0;
 }
 
-static int match_entry(ENTRY *ep, int flag,
-		 int argc, char * const argv[])
+static int match_entry(struct env_entry *ep, int flag, int argc,
+		       char *const argv[])
 {
 	int arg;
 	void *priv = NULL;
@@ -596,7 +597,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
 		 char **resp, size_t size,
 		 int argc, char * const argv[])
 {
-	ENTRY *list[htab->size];
+	struct env_entry *list[htab->size];
 	char *res, *p;
 	size_t totlen;
 	int i, n;
@@ -617,7 +618,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
 	for (i = 1, n = 0, totlen = 0; i <= htab->size; ++i) {
 
 		if (htab->table[i].used > 0) {
-			ENTRY *ep = &htab->table[i].entry;
+			struct env_entry *ep = &htab->table[i].entry;
 			int found = match_entry(ep, flag, argc, argv);
 
 			if ((argc > 0) && (found == 0))
@@ -657,7 +658,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
 #endif
 
 	/* Sort list by keys */
-	qsort(list, n, sizeof(ENTRY *), cmpkey);
+	qsort(list, n, sizeof(struct env_entry *), cmpkey);
 
 	/* Check if the user supplied buffer size is sufficient */
 	if (size) {
@@ -869,7 +870,7 @@ int himport_r(struct hsearch_data *htab,
 	}
 	/* Parse environment; allow for '\0' and 'sep' as separators */
 	do {
-		ENTRY e, *rv;
+		struct env_entry e, *rv;
 
 		/* skip leading white space */
 		while (isblank(*dp))
@@ -976,7 +977,7 @@ 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)(ENTRY *))
+int hwalk_r(struct hsearch_data *htab, int (*callback)(struct env_entry *entry))
 {
 	int i;
 	int retval;
diff --git a/test/env/hashtable.c b/test/env/hashtable.c
index 8c87e65457..bad276bd10 100644
--- a/test/env/hashtable.c
+++ b/test/env/hashtable.c
@@ -18,8 +18,8 @@ static int htab_fill(struct unit_test_state *uts,
 		     struct hsearch_data *htab, size_t size)
 {
 	size_t i;
-	ENTRY item;
-	ENTRY *ritem;
+	struct env_entry item;
+	struct env_entry *ritem;
 	char key[20];
 
 	for (i = 0; i < size; i++) {
@@ -38,8 +38,8 @@ static int htab_check_fill(struct unit_test_state *uts,
 			   struct hsearch_data *htab, size_t size)
 {
 	size_t i;
-	ENTRY item;
-	ENTRY *ritem;
+	struct env_entry item;
+	struct env_entry *ritem;
 	char key[20];
 
 	for (i = 0; i < size; i++) {
@@ -61,8 +61,8 @@ static int htab_create_delete(struct unit_test_state *uts,
 			      struct hsearch_data *htab, size_t iterations)
 {
 	size_t i;
-	ENTRY item;
-	ENTRY *ritem;
+	struct env_entry item;
+	struct env_entry *ritem;
 	char key[20];
 
 	for (i = 0; i < iterations; i++) {
-- 
2.22.0.770.g0f2c4a37fd-goog



More information about the U-Boot mailing list