[U-Boot] [PATCH] avoid flash writes for new keys, with no values with fw_setenv

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()); }
/*

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
participants (2)
-
Sridhar Addagada
-
Wolfgang Denk