summaryrefslogtreecommitdiffstats
path: root/common/env.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2008-08-20 17:46:07 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2008-08-20 17:46:54 +0200
commit66a936fa64a8d1c9aeb08be119c968258fbdc9ce (patch)
treefef9b1a1b50c71f81e9caaf3bdaac065c6bbdd35 /common/env.c
parentbcb049a7027f4e22d9ebb0e84514f1eb86cad65e (diff)
downloadbarebox-66a936fa64a8d1c9aeb08be119c968258fbdc9ce.tar.gz
setenv: Fix warning introduced with last commit
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/env.c')
-rw-r--r--common/env.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/common/env.c b/common/env.c
index 50da2ea..04ca275 100644
--- a/common/env.c
+++ b/common/env.c
@@ -198,35 +198,45 @@ static int setenv_raw(struct variable_d *var, const char *name, const char *valu
return 0;
}
-int setenv(const char *name, const char *value)
+int setenv(const char *_name, const char *value)
{
+ char *name = strdup(_name);
char *par;
+ struct variable_d *var;
+ int ret = 0;
if (!*value)
value = NULL;
+
if ((par = strchr(name, '.'))) {
struct device_d *dev;
+
*par++ = 0;
dev = get_device_by_id(name);
- if (dev) {
- int ret = dev_set_param(dev, par, value);
- if (ret < 0)
- perror("set parameter");
- errno = 0;
- } else {
- errno = -ENODEV;
+ if (dev)
+ ret = dev_set_param(dev, par, value);
+ else
+ ret = -ENODEV;
+
+ errno = ret;
+
+ if (ret < 0)
perror("set parameter");
- }
- return errno;
+
+ goto out;
}
if (getenv_raw(context->global, name))
- setenv_raw(context->global, name, value);
+ var = context->global;
else
- setenv_raw(context->local, name, value);
+ var = context->local;
- return 0;
+ ret = setenv_raw(var, name, value);
+out:
+ free(name);
+
+ return ret;
}
EXPORT_SYMBOL(setenv);