mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] device parameters: Allow dots in device names for setenv aswell
@ 2018-01-10 15:06 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2018-01-10 15:06 UTC (permalink / raw)
  To: Barebox List

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>
---
 common/env.c | 54 +++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 19 deletions(-)

diff --git a/common/env.c b/common/env.c
index df8a4dff60..80d3f7ab50 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;
 	}
 
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-01-10 15:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-10 15:06 [PATCH] device parameters: Allow dots in device names for setenv aswell Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox