diff mbox series

[U-Boot,v2,1/4] env: make env_import(_redund) return 0 on success, not 1

Message ID 20180131134713.11566-2-sgoldschmidt@de.pepperl-fuchs.com
State Accepted
Delegated to: Tom Rini
Headers show
Series env: cleanups after adding multiple envs | expand

Commit Message

Simon Goldschmidt Jan. 31, 2018, 1:47 p.m. UTC
env_import (and env_import_redund) currently return 1 on success
and 0 on error. However, they are only used from functions
returning 0 on success or a negative value on error.

Let's clean this up by making env_import and env_import_redund
return 0 on success and -EIO on error (as was the case for all
users before).

Users that cared for the return value are also updated. Funny
enough, this only affects onenand.c and sf.c

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>
---
 env/common.c  | 8 ++++----
 env/onenand.c | 4 ++--
 env/sf.c      | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

Comments

Maxime Ripard Jan. 31, 2018, 3:38 p.m. UTC | #1
On Wed, Jan 31, 2018 at 02:47:10PM +0100, Simon Goldschmidt wrote:
> env_import (and env_import_redund) currently return 1 on success
> and 0 on error. However, they are only used from functions
> returning 0 on success or a negative value on error.
> 
> Let's clean this up by making env_import and env_import_redund
> return 0 on success and -EIO on error (as was the case for all
> users before).
> 
> Users that cared for the return value are also updated. Funny
> enough, this only affects onenand.c and sf.c
> 
> Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime
Tom Rini Feb. 1, 2018, 1:09 p.m. UTC | #2
On Wed, Jan 31, 2018 at 02:47:10PM +0100, Simon Goldschmidt wrote:

> env_import (and env_import_redund) currently return 1 on success
> and 0 on error. However, they are only used from functions
> returning 0 on success or a negative value on error.
> 
> Let's clean this up by making env_import and env_import_redund
> return 0 on success and -EIO on error (as was the case for all
> users before).
> 
> Users that cared for the return value are also updated. Funny
> enough, this only affects onenand.c and sf.c
> 
> Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>
> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

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

Patch

diff --git a/env/common.c b/env/common.c
index c633502d68..363ba6fead 100644
--- a/env/common.c
+++ b/env/common.c
@@ -118,21 +118,21 @@  int env_import(const char *buf, int check)
 
 		if (crc32(0, ep->data, ENV_SIZE) != crc) {
 			set_default_env("!bad CRC");
-			return 0;
+			return -EIO;
 		}
 	}
 
 	if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0, 0,
 			0, NULL)) {
 		gd->flags |= GD_FLG_ENV_READY;
-		return 1;
+		return 0;
 	}
 
 	pr_err("Cannot import environment: errno = %d\n", errno);
 
 	set_default_env("!import failed");
 
-	return 0;
+	return -EIO;
 }
 
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
@@ -153,7 +153,7 @@  int env_import_redund(const char *buf1, const char *buf2)
 
 	if (!crc1_ok && !crc2_ok) {
 		set_default_env("!bad CRC");
-		return 0;
+		return -EIO;
 	} else if (crc1_ok && !crc2_ok) {
 		gd->env_valid = ENV_VALID;
 	} else if (!crc1_ok && crc2_ok) {
diff --git a/env/onenand.c b/env/onenand.c
index 2e3045c5f5..10a8cccbe8 100644
--- a/env/onenand.c
+++ b/env/onenand.c
@@ -57,10 +57,10 @@  static int env_onenand_load(void)
 #endif /* !ENV_IS_EMBEDDED */
 
 	rc = env_import(buf, 1);
-	if (rc)
+	if (!rc)
 		gd->env_valid = ENV_VALID;
 
-	return rc ? 0 : -EIO;
+	return rc;
 }
 
 static int env_onenand_save(void)
diff --git a/env/sf.c b/env/sf.c
index a2e4c93631..3dc54410df 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -236,7 +236,7 @@  static int env_sf_load(void)
 		ep = tmp_env2;
 
 	ret = env_import((char *)ep, 0);
-	if (!ret) {
+	if (ret) {
 		pr_err("Cannot import environment: errno = %d\n", errno);
 		set_default_env("!env_import failed");
 	}
@@ -336,7 +336,7 @@  static int env_sf_load(void)
 	}
 
 	ret = env_import(buf, 1);
-	if (ret)
+	if (!ret)
 		gd->env_valid = ENV_VALID;
 
 err_read: