[PATCH] param: let dev_add_param return the newly created param

Sascha Hauer s.hauer at pengutronix.de
Wed Oct 8 07:34:52 PDT 2014


dev_add_param creates a new parameter so it makes more sense to
return it than to return an error code. Since the return value
is hardly ever checked this is only a small patch.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/globalvar.c | 7 ++++++-
 include/param.h    | 4 ++--
 lib/parameter.c    | 8 +++++---
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index 1f9b0cc..c72f147 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -17,7 +17,12 @@ int globalvar_add(const char *name,
 		const char *(*get)(struct device_d *, struct param_d *p),
 		unsigned long flags)
 {
-	return dev_add_param(&global_device, name, set, get, flags);
+	struct param_d *param;
+
+	param = dev_add_param(&global_device, name, set, get, flags);
+	if (IS_ERR(param))
+		return PTR_ERR(param);
+	return 0;
 }
 
 /*
diff --git a/include/param.h b/include/param.h
index 9856a2e..b8dd9b1 100644
--- a/include/param.h
+++ b/include/param.h
@@ -26,7 +26,7 @@ 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, const char *name,
+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),
 		const char *(*get)(struct device_d *, struct param_d *p),
 		unsigned long flags);
@@ -92,7 +92,7 @@ static inline struct param_d *get_param_by_name(struct device_d *dev,
 	return NULL;
 }
 
-static inline int dev_add_param(struct device_d *dev, char *name,
+static inline struct param_d *dev_add_param(struct device_d *dev, char *name,
 		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
 		const char *(*get)(struct device_d *, struct param_d *p),
 		unsigned long flags)
diff --git a/lib/parameter.c b/lib/parameter.c
index 84a632c..d6f8d16 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -160,7 +160,7 @@ static int __dev_add_param(struct param_d *param, struct device_d *dev, const ch
  * 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, const char *name,
+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),
 		const char *(*get)(struct device_d *dev, struct param_d *param),
 		unsigned long flags)
@@ -171,10 +171,12 @@ int dev_add_param(struct device_d *dev, const char *name,
 	param = xzalloc(sizeof(*param));
 
 	ret = __dev_add_param(param, dev, name, set, get, flags);
-	if (ret)
+	if (ret) {
 		free(param);
+		return ERR_PTR(ret);
+	}
 
-	return ret;
+	return param;
 }
 
 /**
-- 
2.1.0




More information about the barebox mailing list