Skip to contentSkip to conversation

avoid flash writes for new keys, with no values with fw_setenv

PATCH New Sridhar Addagada 2 participants 2 messages Dec 21, 2011 – Jan 5, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
tools/env/fw_env.c | 11 ++++++-----

1 files changed, 6 insertions(+), 5 deletions(-)
tools/env/fw_env.c +0 -0
index 996682e..68597a5 100644
@@ -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());
}

/*

Signature · 1 line
1.7.3.GIT
#1 lore raw

PATCH 1/1 avoid flash writes for new keys, with no values with fw_setenv

Dear Sridhar Addagada,

Quoted 2 lines · In message <[email protected]> you…

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

Signature · 5 lines
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