diff mbox series

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

Message ID 20200219094726.26798-3-rasmus.villemoes@prevas.dk
State Accepted
Commit 82b2f41357199c9fd06da80f8dd21e0576d08efe
Headers show
Series CMD_SAVEENV ifdef cleanup | expand

Commit Message

Rasmus Villemoes Feb. 19, 2020, 9:47 a.m. UTC
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 <rasmus.villemoes at prevas.dk>
---
 include/env_internal.h | 2 ++
 1 file changed, 2 insertions(+)

Comments

Tom Rini April 24, 2020, 5:08 p.m. UTC | #1
On Wed, Feb 19, 2020 at 09:47:40AM +0000, 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 <rasmus.villemoes at prevas.dk>

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

Patch

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 */