diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2016-09-14 12:32:10 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-09-20 10:29:01 +0200 |
commit | 3a690e4d6976517315f1dd73334920d749a28755 (patch) | |
tree | efc42f7961d65db235578a558abd8e15a5f44fbf | |
parent | 8c6ca8acc581fee5db9482985d291b4d5a6b67f7 (diff) | |
download | barebox-3a690e4d6976517315f1dd73334920d749a28755.tar.gz barebox-3a690e4d6976517315f1dd73334920d749a28755.tar.xz |
state: Add state to state_variable
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>
-rw-r--r-- | common/state/state.h | 3 | ||||
-rw-r--r-- | 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 7b3e49512e..855ba9d868 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 0d2a626a23..4f8246249d 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, |