mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] globalvar: Move static inline functions to common/
@ 2016-09-20 14:26 Sascha Hauer
  2016-09-20 14:26 ` [PATCH 2/2] globalvar: sync with nvvars Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2016-09-20 14:26 UTC (permalink / raw)
  To: Barebox List

These functions will get bigger in the next patch which disqualifies
them as static inline functions.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/globalvar.c  | 67 ++++++++++++++++++++++++++++++++++++++++++++++
 include/globalvar.h | 76 +++++------------------------------------------------
 2 files changed, 74 insertions(+), 69 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index 44e6528..49f7f7d 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -437,6 +437,73 @@ int globalvar_add_simple(const char *name, const char *value)
 	return dev_set_param(&global_device, name, value);
 }
 
+int globalvar_add_simple_string(const char *name, char **value)
+{
+	struct param_d *p;
+
+	p = dev_add_param_string(&global_device, name, NULL, NULL,
+		value, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
+int globalvar_add_simple_int(const char *name, int *value,
+			     const char *format)
+{
+	struct param_d *p;
+
+	p = dev_add_param_int(&global_device, name, NULL, NULL,
+		value, format, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
+int globalvar_add_simple_bool(const char *name, int *value)
+{
+	struct param_d *p;
+
+	p = dev_add_param_bool(&global_device, name, NULL, NULL,
+		value, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
+int globalvar_add_simple_enum(const char *name,	int *value,
+			      const char * const *names, int max)
+{
+	struct param_d *p;
+
+	p = dev_add_param_enum(&global_device, name, NULL, NULL,
+		value, names, max, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
+int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
+{
+	struct param_d *p;
+
+	p = dev_add_param_ip(&global_device, name, NULL, NULL,
+		ip, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
 static int globalvar_init(void)
 {
 	register_device(&global_device);
diff --git a/include/globalvar.h b/include/globalvar.h
index 1cd8d21..2322efb 100644
--- a/include/globalvar.h
+++ b/include/globalvar.h
@@ -18,75 +18,13 @@ void globalvar_remove(const char *name);
 char *globalvar_get_match(const char *match, const char *separator);
 void globalvar_set_match(const char *match, const char *val);
 
-static inline int globalvar_add_simple_string(const char *name,
-		char **value)
-{
-	struct param_d *p;
-
-	p = dev_add_param_string(&global_device, name, NULL, NULL,
-		value, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
-}
-
-static inline int globalvar_add_simple_int(const char *name,
-		int *value, const char *format)
-{
-	struct param_d *p;
-
-	p = dev_add_param_int(&global_device, name, NULL, NULL,
-		value, format, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
-}
-
-static inline int globalvar_add_simple_bool(const char *name,
-		int *value)
-{
-	struct param_d *p;
-
-	p = dev_add_param_bool(&global_device, name, NULL, NULL,
-		value, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
-}
-
-static inline int globalvar_add_simple_enum(const char *name,
-		int *value, const char * const *names, int max)
-{
-	struct param_d *p;
-
-	p = dev_add_param_enum(&global_device, name, NULL, NULL,
-		value, names, max, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
-}
-
-static inline int globalvar_add_simple_ip(const char *name,
-		IPaddr_t *ip)
-{
-	struct param_d *p;
-
-	p = dev_add_param_ip(&global_device, name, NULL, NULL,
-		ip, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
-}
+int globalvar_add_simple_string(const char *name, char **value);
+int globalvar_add_simple_int(const char *name, int *value,
+			     const char *format);
+int globalvar_add_simple_bool(const char *name, int *value);
+int globalvar_add_simple_enum(const char *name,	int *value,
+			      const char * const *names, int max);
+int globalvar_add_simple_ip(const char *name, IPaddr_t *ip);
 
 int nvvar_load(void);
 void nvvar_print(void);
-- 
2.8.1


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] globalvar: sync with nvvars
  2016-09-20 14:26 [PATCH 1/2] globalvar: Move static inline functions to common/ Sascha Hauer
@ 2016-09-20 14:26 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2016-09-20 14:26 UTC (permalink / raw)
  To: Barebox List

This patch fixes the behaviour when a driver creates a globalvar using
globalvar_add_simple_[string|int|bool|enum|ip]) *after* nvvars are
initialized and this globalvar is overwritten with a nvvar. Currently
this fix is not needed because all globalvars are registered before the
nvvars are initialized.

We have two different typed of globalvars. The first type, here referred
to as qualified globalvars, has a backend variable storage (the ones
created with globalvar_add_simple_[string|int|bool|enum|ip]), the other
created with globalvar_add_simple only has a dynamically allocted string
as backend.

Normally during startup of barebox the qualified globalvars are
registered and during load of nvvars are synced with the values from the
nvvars. Everything works fine in this case. However, when during nvvar
initialisation a globalvar for a nvvar does not exist, then it is
registered as unqualified globalvar. When then later some driver wants
to register a qualified globalvar for which a unqualified globalvar
already exists, it will get a -EEXIST. This is not the expected
behaviour. Instead, the current unqualified globalvar should be removed,
recreated as qualified globalvar and then afterwards synced with the
corresponding nvvar. This behaviour is fixed with this patch.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/globalvar.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 include/param.h    |  1 +
 2 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index 49f7f7d..3fd8221 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -425,11 +425,14 @@ void globalvar_set_match(const char *match, const char *val)
  */
 int globalvar_add_simple(const char *name, const char *value)
 {
-	int ret;
+	struct param_d *param;
 
-	ret = globalvar_add(name, NULL, NULL, 0);
-	if (ret && ret != -EEXIST)
-		return ret;
+	param = dev_add_param(&global_device, name, NULL, NULL,
+			      PARAM_GLOBALVAR_UNQUALIFIED);
+	if (IS_ERR(param)) {
+		if (PTR_ERR(param) != -EEXIST)
+			return PTR_ERR(param);
+	}
 
 	if (!value)
 		return 0;
@@ -437,9 +440,39 @@ int globalvar_add_simple(const char *name, const char *value)
 	return dev_set_param(&global_device, name, value);
 }
 
+static int globalvar_remove_unqualified(const char *name)
+{
+	struct param_d *p;
+
+	p = get_param_by_name(&global_device, name);
+	if (!p)
+		return 0;
+
+	if (!(p->flags & PARAM_GLOBALVAR_UNQUALIFIED))
+		return -EEXIST;
+
+	dev_remove_param(p);
+
+	return 0;
+}
+
+static void globalvar_nv_sync(const char *name)
+{
+	const char *val;
+
+	val = dev_get_param(&nv_device, name);
+	if (val)
+		dev_set_param(&global_device, name, val);
+}
+
 int globalvar_add_simple_string(const char *name, char **value)
 {
 	struct param_d *p;
+	int ret;
+
+	ret = globalvar_remove_unqualified(name);
+	if (ret)
+		return ret;
 
 	p = dev_add_param_string(&global_device, name, NULL, NULL,
 		value, NULL);
@@ -447,6 +480,8 @@ int globalvar_add_simple_string(const char *name, char **value)
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
+	globalvar_nv_sync(name);
+
 	return 0;
 }
 
@@ -454,6 +489,11 @@ int globalvar_add_simple_int(const char *name, int *value,
 			     const char *format)
 {
 	struct param_d *p;
+	int ret;
+
+	ret = globalvar_remove_unqualified(name);
+	if (ret)
+		return ret;
 
 	p = dev_add_param_int(&global_device, name, NULL, NULL,
 		value, format, NULL);
@@ -461,12 +501,19 @@ int globalvar_add_simple_int(const char *name, int *value,
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
+	globalvar_nv_sync(name);
+
 	return 0;
 }
 
 int globalvar_add_simple_bool(const char *name, int *value)
 {
 	struct param_d *p;
+	int ret;
+
+	ret = globalvar_remove_unqualified(name);
+	if (ret)
+		return ret;
 
 	p = dev_add_param_bool(&global_device, name, NULL, NULL,
 		value, NULL);
@@ -474,6 +521,8 @@ int globalvar_add_simple_bool(const char *name, int *value)
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
+	globalvar_nv_sync(name);
+
 	return 0;
 }
 
@@ -481,6 +530,11 @@ int globalvar_add_simple_enum(const char *name,	int *value,
 			      const char * const *names, int max)
 {
 	struct param_d *p;
+	int ret;
+
+	ret = globalvar_remove_unqualified(name);
+	if (ret)
+		return ret;
 
 	p = dev_add_param_enum(&global_device, name, NULL, NULL,
 		value, names, max, NULL);
@@ -488,12 +542,19 @@ int globalvar_add_simple_enum(const char *name,	int *value,
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
+	globalvar_nv_sync(name);
+
 	return 0;
 }
 
 int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
 {
 	struct param_d *p;
+	int ret;
+
+	ret = globalvar_remove_unqualified(name);
+	if (ret)
+		return ret;
 
 	p = dev_add_param_ip(&global_device, name, NULL, NULL,
 		ip, NULL);
@@ -501,6 +562,8 @@ int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
+	globalvar_nv_sync(name);
+
 	return 0;
 }
 
diff --git a/include/param.h b/include/param.h
index 3fb4740..68e08a2 100644
--- a/include/param.h
+++ b/include/param.h
@@ -6,6 +6,7 @@
 #include <linux/list.h>
 
 #define PARAM_FLAG_RO	(1 << 0)
+#define PARAM_GLOBALVAR_UNQUALIFIED	(1 << 1)
 
 struct device_d;
 typedef uint32_t          IPaddr_t;
-- 
2.8.1


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-20 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-20 14:26 [PATCH 1/2] globalvar: Move static inline functions to common/ Sascha Hauer
2016-09-20 14:26 ` [PATCH 2/2] globalvar: sync with nvvars Sascha Hauer

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