summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2015-05-26 13:37:47 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2015-05-26 14:33:18 +0200
commit7ea826343bbff842b360d6e949217aa7da9c9e12 (patch)
treec063a1ed7e4fe2f9e7933093d0455ca0e068afb9 /common
parent23846b7301d803c845f5b5db64f50c084e61519d (diff)
downloadbarebox-7ea826343bbff842b360d6e949217aa7da9c9e12.tar.gz
barebox-7ea826343bbff842b360d6e949217aa7da9c9e12.tar.xz
state: backend_raw: remove hard coded limit of two copies
Although there is the define RAW_BACKEND_COPIES, the state_backend_raw_save() function silently assumes exactly two copies. This patch removes that assumtion by looping over all copies, but saving the one we're read from at the end. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/state.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/common/state.c b/common/state.c
index dab51e39a5..facae84d21 100644
--- a/common/state.c
+++ b/common/state.c
@@ -1167,7 +1167,7 @@ static int state_backend_raw_save(struct state_backend *backend,
{
struct state_backend_raw *backend_raw = container_of(backend,
struct state_backend_raw, backend);
- int ret = 0, size, fd;
+ int ret = 0, size, fd, i;
void *buf, *data;
struct backend_raw_header *header;
struct state_variable *sv;
@@ -1192,10 +1192,17 @@ static int state_backend_raw_save(struct state_backend *backend,
if (fd < 0)
goto out_free;
- ret = backend_raw_write_one(backend_raw, state, fd,
- !backend_raw->num_copy_read, buf, size);
- if (ret)
- goto out_close;
+ /* save other slots first */
+ for (i = 0; i < RAW_BACKEND_COPIES; i++) {
+ if (i == backend_raw->num_copy_read)
+ continue;
+
+ ret = backend_raw_write_one(backend_raw, state, fd,
+ i, buf, size);
+ if (ret)
+ goto out_close;
+
+ }
ret = backend_raw_write_one(backend_raw, state, fd,
backend_raw->num_copy_read, buf, size);