[RFC][PATCH] ubi: Implement a read cache

David Gstir david at sigma-star.at
Mon Jul 18 01:05:18 PDT 2016


Hi!

> On 15.07.2016, at 14:57, Richard Weinberger <richard at nod.at> wrote:

<snip>

> +static int read_cache_init(struct ubi_device *ubi)
> +{
> +	int i;
> +	struct ubi_read_cache_line *line;
> +	struct ubi_read_cache *read_cache = kzalloc(sizeof(*read_cache),
> +						    GFP_KERNEL);
> +
> +	if (!read_cache)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < UBI_READ_CACHE_LINES; i++) {
> +		line = &read_cache->lines[i];
> +
> +		mutex_init(&line->line_lock);
> +		line->buf = kmalloc(ubi->mtd->writesize, GFP_KERNEL);
> +		line->pnum = line->offset = -1;
> +		if (!line->buf)
> +			goto err_nomem;
> +	}
> +
> +	read_cache->buflen = ubi->mtd->writesize;
> +
> +	ubi->read_cache = read_cache;
> +
> +	return 0;
> +
> +err_nomem:
> +	for (i = 0; i < UBI_READ_CACHE_LINES; i++) {
> +		line = &read_cache->lines[i];
> +		kfree(line->buf);
> +	}

You're missing a kfree(read_cache); here. :)

> +
> +	return -ENOMEM;
> +}
> 

Will test the patch today.

-David




More information about the linux-mtd mailing list