mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] param: let dev_add_param return the newly created param
Date: Wed,  8 Oct 2014 16:34:52 +0200	[thread overview]
Message-ID: <1412778892-22976-1-git-send-email-s.hauer@pengutronix.de> (raw)

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


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

                 reply	other threads:[~2014-10-08 14:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1412778892-22976-1-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