public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] avoid flash writes for new keys, with no values with fw_setenv
@ 2011-12-21  8:59 Sridhar Addagada
  2012-01-05 16:19 ` Wolfgang Denk
  0 siblings, 1 reply; 2+ messages in thread
From: Sridhar Addagada @ 2011-12-21  8:59 UTC (permalink / raw)
  To: u-boot

This will avoid flash writes for fw_setenv command where the key is not present the environment and no value has been provided.

Signed-off-by: Sridhar Addagada <sridhar_a@yahoo.com>
---
tools/env/fw_env.c |   11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 996682e..68597a5 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -366,7 +366,7 @@ int fw_env_close(void)
*/
int fw_env_write(char *name, char *value)
{
-	int len;
+	int len, found = 0;
char *env, *nxt;
char *oldval = NULL;

@@ -415,7 +415,7 @@ int fw_env_write(char *name, char *value)

/* Delete only ? */
if (!value || !strlen(value))
-		return 0;
+		return (found ? 0 : -1);

/*
* Append new definition at the end
@@ -460,7 +460,7 @@ int fw_env_write(char *name, char *value)
*/
int fw_setenv(int argc, char *argv[])
{
-	int i, len;
+	int r, i, len;
char *name;
char *value = NULL;
char *tmpval = NULL;
@@ -501,12 +501,13 @@ int fw_setenv(int argc, char *argv[])
*tmpval++ = *val++;
}

-	fw_env_write(name, value);
+	r = fw_env_write(name, value);

if (value)
free(value);

-	return fw_env_close();
+    // avoid flash write for new keys, with no values.
+	return ((-1 == r) ? r : fw_env_close());
}

/*
-- 
1.7.3.GIT

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] avoid flash writes for new keys, with no values with fw_setenv
  2011-12-21  8:59 [U-Boot] [PATCH] avoid flash writes for new keys, with no values with fw_setenv Sridhar Addagada
@ 2012-01-05 16:19 ` Wolfgang Denk
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Denk @ 2012-01-05 16:19 UTC (permalink / raw)
  To: u-boot

Dear Sridhar Addagada,

In message <1324457962.60605.YahooMailNeo@web120203.mail.ne1.yahoo.com> you wrote:
>
> This will avoid flash writes for fw_setenv command where the key is not present the environment and no value has been provided.

Line too long.  And your patch is white space corrupted.  Please fix
your mailer, or better use git-format-patch and git-send-email instead.

Also, make sure to always call fw_env_close().

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If there are self-made purgatories, then we all have to live in them.
	-- Spock, "This Side of Paradise", stardate 3417.7

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-05 16:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-21  8:59 [U-Boot] [PATCH] avoid flash writes for new keys, with no values with fw_setenv Sridhar Addagada
2012-01-05 16:19 ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox