mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/4] nv: simplify nvvar_add
Date: Thu, 22 Sep 2016 10:11:11 +0200	[thread overview]
Message-ID: <1474531872-15000-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1474531872-15000-1-git-send-email-s.hauer@pengutronix.de>

We do not need to have an extra code path when the variable already
exists, instead setting an existing variable can be done in the
variable creation code path aswell.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/globalvar.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index 007e955..8f37c99 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -231,7 +231,7 @@ static int nv_param_set(struct device_d *dev, struct param_d *p, const char *val
 
 static int __nvvar_add(const char *name, const char *value)
 {
-	struct param_d *p, *gp;
+	struct param_d *p;
 	int ret;
 	int devspace;
 	struct device_d *dev;
@@ -246,19 +246,12 @@ static int __nvvar_add(const char *name, const char *value)
 
 	devspace = ret;
 
-	gp = get_param_by_name(&nv_device, name);
-	if (gp) {
-		if (!devspace) {
-			ret = dev_set_param(&global_device, name, value);
-			if (ret)
-				return ret;
-		}
-
-		ret = dev_set_param(&nv_device, name, value);
-		if (ret)
-			return ret;
-
-		return 0;
+	/* Get param. If it doesn't exist yet, create it */
+	p = get_param_by_name(&nv_device, name);
+	if (!p) {
+		p = dev_add_param(&nv_device, name, nv_param_set, nv_param_get, 0);
+		if (IS_ERR(p))
+			return PTR_ERR(p);
 	}
 
 	if (!devspace) {
@@ -267,10 +260,6 @@ static int __nvvar_add(const char *name, const char *value)
 			return ret;
 	}
 
-	p = dev_add_param(&nv_device, name, nv_param_set, nv_param_get, 0);
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
 	if (!value) {
 		if (devspace) {
 			if (dev)
-- 
2.8.1


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

  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 ` Sascha Hauer [this message]
2016-09-22  8:11 ` [PATCH 4/4] globalvar: Also create globalvars from for nonvolatile device vars Sascha Hauer

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-3-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