Re: [PATCH 2/5] env_internal.h: add alternative ENV_SAVE_PTR macro

2020-04-24 Thread Tom Rini
On Wed, Feb 19, 2020 at 09:47:40AM +, Rasmus Villemoes wrote:

> The current definition of the env_save_ptr does not take SPL_SAVEENV
> into account. Moreover, the way it is implemented means that drivers
> need to guard the definitions of their _save methods with ifdefs to
> avoid "defined but unused" warnings in case CMD_SAVEENV=n.
> 
> The ifdeffery can be avoided by using a "something ? x : NULL"
> construction instead and still have the compiler elide the _save
> method when it is not referenced. Unfortunately we can't just switch
> the existing env_save_ptr macro, since that would give a lot of build
> errors unless all the ifdeffery is removed at the same time.
> Conversely, removing that ifdeffery first would merely lead to the
> "defined but unused" warnings temporarily, but for some storage
> drivers it requires a bit more work than just removing their private
> CMD_SAVEENV logic.
> 
> So introduce an alternative to env_save_ptr, which for lack of a
> better name is simply uppercased, allowing one to update storage
> drivers piecemeal to both reduce their ifdeffery and honour
> CONFIG_SPL_SAVEENV.
> 
> Signed-off-by: Rasmus Villemoes 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH 2/5] env_internal.h: add alternative ENV_SAVE_PTR macro

2020-02-19 Thread Rasmus Villemoes
The current definition of the env_save_ptr does not take SPL_SAVEENV
into account. Moreover, the way it is implemented means that drivers
need to guard the definitions of their _save methods with ifdefs to
avoid "defined but unused" warnings in case CMD_SAVEENV=n.

The ifdeffery can be avoided by using a "something ? x : NULL"
construction instead and still have the compiler elide the _save
method when it is not referenced. Unfortunately we can't just switch
the existing env_save_ptr macro, since that would give a lot of build
errors unless all the ifdeffery is removed at the same time.
Conversely, removing that ifdeffery first would merely lead to the
"defined but unused" warnings temporarily, but for some storage
drivers it requires a bit more work than just removing their private
CMD_SAVEENV logic.

So introduce an alternative to env_save_ptr, which for lack of a
better name is simply uppercased, allowing one to update storage
drivers piecemeal to both reduce their ifdeffery and honour
CONFIG_SPL_SAVEENV.

Signed-off-by: Rasmus Villemoes 
---
 include/env_internal.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/env_internal.h b/include/env_internal.h
index 90a4df8a72..e89fbdb1b7 100644
--- a/include/env_internal.h
+++ b/include/env_internal.h
@@ -207,6 +207,8 @@ struct env_driver {
 #define env_save_ptr(x) NULL
 #endif
 
+#define ENV_SAVE_PTR(x) (CONFIG_IS_ENABLED(SAVEENV) ? (x) : NULL)
+
 extern struct hsearch_data env_htab;
 
 #endif /* DO_DEPS_ONLY */
-- 
2.23.0