[PATCH 11/42] state: backend_circular: Read whole PEB
Sam Ravnborg
sam at ravnborg.org
Sat Apr 15 01:40:17 PDT 2017
On Fri, Mar 31, 2017 at 09:03:15AM +0200, Sascha Hauer wrote:
> When the circular backend searches for the last page written in the
> eraseblock, it iterates backwards pagewise from the end of the block.
> This is ok for NAND flash, but on NOR flash, which does not have pages,
> the code ends up iterating bytewise backwards, calling into mtd each
> time. This is very time consuming, so optimize this by reading the whole
> eraseblock once and just iterate over the buffer in memory.
>
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
> common/state/backend_bucket_circular.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c
> index 0bce900d0d..53c2aae803 100644
> --- a/common/state/backend_bucket_circular.c
> +++ b/common/state/backend_bucket_circular.c
> @@ -379,26 +379,24 @@ static int state_backend_bucket_circular_init(
> int sub_offset;
> uint32_t written_length = 0;
> uint8_t *buf;
> + int ret;
>
> - buf = xmalloc(circ->writesize);
> + buf = xmalloc(circ->max_size);
> if (!buf)
> return -ENOMEM;
>
> + ret = state_mtd_peb_read(circ, buf, 0, circ->max_size);
> + if (ret && ret != -EUCLEAN)
> + return ret;
We leak buf here.
But ownership of buf is vague.
In one implementation of state_mtd_peb_read() we free buf
in case of errors, but not in all paths.
This is the version of state_mtd_peb_read() outside the
#ifdef __BAREBOX__
block.
The version of state_mtd_peb_read() inside the
#ifdef __BAREBOX__
will not free buf, so there ownership is more clear.
But in both cases we may leak buf.
This is as such unrelated to this patch - but noticed while browsing these
patches.
Sam
More information about the barebox
mailing list