mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* device parameter patches
@ 2012-04-24  9:21 Sascha Hauer
  2012-04-24  9:21 ` [PATCH 1/3] param: make return value of param getter function const Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-04-24  9:21 UTC (permalink / raw)
  To: barebox

Some device parameter patches.

Sascha

----------------------------------------------------------------
Sascha Hauer (3):
      param: make return value of param getter function const
      devinfo: use accessor function for parameters
      dev_add_param: check if param exists already

 drivers/base/driver.c |    2 +-
 include/param.h       |    6 +++---
 lib/parameter.c       |   14 +++++++++-----
 3 files changed, 13 insertions(+), 9 deletions(-)

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

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

* [PATCH 1/3] param: make return value of param getter function const
  2012-04-24  9:21 device parameter patches Sascha Hauer
@ 2012-04-24  9:21 ` Sascha Hauer
  2012-04-24  9:21 ` [PATCH 2/3] devinfo: use accessor function for parameters Sascha Hauer
  2012-04-24  9:21 ` [PATCH 3/3] dev_add_param: check if param exists already Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-04-24  9:21 UTC (permalink / raw)
  To: barebox

The string returned by the getter function should not be
changed. Make it const.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/param.h |    6 +++---
 lib/parameter.c |   10 +++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/param.h b/include/param.h
index 4a39dc7..e7b66a4 100644
--- a/include/param.h
+++ b/include/param.h
@@ -10,7 +10,7 @@ struct device_d;
 typedef unsigned long          IPaddr_t;
 
 struct param_d {
-	char* (*get)(struct device_d *, struct param_d *param);
+	const char* (*get)(struct device_d *, struct param_d *param);
 	int (*set)(struct device_d *, struct param_d *param, const char *val);
 	unsigned int flags;
 	char *name;
@@ -24,9 +24,9 @@ const char *dev_get_param(struct device_d *dev, const char *name);
 int dev_set_param(struct device_d *dev, const char *name, const char *val);
 struct param_d *get_param_by_name(struct device_d *dev, const char *name);
 
-int dev_add_param(struct device_d *dev, char *name,
+int dev_add_param(struct device_d *dev, const char *name,
 		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
-		char *(*get)(struct device_d *, struct param_d *p),
+		const char *(*get)(struct device_d *, struct param_d *p),
 		unsigned long flags);
 
 int dev_add_param_fixed(struct device_d *dev, char *name, char *value);
diff --git a/lib/parameter.c b/lib/parameter.c
index 5a7ae1a..e746467 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -133,14 +133,14 @@ int dev_param_set_generic(struct device_d *dev, struct param_d *p,
 	return 0;
 }
 
-static char *param_get_generic(struct device_d *dev, struct param_d *p)
+static const char *param_get_generic(struct device_d *dev, struct param_d *p)
 {
 	return p->value;
 }
 
-static struct param_d *__dev_add_param(struct device_d *dev, char *name,
+static struct param_d *__dev_add_param(struct device_d *dev, const char *name,
 		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
-		char *(*get)(struct device_d *dev, struct param_d *p),
+		const char *(*get)(struct device_d *dev, struct param_d *p),
 		unsigned long flags)
 {
 	struct param_d *param;
@@ -176,9 +176,9 @@ static struct param_d *__dev_add_param(struct device_d *dev, char *name,
  * expect the parameter value to be a string which can be freed with free(). Do
  * not use static arrays when using the generic functions.
  */
-int dev_add_param(struct device_d *dev, char *name,
+int dev_add_param(struct device_d *dev, const char *name,
 		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
-		char *(*get)(struct device_d *dev, struct param_d *param),
+		const char *(*get)(struct device_d *dev, struct param_d *param),
 		unsigned long flags)
 {
 	struct param_d *param;
-- 
1.7.10


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

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

* [PATCH 2/3] devinfo: use accessor function for parameters
  2012-04-24  9:21 device parameter patches Sascha Hauer
  2012-04-24  9:21 ` [PATCH 1/3] param: make return value of param getter function const Sascha Hauer
@ 2012-04-24  9:21 ` Sascha Hauer
  2012-04-24  9:21 ` [PATCH 3/3] dev_add_param: check if param exists already Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-04-24  9:21 UTC (permalink / raw)
  To: barebox

Instead of directly accessing the struct member of struct param_d
use the provided getter function.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/base/driver.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 2d206f9..9924fee 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -401,7 +401,7 @@ static int do_devinfo(int argc, char *argv[])
 				"no parameters available" : "Parameters:");
 
 		list_for_each_entry(param, &dev->parameters, list)
-			printf("%16s = %s\n", param->name, param->value);
+			printf("%16s = %s\n", param->name, dev_get_param(dev, param->name));
 	}
 
 	return 0;
-- 
1.7.10


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

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

* [PATCH 3/3] dev_add_param: check if param exists already
  2012-04-24  9:21 device parameter patches Sascha Hauer
  2012-04-24  9:21 ` [PATCH 1/3] param: make return value of param getter function const Sascha Hauer
  2012-04-24  9:21 ` [PATCH 2/3] devinfo: use accessor function for parameters Sascha Hauer
@ 2012-04-24  9:21 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-04-24  9:21 UTC (permalink / raw)
  To: barebox

Before adding a new parameter to a device we should check if
it already exists.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/parameter.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/parameter.c b/lib/parameter.c
index e746467..baf7720 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -183,6 +183,10 @@ int dev_add_param(struct device_d *dev, const char *name,
 {
 	struct param_d *param;
 
+	param = get_param_by_name(dev, name);
+	if (param)
+		return -EEXIST;
+
 	param = __dev_add_param(dev, name, set, get, flags);
 
 	return param ? 0 : -EINVAL;
-- 
1.7.10


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

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

end of thread, other threads:[~2012-04-24  9:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-24  9:21 device parameter patches Sascha Hauer
2012-04-24  9:21 ` [PATCH 1/3] param: make return value of param getter function const Sascha Hauer
2012-04-24  9:21 ` [PATCH 2/3] devinfo: use accessor function for parameters Sascha Hauer
2012-04-24  9:21 ` [PATCH 3/3] dev_add_param: check if param exists already Sascha Hauer

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