From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 4/4] globalvar: Also create globalvars from for nonvolatile device vars
Date: Thu, 22 Sep 2016 10:11:12 +0200 [thread overview]
Message-ID: <1474531872-15000-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1474531872-15000-1-git-send-email-s.hauer@pengutronix.de>
nv variables beginning with "nv.dev.<devname>.<varname>" are directly
mirrored to <devname>.<varname> and there is no globalvar for it. To
make it a bit more consistent and to increase the visibility of the
nonvolatile device variables create globalvars for them aswell.
With this the propagation flow has changed from:
nv.dev.<devname>.<varname>
-> <devname>.<varname>
to:
nv.dev.<devname>.<varname>
-> global.dev.<devname>.<varname>
-> <devname>.<varname>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/globalvar.c | 75 ++++++++++++++++++++++--------------------------------
1 file changed, 30 insertions(+), 45 deletions(-)
diff --git a/common/globalvar.c b/common/globalvar.c
index 8f37c99..a2555cf 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -179,34 +179,14 @@ static int nvvar_device_dispatch(const char *name, struct device_d **dev,
static int nv_set(struct device_d *dev, struct param_d *p, const char *val)
{
int ret;
- int devspace;
- struct device_d *rdev;
- const char *pname;
if (!val)
val = "";
- ret = nvvar_device_dispatch(p->name, &rdev, &pname);
- if (ret < 0)
+ ret = dev_set_param(&global_device, p->name, val);
+ if (ret)
return ret;
- devspace = ret;
-
- if (devspace) {
- if (rdev) {
- ret = dev_set_param(rdev, pname, val);
- if (ret) {
- pr_err("Cannot init param from nv: %s.%s=%s: %s\n",
- dev_name(rdev), pname, val, strerror(-ret));
- return ret;
- }
- }
- } else {
- ret = dev_set_param(&global_device, p->name, val);
- if (ret)
- return ret;
- }
-
free(p->value);
p->value = xstrdup(val);
@@ -233,19 +213,10 @@ static int __nvvar_add(const char *name, const char *value)
{
struct param_d *p;
int ret;
- int devspace;
- struct device_d *dev;
- const char *pname;
if (!IS_ENABLED(CONFIG_NVVAR))
return -ENOSYS;
- ret = nvvar_device_dispatch(name, &dev, &pname);
- if (ret < 0)
- return ret;
-
- devspace = ret;
-
/* Get param. If it doesn't exist yet, create it */
p = get_param_by_name(&nv_device, name);
if (!p) {
@@ -254,20 +225,13 @@ static int __nvvar_add(const char *name, const char *value)
return PTR_ERR(p);
}
- if (!devspace) {
- ret = globalvar_add_simple(name, value);
- if (ret && ret != -EEXIST)
- return ret;
- }
+ /* Create corresponding globalvar if it doesn't exist yet */
+ ret = globalvar_add_simple(name, value);
+ if (ret && ret != -EEXIST)
+ return ret;
- if (!value) {
- if (devspace) {
- if (dev)
- value = dev_get_param(dev, pname);
- } else {
- value = dev_get_param(&global_device, name);
- }
- }
+ if (!value)
+ value = dev_get_param(&global_device, name);
return nv_set(&nv_device, p, value);
}
@@ -409,6 +373,27 @@ void globalvar_set_match(const char *match, const char *val)
}
}
+int globalvar_simple_set(struct device_d *dev, struct param_d *p, const char *val)
+{
+ struct device_d *rdev;
+ const char *pname;
+ int ret;
+
+ ret = nvvar_device_dispatch(p->name, &rdev, &pname);
+ if (ret < 0)
+ return ret;
+
+ if (ret && rdev) {
+ ret = dev_set_param(rdev, pname, val);
+ if (ret)
+ pr_err("Cannot init param from global: %s.%s=%s: %s\n",
+ dev_name(rdev), pname, val, strerror(-ret));
+ }
+
+ /* Pass to the generic function we have overwritten */
+ return dev_param_set_generic(dev, p, val);
+}
+
/*
* globalvar_add_simple
*
@@ -418,7 +403,7 @@ int globalvar_add_simple(const char *name, const char *value)
{
struct param_d *param;
- param = dev_add_param(&global_device, name, NULL, NULL,
+ param = dev_add_param(&global_device, name, globalvar_simple_set, NULL,
PARAM_GLOBALVAR_UNQUALIFIED);
if (IS_ERR(param)) {
if (PTR_ERR(param) != -EEXIST)
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2016-09-22 8:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-22 8:11 [PATCH 1/4] globalvar: Allow to remove multiple globalvars using wildcards Sascha Hauer
2016-09-22 8:11 ` [PATCH 2/4] global: Make 'global' command behaviour consistent to 'nv' Sascha Hauer
2016-09-22 8:11 ` [PATCH 3/4] nv: simplify nvvar_add Sascha Hauer
2016-09-22 8:11 ` Sascha Hauer [this message]
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=1474531872-15000-4-git-send-email-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