diff mbox series

[4/4] make env_entry::callback conditional on !CONFIG_SPL_BUILD

Message ID 20200227135600.28853-5-rasmus.villemoes@prevas.dk
State Accepted
Commit 080019b86c997a9b7e13bc7b8f476fbf9a0e5f3c
Delegated to: Tom Rini
Headers show
Series remove (more) env callback code for SPL | expand

Commit Message

Rasmus Villemoes Feb. 27, 2020, 1:56 p.m. UTC
The callback member of struct env_entry is always NULL for an SPL
build. Removing it thus saves a bit of run-time memory in the
SPL (when CONFIG_SPL_ENV_SUPPORT=y) since struct env_entry is embedded
in struct env_entry_node - i.e. about 2KB for the normal case of
512+change hash table entries.

Two small fixups are needed for this, all other references to the
callback member are already under !CONFIG_SPL_BUILD: Don't initialize
.callback in set_flags() - hsearch_r doesn't use that value
anyway. And make env_callback_init() initialize ->callback to NULL for
a new entry instead of relying on an unused or deleted entry having
NULL in ->callback.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 env/callback.c   | 2 ++
 env/flags.c      | 1 -
 include/search.h | 2 ++
 lib/hashtable.c  | 1 -
 4 files changed, 4 insertions(+), 2 deletions(-)

Comments

Simon Glass Feb. 27, 2020, 11:40 p.m. UTC | #1
On Thu, 27 Feb 2020 at 05:56, Rasmus Villemoes
<rasmus.villemoes@prevas.dk> wrote:
>
> The callback member of struct env_entry is always NULL for an SPL
> build. Removing it thus saves a bit of run-time memory in the
> SPL (when CONFIG_SPL_ENV_SUPPORT=y) since struct env_entry is embedded
> in struct env_entry_node - i.e. about 2KB for the normal case of
> 512+change hash table entries.
>
> Two small fixups are needed for this, all other references to the
> callback member are already under !CONFIG_SPL_BUILD: Don't initialize
> .callback in set_flags() - hsearch_r doesn't use that value
> anyway. And make env_callback_init() initialize ->callback to NULL for
> a new entry instead of relying on an unused or deleted entry having
> NULL in ->callback.
>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
>  env/callback.c   | 2 ++
>  env/flags.c      | 1 -
>  include/search.h | 2 ++
>  lib/hashtable.c  | 1 -
>  4 files changed, 4 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini April 24, 2020, 5:09 p.m. UTC | #2
On Thu, Feb 27, 2020 at 01:56:12PM +0000, Rasmus Villemoes wrote:

> The callback member of struct env_entry is always NULL for an SPL
> build. Removing it thus saves a bit of run-time memory in the
> SPL (when CONFIG_SPL_ENV_SUPPORT=y) since struct env_entry is embedded
> in struct env_entry_node - i.e. about 2KB for the normal case of
> 512+change hash table entries.
> 
> Two small fixups are needed for this, all other references to the
> callback member are already under !CONFIG_SPL_BUILD: Don't initialize
> .callback in set_flags() - hsearch_r doesn't use that value
> anyway. And make env_callback_init() initialize ->callback to NULL for
> a new entry instead of relying on an unused or deleted entry having
> NULL in ->callback.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/env/callback.c b/env/callback.c
index f0904cfdc5..4054b9ef58 100644
--- a/env/callback.c
+++ b/env/callback.c
@@ -55,6 +55,8 @@  void env_callback_init(struct env_entry *var_entry)
 		first_call = 0;
 	}
 
+	var_entry->callback = NULL;
+
 	/* look in the ".callbacks" var for a reference to this variable */
 	if (callback_list != NULL)
 		ret = env_attr_lookup(callback_list, var_name, callback_name);
diff --git a/env/flags.c b/env/flags.c
index 418d6cc742..b88fe7ba9c 100644
--- a/env/flags.c
+++ b/env/flags.c
@@ -457,7 +457,6 @@  static int set_flags(const char *name, const char *value, void *priv)
 
 	e.key	= name;
 	e.data	= NULL;
-	e.callback = NULL;
 	hsearch_r(e, ENV_FIND, &ep, &env_htab, 0);
 
 	/* does the env variable actually exist? */
diff --git a/include/search.h b/include/search.h
index 0469a852e0..8f87dc72ce 100644
--- a/include/search.h
+++ b/include/search.h
@@ -29,8 +29,10 @@  enum env_action {
 struct env_entry {
 	const char *key;
 	char *data;
+#ifndef CONFIG_SPL_BUILD
 	int (*callback)(const char *name, const char *value, enum env_op op,
 		int flags);
+#endif
 	int flags;
 };
 
diff --git a/lib/hashtable.c b/lib/hashtable.c
index c4e1e2bd45..f82f2463cf 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -450,7 +450,6 @@  static void _hdelete(const char *key, struct hsearch_data *htab,
 	debug("hdelete: DELETING key \"%s\"\n", key);
 	free((void *)ep->key);
 	free(ep->data);
-	ep->callback = NULL;
 	ep->flags = 0;
 	htab->table[idx].used = USED_DELETED;