mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/3] state: consistently pass one type as private data to dev_add_param_*
Date: Tue, 20 Sep 2016 10:30:42 +0200	[thread overview]
Message-ID: <1474360242-3512-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1474360242-3512-1-git-send-email-s.hauer@pengutronix.de>

The different dev_add_param_* calls all use different types as private
data. This is unnecessary, use struct state_variable * for all of them.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/state/state_variables.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 6f2b1ae..efc2456 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -36,9 +36,9 @@
  */
 static int state_set_dirty(struct param_d *p, void *priv)
 {
-	struct state *state = priv;
+	struct state_variable *sv = priv;
 
-	state->dirty = 1;
+	sv->state->dirty = 1;
 
 	return 0;
 }
@@ -90,13 +90,13 @@ static int state_uint32_import(struct state_variable *sv,
 
 static int state_uint8_set(struct param_d *p, void *priv)
 {
-	struct state_uint32 *su32 = priv;
-	struct state *state = su32->var.state;
+	struct state_variable *sv = priv;
+	struct state_uint32 *su32 = to_state_uint32(sv);
 
 	if (su32->value > 255)
 		return -ERANGE;
 
-	return state_set_dirty(p, state);
+	return state_set_dirty(p, sv);
 }
 
 static struct state_variable *state_uint8_create(struct state *state,
@@ -109,7 +109,7 @@ static struct state_variable *state_uint8_create(struct state *state,
 	su32 = xzalloc(sizeof(*su32));
 
 	param = dev_add_param_int(&state->dev, name, state_uint8_set,
-				  NULL, &su32->value, "%u", su32);
+				  NULL, &su32->value, "%u", &su32->var);
 	if (IS_ERR(param)) {
 		free(su32);
 		return ERR_CAST(param);
@@ -137,7 +137,7 @@ static struct state_variable *state_uint32_create(struct state *state,
 	su32 = xzalloc(sizeof(*su32));
 
 	param = dev_add_param_int(&state->dev, name, state_set_dirty,
-				  NULL, &su32->value, "%u", state);
+				  NULL, &su32->value, "%u", &su32->var);
 	if (IS_ERR(param)) {
 		free(su32);
 		return ERR_CAST(param);
@@ -249,7 +249,7 @@ static struct state_variable *state_enum32_create(struct state *state,
 
 	enum32->param = dev_add_param_enum(&state->dev, name, state_set_dirty,
 					   NULL, &enum32->value, enum32->names,
-					   num_names, state);
+					   num_names, &enum32->var);
 	if (IS_ERR(enum32->param)) {
 		ret = PTR_ERR(enum32->param);
 		goto out;
@@ -312,7 +312,7 @@ static struct state_variable *state_mac_create(struct state *state,
 	mac->var.state = state;
 
 	mac->param = dev_add_param_mac(&state->dev, name, state_set_dirty,
-				       NULL, mac->value, state);
+				       NULL, mac->value, &mac->var);
 	if (IS_ERR(mac->param)) {
 		ret = PTR_ERR(mac->param);
 		goto out;
@@ -375,20 +375,21 @@ static int state_string_import(struct state_variable *sv,
 
 static int state_string_set(struct param_d *p, void *priv)
 {
-	struct state_string *string = priv;
-	struct state *state = string->var.state;
+	struct state_variable *sv = priv;
+	struct state_string *string = to_state_string(sv);
 	int ret;
 
 	ret = state_string_copy_to_raw(string, string->value);
 	if (ret)
 		return ret;
 
-	return state_set_dirty(p, state);
+	return state_set_dirty(p, sv->state);
 }
 
 static int state_string_get(struct param_d *p, void *priv)
 {
-	struct state_string *string = priv;
+	struct state_variable *sv = priv;
+	struct state_string *string = to_state_string(sv);
 
 	free(string->value);
 	if (string->raw[0])
@@ -425,7 +426,7 @@ static struct state_variable *state_string_create(struct state *state,
 
 	string->param = dev_add_param_string(&state->dev, name,
 					     state_string_set, state_string_get,
-					     &string->value, string);
+					     &string->value, &string->var);
 	if (IS_ERR(string->param)) {
 		ret = PTR_ERR(string->param);
 		goto out;
-- 
2.8.1


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

      parent reply	other threads:[~2016-09-20  8:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-20  8:30 [PATCH 1/3] state: Add state to state_variable Sascha Hauer
2016-09-20  8:30 ` [PATCH 2/3] state: make locally used function static Sascha Hauer
2016-09-20  8:30 ` Sascha Hauer [this message]

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=1474360242-3512-3-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