* [PATCH 1/3] state: Add state to state_variable
@ 2016-09-20 8:30 Sascha Hauer
2016-09-20 8:30 ` [PATCH 2/3] state: make locally used function static Sascha Hauer
2016-09-20 8:30 ` [PATCH 3/3] state: consistently pass one type as private data to dev_add_param_* Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2016-09-20 8:30 UTC (permalink / raw)
To: Barebox List
A state variable should know which state it belongs to. Add field
for it to struct state_variable.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/state/state.h | 3 +--
common/state/state_variables.c | 11 +++++++----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/common/state/state.h b/common/state/state.h
index 7b3e495..855ba9d 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -138,6 +138,7 @@ struct variable_type {
/* instance of a single variable */
struct state_variable {
+ struct state *state;
enum state_variable_type type;
struct list_head list;
const char *name;
@@ -152,7 +153,6 @@ struct state_variable {
struct state_uint32 {
struct state_variable var;
struct param_d *param;
- struct state *state;
uint32_t value;
uint32_t value_default;
};
@@ -185,7 +185,6 @@ struct state_mac {
struct state_string {
struct state_variable var;
struct param_d *param;
- struct state *state;
char *value;
const char *value_default;
char raw[];
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 0d2a626..4f82462 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -91,7 +91,7 @@ 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->state;
+ struct state *state = su32->var.state;
if (su32->value > 255)
return -ERANGE;
@@ -122,7 +122,7 @@ static struct state_variable *state_uint8_create(struct state *state,
#else
su32->var.raw = &su32->value + 3;
#endif
- su32->state = state;
+ su32->var.state = state;
return &su32->var;
}
@@ -146,6 +146,7 @@ static struct state_variable *state_uint32_create(struct state *state,
su32->param = param;
su32->var.size = sizeof(uint32_t);
su32->var.raw = &su32->value;
+ su32->var.state = state;
return &su32->var;
}
@@ -235,6 +236,7 @@ static struct state_variable *state_enum32_create(struct state *state,
enum32->num_names = num_names;
enum32->var.size = sizeof(uint32_t);
enum32->var.raw = &enum32->value;
+ enum32->var.state = state;
for (i = 0; i < num_names; i++) {
const char *name;
@@ -307,6 +309,7 @@ static struct state_variable *state_mac_create(struct state *state,
mac->var.size = ARRAY_SIZE(mac->value);
mac->var.raw = mac->value;
+ mac->var.state = state;
mac->param = dev_add_param_mac(&state->dev, name, state_set_dirty,
NULL, mac->value, state);
@@ -373,7 +376,7 @@ 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->state;
+ struct state *state = string->var.state;
int ret;
ret = state_string_copy_to_raw(string, string->value);
@@ -418,7 +421,7 @@ static struct state_variable *state_string_create(struct state *state,
string = xzalloc(sizeof(*string) + start_size[1]);
string->var.size = start_size[1];
string->var.raw = &string->raw;
- string->state = state;
+ string->var.state = state;
string->param = dev_add_param_string(&state->dev, name,
state_string_set, state_string_get,
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/3] state: make locally used function static
2016-09-20 8:30 [PATCH 1/3] state: Add state to state_variable Sascha Hauer
@ 2016-09-20 8:30 ` Sascha Hauer
2016-09-20 8:30 ` [PATCH 3/3] state: consistently pass one type as private data to dev_add_param_* Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2016-09-20 8:30 UTC (permalink / raw)
To: Barebox List
state_set_dirty() is only used in one file, make it static.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/state/state.h | 1 -
common/state/state_variables.c | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/common/state/state.h b/common/state/state.h
index 855ba9d..bc6917d 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -190,7 +190,6 @@ struct state_string {
char raw[];
};
-int state_set_dirty(struct param_d *p, void *priv);
int state_from_node(struct state *state, struct device_node *node, bool create);
struct device_node *state_to_node(struct state *state,
struct device_node *parent,
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 4f82462..6f2b1ae 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -34,7 +34,7 @@
* @param priv
* @return
*/
-int state_set_dirty(struct param_d *p, void *priv)
+static int state_set_dirty(struct param_d *p, void *priv)
{
struct state *state = priv;
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 3/3] state: consistently pass one type as private data to dev_add_param_*
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
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2016-09-20 8:30 UTC (permalink / raw)
To: Barebox List
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-09-20 8:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 3/3] state: consistently pass one type as private data to dev_add_param_* Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox