mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Christian Eggers <ceggers@arri.de>
To: barebox@lists.infradead.org
Cc: Christian Eggers <ceggers@arri.de>, ceggers@gmx.de
Subject: [PATCH 4/5] globalvar: Allow NULL pointers to be returned by dev_add_param()
Date: Thu, 23 Jan 2020 13:20:44 +0100	[thread overview]
Message-ID: <20200123122045.25507-4-ceggers@arri.de> (raw)
In-Reply-To: <20200123122045.25507-1-ceggers@arri.de>

The following commit will change the return value of dev_add_param()
from -ENOSYS to NULL if CONFIG_PARAMETER is disabled. After that,
building without CONFIG_PARAMETER will return a NULL pointer to
__nvvar_add() instead of an error.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 common/globalvar.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index cec0a9cc4..8dcbc04bd 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -166,21 +166,24 @@ static int nvvar_device_dispatch(const char *name, struct device_d **dev,
 	return 1;
 }
 
-static int nv_set(struct device_d *dev, struct param_d *p, const char *val)
+static int nv_set(struct device_d *dev, struct param_d *p, const char *name, const char *val)
 {
 	int ret;
 
 	if (!val) {
-		free(p->value);
+		if (p)
+			free(p->value);
 		return 0;
 	}
 
-	ret = dev_set_param(&global_device, p->name, val);
+	ret = dev_set_param(&global_device, name, val);
 	if (ret)
 		return ret;
 
-	free(p->value);
-	p->value = xstrdup(val);
+	if (p) {
+		free(p->value);
+		p->value = xstrdup(val);
+	}
 
 	return 0;
 }
@@ -194,7 +197,7 @@ static int nv_param_set(struct device_d *dev, struct param_d *p, const char *val
 {
 	int ret;
 
-	ret = nv_set(dev, p, val);
+	ret = nv_set(dev, p, p->name, val);
 	if (ret)
 		return ret;
 
@@ -225,7 +228,7 @@ static int __nvvar_add(const char *name, const char *value)
 		return ret;
 
 	if (value)
-		return nv_set(&nv_device, p, value);
+		return nv_set(&nv_device, p, name, value);
 
 	ret = nvvar_device_dispatch(name, &dev, &pname);
 	if (ret > 0)
@@ -233,7 +236,7 @@ static int __nvvar_add(const char *name, const char *value)
 	else
 		value = dev_get_param(&global_device, name);
 
-	if (value) {
+	if (value && p) {
 		free(p->value);
 		p->value = xstrdup(value);
 	}
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


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

  parent reply	other threads:[~2020-01-23 12:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-23 12:20 [PATCH 1/5] state: remove param member from struct state_string Christian Eggers
2020-01-23 12:20 ` [PATCH 2/5] mci: remove param_probe member from struct mci Christian Eggers
2020-01-23 12:20 ` [PATCH 3/5] state: remove param member from state_uint32, state_enum32, state_mac Christian Eggers
2020-01-23 12:20 ` Christian Eggers [this message]
2020-01-23 12:20 ` [PATCH 5/5] parameter: Return NULL instead of ENOSYS if CONFIG_PARAMETER is disabled Christian Eggers
2020-01-27  9:58 ` [PATCH 1/5] state: remove param member from struct state_string 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=20200123122045.25507-4-ceggers@arri.de \
    --to=ceggers@arri.de \
    --cc=barebox@lists.infradead.org \
    --cc=ceggers@gmx.de \
    /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