Re: [U-Boot] [PATCH 33/39] env: Drop the ACTION typedef

2019-07-30 Thread Joe Hershberger
On Sun, Jul 28, 2019 at 9:22 AM Simon Glass  wrote:
>
> Avoid using a typedef here which is unnecessary. Add an 'env_' prefix to
> both the enum and its members to make it clear that these are related to
> the environment.
>
> Add an ENV prefix to these two flags so that it is clear what they relate
> too. Also move them to env.h since they are part of the public API. Use an

too -> to

> enum rather than a #define to tie them together.
>
> Signed-off-by: Simon Glass 
> ---
>
>  api/api.c |  2 +-
>  cmd/nvedit.c  |  8 
>  drivers/tee/sandbox.c |  6 +++---
>  env/callback.c|  2 +-
>  env/flags.c   |  2 +-
>  include/search.h  | 16 
>  lib/hashtable.c   | 18 +-
>  test/env/hashtable.c  |  8 
>  8 files changed, 31 insertions(+), 31 deletions(-)
>
> diff --git a/api/api.c b/api/api.c
> index a0fc62ca9e..5e7c8149bf 100644
> --- a/api/api.c
> +++ b/api/api.c
> @@ -514,7 +514,7 @@ static int API_env_enum(va_list ap)
> if (s != NULL)
> *s = 0;
> search.key = var;
> -   i = hsearch_r(search, FIND, , _htab, 0);
> +   i = hsearch_r(search, ENVA_FIND, , _htab, 0);
> if (i == 0) {
> i = API_EINVAL;
> goto done;
> diff --git a/cmd/nvedit.c b/cmd/nvedit.c
> index d6a86abb03..3d244951b0 100644
> --- a/cmd/nvedit.c
> +++ b/cmd/nvedit.c
> @@ -98,7 +98,7 @@ static int env_print(char *name, int flag)
>
> e.key = name;
> e.data = NULL;
> -   hsearch_r(e, FIND, , _htab, flag);
> +   hsearch_r(e, ENVA_FIND, , _htab, flag);
> if (ep == NULL)
> return 0;
> len = printf("%s=%s\n", ep->key, ep->data);
> @@ -288,7 +288,7 @@ static int _do_env_set(int flag, int argc, char * const 
> argv[], int env_flag)
>
> e.key   = name;
> e.data  = value;
> -   hsearch_r(e, ENTER, , _htab, env_flag);
> +   hsearch_r(e, ENVA_ENTER, , _htab, env_flag);
> free(value);
> if (!ep) {
> printf("## Error inserting \"%s\" variable, errno=%d\n",
> @@ -680,7 +680,7 @@ char *env_get(const char *name)
>
> e.key   = name;
> e.data  = NULL;
> -   hsearch_r(e, FIND, , _htab, 0);
> +   hsearch_r(e, ENVA_FIND, , _htab, 0);
>
> return ep ? ep->data : NULL;
> }
> @@ -1281,7 +1281,7 @@ static int do_env_exists(cmd_tbl_t *cmdtp, int flag, 
> int argc,
>
> e.key = argv[1];
> e.data = NULL;
> -   hsearch_r(e, FIND, , _htab, 0);
> +   hsearch_r(e, ENVA_FIND, , _htab, 0);
>
> return (ep == NULL) ? 1 : 0;
>  }
> diff --git a/drivers/tee/sandbox.c b/drivers/tee/sandbox.c
> index 4bbcf74967..0561957067 100644
> --- a/drivers/tee/sandbox.c
> +++ b/drivers/tee/sandbox.c
> @@ -174,7 +174,7 @@ static u32 ta_avb_invoke_func(struct udevice *dev, u32 
> func, uint num_params,
>
> e.key = name;
> e.data = NULL;
> -   hsearch_r(e, FIND, , >pstorage_htab, 0);
> +   hsearch_r(e, ENVA_FIND, , >pstorage_htab, 0);
> if (!ep)
> return TEE_ERROR_ITEM_NOT_FOUND;
>
> @@ -198,13 +198,13 @@ static u32 ta_avb_invoke_func(struct udevice *dev, u32 
> func, uint num_params,
>
> e.key = name;
> e.data = NULL;
> -   hsearch_r(e, FIND, , >pstorage_htab, 0);
> +   hsearch_r(e, ENVA_FIND, , >pstorage_htab, 0);
> if (ep)
> hdelete_r(e.key, >pstorage_htab, 0);
>
> e.key = name;
> e.data = value;
> -   hsearch_r(e, ENTER, , >pstorage_htab, 0);
> +   hsearch_r(e, ENVA_ENTER, , >pstorage_htab, 0);
> if (!ep)
> return TEE_ERROR_OUT_OF_MEMORY;
>
> diff --git a/env/callback.c b/env/callback.c
> index d539da93aa..9bfa744921 100644
> --- a/env/callback.c
> +++ b/env/callback.c
> @@ -98,7 +98,7 @@ static int set_callback(const char *name, const char 
> *value, void *priv)
> e.key   = name;
> e.data  = NULL;
> e.callback = NULL;
> -   hsearch_r(e, FIND, , _htab, 0);
> +   hsearch_r(e, ENVA_FIND, , _htab, 0);
>
> /* does the env variable actually exist? */
> if (ep != NULL) {
> diff --git a/env/flags.c b/env/flags.c
> index fdbad7bf33..388c2f184b 100644
> --- a/env/flags.c
> +++ b/env/flags.c
> @@ -458,7 +458,7 @@ static int set_flags(const char *name, const char *value, 
> void *priv)
> e.key   = name;
> e.data  = NULL;
> e.callback = NULL;
> -   hsearch_r(e, FIND, , _htab, 0);
> +   hsearch_r(e, ENVA_FIND, , _htab, 0);
>
> /* does the env variable actually exist? */
> if (ep != NULL) {
> diff --git a/include/search.h 

[U-Boot] [PATCH 33/39] env: Drop the ACTION typedef

2019-07-28 Thread Simon Glass
Avoid using a typedef here which is unnecessary. Add an 'env_' prefix to
both the enum and its members to make it clear that these are related to
the environment.

Add an ENV prefix to these two flags so that it is clear what they relate
too. Also move them to env.h since they are part of the public API. Use an
enum rather than a #define to tie them together.

Signed-off-by: Simon Glass 
---

 api/api.c |  2 +-
 cmd/nvedit.c  |  8 
 drivers/tee/sandbox.c |  6 +++---
 env/callback.c|  2 +-
 env/flags.c   |  2 +-
 include/search.h  | 16 
 lib/hashtable.c   | 18 +-
 test/env/hashtable.c  |  8 
 8 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/api/api.c b/api/api.c
index a0fc62ca9e..5e7c8149bf 100644
--- a/api/api.c
+++ b/api/api.c
@@ -514,7 +514,7 @@ static int API_env_enum(va_list ap)
if (s != NULL)
*s = 0;
search.key = var;
-   i = hsearch_r(search, FIND, , _htab, 0);
+   i = hsearch_r(search, ENVA_FIND, , _htab, 0);
if (i == 0) {
i = API_EINVAL;
goto done;
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index d6a86abb03..3d244951b0 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -98,7 +98,7 @@ static int env_print(char *name, int flag)
 
e.key = name;
e.data = NULL;
-   hsearch_r(e, FIND, , _htab, flag);
+   hsearch_r(e, ENVA_FIND, , _htab, flag);
if (ep == NULL)
return 0;
len = printf("%s=%s\n", ep->key, ep->data);
@@ -288,7 +288,7 @@ static int _do_env_set(int flag, int argc, char * const 
argv[], int env_flag)
 
e.key   = name;
e.data  = value;
-   hsearch_r(e, ENTER, , _htab, env_flag);
+   hsearch_r(e, ENVA_ENTER, , _htab, env_flag);
free(value);
if (!ep) {
printf("## Error inserting \"%s\" variable, errno=%d\n",
@@ -680,7 +680,7 @@ char *env_get(const char *name)
 
e.key   = name;
e.data  = NULL;
-   hsearch_r(e, FIND, , _htab, 0);
+   hsearch_r(e, ENVA_FIND, , _htab, 0);
 
return ep ? ep->data : NULL;
}
@@ -1281,7 +1281,7 @@ static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int 
argc,
 
e.key = argv[1];
e.data = NULL;
-   hsearch_r(e, FIND, , _htab, 0);
+   hsearch_r(e, ENVA_FIND, , _htab, 0);
 
return (ep == NULL) ? 1 : 0;
 }
diff --git a/drivers/tee/sandbox.c b/drivers/tee/sandbox.c
index 4bbcf74967..0561957067 100644
--- a/drivers/tee/sandbox.c
+++ b/drivers/tee/sandbox.c
@@ -174,7 +174,7 @@ static u32 ta_avb_invoke_func(struct udevice *dev, u32 
func, uint num_params,
 
e.key = name;
e.data = NULL;
-   hsearch_r(e, FIND, , >pstorage_htab, 0);
+   hsearch_r(e, ENVA_FIND, , >pstorage_htab, 0);
if (!ep)
return TEE_ERROR_ITEM_NOT_FOUND;
 
@@ -198,13 +198,13 @@ static u32 ta_avb_invoke_func(struct udevice *dev, u32 
func, uint num_params,
 
e.key = name;
e.data = NULL;
-   hsearch_r(e, FIND, , >pstorage_htab, 0);
+   hsearch_r(e, ENVA_FIND, , >pstorage_htab, 0);
if (ep)
hdelete_r(e.key, >pstorage_htab, 0);
 
e.key = name;
e.data = value;
-   hsearch_r(e, ENTER, , >pstorage_htab, 0);
+   hsearch_r(e, ENVA_ENTER, , >pstorage_htab, 0);
if (!ep)
return TEE_ERROR_OUT_OF_MEMORY;
 
diff --git a/env/callback.c b/env/callback.c
index d539da93aa..9bfa744921 100644
--- a/env/callback.c
+++ b/env/callback.c
@@ -98,7 +98,7 @@ static int set_callback(const char *name, const char *value, 
void *priv)
e.key   = name;
e.data  = NULL;
e.callback = NULL;
-   hsearch_r(e, FIND, , _htab, 0);
+   hsearch_r(e, ENVA_FIND, , _htab, 0);
 
/* does the env variable actually exist? */
if (ep != NULL) {
diff --git a/env/flags.c b/env/flags.c
index fdbad7bf33..388c2f184b 100644
--- a/env/flags.c
+++ b/env/flags.c
@@ -458,7 +458,7 @@ static int set_flags(const char *name, const char *value, 
void *priv)
e.key   = name;
e.data  = NULL;
e.callback = NULL;
-   hsearch_r(e, FIND, , _htab, 0);
+   hsearch_r(e, ENVA_FIND, , _htab, 0);
 
/* does the env variable actually exist? */
if (ep != NULL) {
diff --git a/include/search.h b/include/search.h
index c99648f80b..fa7758480b 100644
--- a/include/search.h
+++ b/include/search.h
@@ -19,11 +19,11 @@
 
 #define __set_errno(val) do { errno = val; } while (0)
 
-/* Action which shall be performed in the call to hsearch.  */
-typedef enum {
-   FIND,
-   ENTER
-} ACTION;
+/* enum env_action: