summaryrefslogtreecommitdiffstats
path: root/common/globalvar.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-04-06 15:35:18 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-04-07 08:29:03 +0200
commitd8dfe33e90931747868bac3e4d65af684b29fb47 (patch)
tree531fc86591aa9aff68bc75db1a76245ee2efd5d1 /common/globalvar.c
parent441e9f5a72b245b671118f3e771eb129834a7a34 (diff)
downloadbarebox-d8dfe33e90931747868bac3e4d65af684b29fb47.tar.gz
barebox-d8dfe33e90931747868bac3e4d65af684b29fb47.tar.xz
nvvar: Fix creation without value
When a new nvvar is added without a value we want to get the value from the corresponding globalvar. We do this by using nv_set which ends up freeing the exact string that we passed into nv_set as value. This results in a corrupt value. Fix this by assigning a value manually without calling nv_set. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/globalvar.c')
-rw-r--r--common/globalvar.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/common/globalvar.c b/common/globalvar.c
index 52808f8852..ab573cc68d 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -233,10 +233,16 @@ static int __nvvar_add(const char *name, const char *value)
if (ret && ret != -EEXIST)
return ret;
- if (!value)
- value = dev_get_param(&global_device, name);
+ if (value)
+ return nv_set(&nv_device, p, value);
+
+ value = dev_get_param(&global_device, name);
+ if (value) {
+ free(p->value);
+ p->value = xstrdup(value);
+ }
- return nv_set(&nv_device, p, value);
+ return 0;
}
int nvvar_add(const char *name, const char *value)