mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] state: refuse to set dirty parameter via setenv
@ 2018-02-06  7:47 Sascha Hauer
  2018-02-06  7:47 ` [PATCH 2/2] state: Add 'init_from_defaults' parameter Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2018-02-06  7:47 UTC (permalink / raw)
  To: Barebox List

The dirty parameter is readonly, so refuse to set it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/state/state.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/common/state/state.c b/common/state/state.c
index 6399bd3736..5a1a1af856 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -153,6 +153,11 @@ void state_backend_set_readonly(struct state *state)
 	state_storage_set_readonly(&state->storage);
 }
 
+static int state_set_deny(struct param_d *p, void *priv)
+{
+	return -EROFS;
+}
+
 static struct state *state_new(const char *name)
 {
 	struct state *state;
@@ -172,7 +177,7 @@ static struct state *state_new(const char *name)
 	}
 
 	state->dirty = 1;
-	dev_add_param_bool(&state->dev, "dirty", NULL, NULL, &state->dirty,
+	dev_add_param_bool(&state->dev, "dirty", state_set_deny, NULL, &state->dirty,
 			   NULL);
 	state->save_on_shutdown = 1;
 	dev_add_param_bool(&state->dev, "save_on_shutdown", NULL, NULL,
-- 
2.15.1


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] state: Add 'init_from_defaults' parameter
  2018-02-06  7:47 [PATCH 1/2] state: refuse to set dirty parameter via setenv Sascha Hauer
@ 2018-02-06  7:47 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2018-02-06  7:47 UTC (permalink / raw)
  To: Barebox List

The init_from_defaults parameter allows to detect if a state has been
initialized from default values, i.e. state_load failed.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/state/state.c | 7 +++++++
 common/state/state.h | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/common/state/state.c b/common/state/state.c
index 5a1a1af856..cb979328c1 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -99,6 +99,7 @@ static int state_do_load(struct state *state, enum state_flags flags)
 		goto out;
 	}
 
+	state->init_from_defaults = 0;
 	state->dirty = 0;
 
 out:
@@ -179,10 +180,14 @@ static struct state *state_new(const char *name)
 	state->dirty = 1;
 	dev_add_param_bool(&state->dev, "dirty", state_set_deny, NULL, &state->dirty,
 			   NULL);
+
 	state->save_on_shutdown = 1;
 	dev_add_param_bool(&state->dev, "save_on_shutdown", NULL, NULL,
 			   &state->save_on_shutdown, NULL);
 
+	dev_add_param_bool(&state->dev, "init_from_defaults", state_set_deny, NULL,
+			   &state->init_from_defaults, NULL);
+
 	list_add_tail(&state->list, &state_list);
 
 	return state;
@@ -643,6 +648,8 @@ struct state *state_new_from_node(struct device_node *node, char *path,
 		goto out_release_state;
 	}
 
+	state->init_from_defaults = 1;
+
 	ret = of_register_fixup(of_state_fixup, state);
 	if (ret) {
 		goto out_release_state;
diff --git a/common/state/state.h b/common/state/state.h
index fcc6b9f5cd..da1c6acaeb 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -107,7 +107,9 @@ struct state {
 	uint32_t magic;
 
 	struct list_head variables; /* Sorted list of variables */
+
 	unsigned int dirty;
+	unsigned int init_from_defaults;
 	unsigned int save_on_shutdown;
 
 	struct state_backend_format *format;
-- 
2.15.1


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-06  7:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-06  7:47 [PATCH 1/2] state: refuse to set dirty parameter via setenv Sascha Hauer
2018-02-06  7:47 ` [PATCH 2/2] state: Add 'init_from_defaults' parameter Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox