diff mbox series

[U-Boot] env: sf: fix return value of env_sf_load

Message ID 20180130075511.31399-1-sgoldschmidt@de.pepperl-fuchs.com
State Superseded
Delegated to: Tom Rini
Headers show
Series [U-Boot] env: sf: fix return value of env_sf_load | expand

Commit Message

Simon Goldschmidt Jan. 30, 2018, 7:55 a.m. UTC
With the recent changes to support multiple environments, I see a
message "Failed (1)" when loading environment from sf.

env_sf_load() returns the return value of env_import(). This must be
'inverted' to return the correct meaning.

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>
---
 env/sf.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Simon Goldschmidt Jan. 30, 2018, 8:15 a.m. UTC | #1
On 30.01.2018 08:55, Simon Goldschmidt wrote:
> With the recent changes to support multiple environments, I see a
> message "Failed (1)" when loading environment from sf.
>
> env_sf_load() returns the return value of env_import(). This must be
> 'inverted' to return the correct meaning.

Thinking about this again, it might be cleaner to make env_import and 
env_import_redundant return 0 on success. Would that be acceptable?

Regards,
Simon

>
> Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>
> ---
>   env/sf.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/env/sf.c b/env/sf.c
> index a2e4c93631..921860fd88 100644
> --- a/env/sf.c
> +++ b/env/sf.c
> @@ -239,6 +239,9 @@ static int env_sf_load(void)
>   	if (!ret) {
>   		pr_err("Cannot import environment: errno = %d\n", errno);
>   		set_default_env("!env_import failed");
> +		ret = -EIO;
> +	} else {
> +		ret = 0;
>   	}
>   
>   err_read:
> @@ -336,8 +339,12 @@ static int env_sf_load(void)
>   	}
>   
>   	ret = env_import(buf, 1);
> -	if (ret)
> +	if (ret) {
>   		gd->env_valid = ENV_VALID;
> +		ret = 0;
> +	} else {
> +		ret = -EIO;
> +	}
>   
>   err_read:
>   	spi_flash_free(env_flash);
Tom Rini Jan. 30, 2018, 3:23 p.m. UTC | #2
On Tue, Jan 30, 2018 at 09:15:09AM +0100, Simon Goldschmidt wrote:
> On 30.01.2018 08:55, Simon Goldschmidt wrote:
> >With the recent changes to support multiple environments, I see a
> >message "Failed (1)" when loading environment from sf.
> >
> >env_sf_load() returns the return value of env_import(). This must be
> >'inverted' to return the correct meaning.
> 
> Thinking about this again, it might be cleaner to make env_import and
> env_import_redundant return 0 on success. Would that be acceptable?

If it makes things look cleaner, yes, thanks!
diff mbox series

Patch

diff --git a/env/sf.c b/env/sf.c
index a2e4c93631..921860fd88 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -239,6 +239,9 @@  static int env_sf_load(void)
 	if (!ret) {
 		pr_err("Cannot import environment: errno = %d\n", errno);
 		set_default_env("!env_import failed");
+		ret = -EIO;
+	} else {
+		ret = 0;
 	}
 
 err_read:
@@ -336,8 +339,12 @@  static int env_sf_load(void)
 	}
 
 	ret = env_import(buf, 1);
-	if (ret)
+	if (ret) {
 		gd->env_valid = ENV_VALID;
+		ret = 0;
+	} else {
+		ret = -EIO;
+	}
 
 err_read:
 	spi_flash_free(env_flash);