mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v3 8/9] state: prepare raw backend for hmac support
Date: Sun, 25 Oct 2015 22:03:35 +0100	[thread overview]
Message-ID: <1445807016-6637-9-git-send-email-mkl@pengutronix.de> (raw)
In-Reply-To: <1445807016-6637-1-git-send-email-mkl@pengutronix.de>

This patch cleans up the raw backend, so that adding hmac support in the next
patch is easier.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 common/state.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/common/state.c b/common/state.c
index fdb5564af3bd..d37f4ab4b539 100644
--- a/common/state.c
+++ b/common/state.c
@@ -1254,7 +1254,7 @@ static int backend_raw_load_one(struct state_backend_raw *backend_raw,
 	struct backend_raw_header header = {};
 	unsigned long max_len;
 	int ret;
-	void *buf;
+	void *buf, *data;
 
 	max_len = backend_raw->stride;
 
@@ -1292,13 +1292,18 @@ static int backend_raw_load_one(struct state_backend_raw *backend_raw,
 		return -EINVAL;
 	}
 
-	buf = xzalloc(header.data_len);
+	buf = xzalloc(sizeof(header) + header.data_len);
+	data = buf + sizeof(header);
+
+	ret = lseek(fd, offset, SEEK_SET);
+	if (ret < 0)
+		goto out_free;
 
-	ret = read_full(fd, buf, header.data_len);
+	ret = read_full(fd, buf, sizeof(header) + header.data_len);
 	if (ret < 0)
 		goto out_free;
 
-	crc = crc32(0, buf, header.data_len);
+	crc = crc32(0, data, header.data_len);
 	if (crc != header.data_crc) {
 		dev_err(&state->dev,
 			"invalid crc, calculated 0x%08x, found 0x%08x\n",
@@ -1310,7 +1315,7 @@ static int backend_raw_load_one(struct state_backend_raw *backend_raw,
 	list_for_each_entry(sv, &state->variables, list) {
 		if (sv->start + sv->size > header.data_len)
 			break;
-		memcpy(sv->raw, buf + sv->start, sv->size);
+		memcpy(sv->raw, data + sv->start, sv->size);
 	}
 
 	free(buf);
-- 
2.6.1


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

  parent reply	other threads:[~2015-10-25 21:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-25 21:03 [PATCH v3 0/8] state framework enhancements Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 1/9] of_path: of_find_path() factor out device detection logic into separate function Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 2/9] of_path: add of_find_path_by_node() Marc Kleine-Budde
2015-10-28  6:20   ` Sascha Hauer
2015-10-28  8:26     ` Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 3/9] state: make use of of_find_path_by_node() and add return -EPROBE_DEFER if device is not available Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 4/9] state: use name of device node as name if alias " Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 5/9] state: disable load command Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 6/9] crypto: Kconfig: add submenu for crypto related config options Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 7/9] crypto: add simple keystore Marc Kleine-Budde
2015-10-25 21:03 ` Marc Kleine-Budde [this message]
2015-10-25 21:03 ` [PATCH v3 9/9] state: backend_raw: add hamc support Marc Kleine-Budde
2015-10-28  6:24   ` Sascha Hauer

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=1445807016-6637-9-git-send-email-mkl@pengutronix.de \
    --to=mkl@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