From 3610970872351b58d9cfdbd9bf9aeabc6adac7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?= Date: Thu, 30 Sep 2021 17:52:45 +0200 Subject: dm: Fix util.h's broken include guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix up the header's include guard to contain the definition of dm_priv_to_rw(), which was erroneously added outside of it, by moving its #endif to the end of the file (i.e. where it belongs). This removes the risk of compilation errors resulting from the redefinition of that function where the header might have been (indirectly) included more than once. Fixes: cfb9c9b77c2 ("dm: core: Use separate priv/plat data region") Signed-off-by: Pierre-Clément Tosi Cc: Simon Glass --- include/dm/util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/dm/util.h b/include/dm/util.h index c634e470e7a..17baf55c255 100644 --- a/include/dm/util.h +++ b/include/dm/util.h @@ -48,8 +48,6 @@ void dm_dump_driver_compat(void); /* Dump out a list of drivers with static platform data */ void dm_dump_static_driver_info(void); -#endif - #if CONFIG_IS_ENABLED(OF_PLATDATA_INST) && CONFIG_IS_ENABLED(READ_ONLY) void *dm_priv_to_rw(void *priv); #else @@ -58,3 +56,5 @@ static inline void *dm_priv_to_rw(void *priv) return priv; } #endif + +#endif -- cgit v1.2.3 From 6dc1e2f10c7ca8ba7caf5444efeb5bb015837829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Sun, 17 Oct 2021 17:36:26 +0200 Subject: env: Fix documentation for env_get_f() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function actually returns: - the number of bytes written into @buf excluding the terminating NULL-byte, if there was enough space in @buf - the number of bytes written into @buf including the terminating NULL-byte, if there wasn't enough space in @buf - -1 if the variable is not found Signed-off-by: Marek Behún Reviewed-by: Simon Glass --- include/env.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/env.h b/include/env.h index d5e2bcb530f..b1a40036813 100644 --- a/include/env.h +++ b/include/env.h @@ -131,7 +131,10 @@ char *from_env(const char *envvar); * support reading the value (slowly) and some will not. * * @varname: Variable to look up - * @return value of variable, or NULL if not found + * @return number of bytes written into @buf, excluding the terminating + * NULL-byte if there was enough space in @buf, and including the + * terminating NULL-byte if there wasn't enough space, or -1 if the + * variable is not found */ int env_get_f(const char *name, char *buf, unsigned int len); -- cgit v1.2.3 From 7b611ee90e1e4db531c4e3896efebfdc0743725d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Sun, 17 Oct 2021 17:36:29 +0200 Subject: env: Change env_match() to static and remove from header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function was used by other parts of U-Boot in the past when environment was read from underlying device one character at a time. This is not the case anymore. Signed-off-by: Marek Behún Reviewed-by: Simon Glass --- include/env.h | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'include') diff --git a/include/env.h b/include/env.h index b1a40036813..a9b2a4c8b2f 100644 --- a/include/env.h +++ b/include/env.h @@ -90,17 +90,6 @@ int env_init(void); */ void env_relocate(void); -/** - * env_match() - Match a name / name=value pair - * - * This is used prior to relocation for finding envrionment variables - * - * @name: A simple 'name', or a 'name=value' pair. - * @index: The environment index for a 'name2=value2' pair. - * @return index for the value if the names match, else -1. - */ -int env_match(unsigned char *name, int index); - /** * env_get() - Look up the value of an environment variable * -- cgit v1.2.3 From 52f9ed34cb3768663ee9c2e5d980143e8ac783a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Sun, 17 Oct 2021 17:36:30 +0200 Subject: env: Inline env_get_char() into its only user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function is a relic from the past when environment was read from underlying device one character at a time. It is used only in the case when getting an environemnt variable prior relocation, and the function is simple enough to be inlined there. Since env_get_char() is being changed to simple access to an array, we can drop the failing cases and simplify the code (this could have been done before, since env_get_char() did not fail even before). Signed-off-by: Marek Behún Reviewed-by: Simon Glass --- include/env.h | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'include') diff --git a/include/env.h b/include/env.h index a9b2a4c8b2f..220ab979d96 100644 --- a/include/env.h +++ b/include/env.h @@ -351,16 +351,6 @@ char *env_get_default(const char *name); /* [re]set to the default environment */ void env_set_default(const char *s, int flags); -/** - * env_get_char() - Get a character from the early environment - * - * This reads from the pre-relocation environment - * - * @index: Index of character to read (0 = first) - * @return character read, or -ve on error - */ -int env_get_char(int index); - /** * env_reloc() - Relocate the 'env' sub-commands * -- cgit v1.2.3 From 3112ce0ce8195880aec5e9373434a85e21c3e1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Sun, 17 Oct 2021 17:36:35 +0200 Subject: env: Make return value of env_get_f() behave like sprintf() on success MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently the env_get_f() function's return value behaves weirdly: it returns the number of bytes written into `buf`, but whether this is excluding the terminating NULL-byte or including it depends on whether there was enough space in `buf`. Change the function to always return the actual length of the value of the environment variable (excluding the terminating NULL-byte) on success. This makes it behave like sprintf(). All users of this function in U-Boot are compatible with this change. Signed-off-by: Marek Behún Reviewed-by: Simon Glass --- include/env.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/env.h b/include/env.h index 220ab979d96..ee5e30d036d 100644 --- a/include/env.h +++ b/include/env.h @@ -120,10 +120,8 @@ char *from_env(const char *envvar); * support reading the value (slowly) and some will not. * * @varname: Variable to look up - * @return number of bytes written into @buf, excluding the terminating - * NULL-byte if there was enough space in @buf, and including the - * terminating NULL-byte if there wasn't enough space, or -1 if the - * variable is not found + * @return actual length of the variable value excluding the terminating + * NULL-byte, or -1 if the variable is not found */ int env_get_f(const char *name, char *buf, unsigned int len); -- cgit v1.2.3