summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChristian Eggers <ceggers@arri.de>2020-01-23 13:20:44 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-01-27 10:57:42 +0100
commita28332268849ae13c0fba6d0fd3e6b18b380e214 (patch)
treef2fad0ed8cd6271b4a9538af82bf7f75bed13014 /common
parent8718fd1f0508ed694569df212333fff9a22b5303 (diff)
downloadbarebox-a28332268849ae13c0fba6d0fd3e6b18b380e214.tar.gz
globalvar: Allow NULL pointers to be returned by dev_add_param()
The following commit will change the return value of dev_add_param() from -ENOSYS to NULL if CONFIG_PARAMETER is disabled. After that, building without CONFIG_PARAMETER will return a NULL pointer to __nvvar_add() instead of an error. Signed-off-by: Christian Eggers <ceggers@arri.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/globalvar.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/common/globalvar.c b/common/globalvar.c
index a826e1b..c87f2c9 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -175,21 +175,24 @@ static int nvvar_device_dispatch(const char *name, struct device_d **dev,
return 1;
}
-static int nv_set(struct device_d *dev, struct param_d *p, const char *val)
+static int nv_set(struct device_d *dev, struct param_d *p, const char *name, const char *val)
{
int ret;
if (!val) {
- free(p->value);
+ if (p)
+ free(p->value);
return 0;
}
- ret = dev_set_param(&global_device, p->name, val);
+ ret = dev_set_param(&global_device, name, val);
if (ret)
return ret;
- free(p->value);
- p->value = xstrdup(val);
+ if (p) {
+ free(p->value);
+ p->value = xstrdup(val);
+ }
return 0;
}
@@ -203,7 +206,7 @@ static int nv_param_set(struct device_d *dev, struct param_d *p, const char *val
{
int ret;
- ret = nv_set(dev, p, val);
+ ret = nv_set(dev, p, p->name, val);
if (ret)
return ret;
@@ -234,7 +237,7 @@ static int __nvvar_add(const char *name, const char *value)
return ret;
if (value)
- return nv_set(&nv_device, p, value);
+ return nv_set(&nv_device, p, name, value);
ret = nvvar_device_dispatch(name, &dev, &pname);
if (ret > 0)
@@ -242,7 +245,7 @@ static int __nvvar_add(const char *name, const char *value)
else
value = dev_get_param(&global_device, name);
- if (value) {
+ if (value && p) {
free(p->value);
p->value = xstrdup(value);
}