Skip to content

Commit

Permalink
env: Drop the ENTRY typedef
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Joe Hershberger <[email protected]>
  • Loading branch information
sjg20 authored and trini committed Aug 11, 2019
1 parent 02cf933 commit dd2408c
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 58 deletions.
2 changes: 1 addition & 1 deletion api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions cmd/nvedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/tee/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions env/callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] = "";
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion env/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions env/flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] = "";
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/env_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
6 changes: 3 additions & 3 deletions include/env_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
21 changes: 12 additions & 9 deletions include/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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. */
Expand All @@ -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,
Expand All @@ -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 */
Expand Down
45 changes: 23 additions & 22 deletions lib/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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))
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -976,7 +977,7 @@ int himport_r(struct hsearch_data *htab,
* 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;
Expand Down
Loading

0 comments on commit dd2408c

Please sign in to comment.