From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] device parameters: Allow dots in device names for setenv aswell
Date: Wed, 10 Jan 2018 16:06:33 +0100 [thread overview]
Message-ID: <20180110150633.30359-1-s.hauer@pengutronix.de> (raw)
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
reply other threads:[~2018-01-10 15:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180110150633.30359-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox