summaryrefslogtreecommitdiffstats
path: root/common/env.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-01-09 16:00:04 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-01-10 16:06:28 +0100
commita433e04e79a096dbbb660c3a50a8317ccc052316 (patch)
tree704d17d48669b4de6354f3b730dfdf81e7e63643 /common/env.c
parentaa7a10e6dc9366e3962cf8a9912b25f25d63177e (diff)
downloadbarebox-a433e04e79a096dbbb660c3a50a8317ccc052316.tar.gz
device parameters: Allow dots in device names for setenv aswell
Since f5d77d80f5 Allow device parameters for devices with dots in name Devices can have dots in their name and we can still read its device parameters. Do the same change for writing parameters so they can be written aswell. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/env.c')
-rw-r--r--common/env.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/common/env.c b/common/env.c
index df8a4df..80d3f7a 100644
--- a/common/env.c
+++ b/common/env.c
@@ -223,34 +223,50 @@ static int setenv_raw(struct list_head *l, const char *name, const char *value)
return 0;
}
-int setenv(const char *_name, const char *value)
+static int dev_setenv(const char *name, const char *val)
{
- char *name = strdup(_name);
- char *par;
- int ret = 0;
- struct list_head *list;
+ const char *pos, *dot, *varname;
+ char *devname;
+ struct device_d *dev;
- if (value && !*value)
- value = NULL;
+ pos = name;
+
+ while (1) {
+ dot = strchr(pos, '.');
+ if (!dot)
+ break;
+
+ devname = xstrndup(name, dot - name);
+ varname = dot + 1;
+ dev = get_device_by_name(devname);
- if ((par = strchr(name, '.'))) {
- struct device_d *dev;
+ free(devname);
- *par++ = 0;
- dev = get_device_by_name(name);
if (dev) {
- ret = dev_set_param(dev, par, value);
- if (ret)
- eprintf("%s: set parameter %s: %s\n",
- dev_name(dev), par, strerror(-ret));
- } else {
- ret = -ENODEV;
- eprintf("set parameter: no such device %s\n", name);
+ if (get_param_by_name(dev, varname))
+ return dev_set_param(dev, varname, val);
}
- errno = -ret;
+ pos = dot + 1;
+ }
+
+ return -ENODEV;
+}
+
+int setenv(const char *_name, const char *value)
+{
+ char *name = strdup(_name);
+ int ret = 0;
+ struct list_head *list;
+
+ if (value && !*value)
+ value = NULL;
+ if (strchr(name, '.')) {
+ ret = dev_setenv(name, value);
+ if (ret)
+ eprintf("Cannot set parameter: %s\n", strerror(-ret));
goto out;
}