From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZqSSN-0008F4-Dm for barebox@lists.infradead.org; Sun, 25 Oct 2015 21:04:00 +0000 From: Marc Kleine-Budde Date: Sun, 25 Oct 2015 22:03:35 +0100 Message-Id: <1445807016-6637-9-git-send-email-mkl@pengutronix.de> In-Reply-To: <1445807016-6637-1-git-send-email-mkl@pengutronix.de> References: <1445807016-6637-1-git-send-email-mkl@pengutronix.de> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH v3 8/9] state: prepare raw backend for hmac support To: barebox@lists.infradead.org This patch cleans up the raw backend, so that adding hmac support in the next patch is easier. Signed-off-by: Marc Kleine-Budde --- 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