[PATCH 7/7] UBI: provide helpers to allocate and free aeb elements

Boris Brezillon boris.brezillon at free-electrons.com
Fri Aug 26 02:02:09 PDT 2016


On Tue, 23 Aug 2016 09:32:54 +0200
Boris Brezillon <boris.brezillon at free-electrons.com> wrote:

> This not only hides the aeb allocation internals (which is always good in
> case we ever want to change the allocation system), but also helps us
> factorize the initialization of some common fields (ec and pnum).
> 
> Signed-off-by: Boris Brezillon <boris.brezillon at free-electrons.com>
> ---
>  drivers/mtd/ubi/attach.c  | 68 ++++++++++++++++++++++++++++++++++-------------
>  drivers/mtd/ubi/fastmap.c | 28 +++++++------------
>  drivers/mtd/ubi/ubi.h     |  3 +++
>  drivers/mtd/ubi/vtbl.c    |  4 +--
>  4 files changed, 65 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
> index be83c17d742b..ba88ff582f1a 100644
> --- a/drivers/mtd/ubi/attach.c
> +++ b/drivers/mtd/ubi/attach.c
> @@ -182,6 +182,46 @@ static struct ubi_ainf_volume *ubi_find_or_add_av(struct ubi_attach_info *ai,
>  }
>  
>  /**
> + * ubi_alloc_aeb - allocate an aeb element
> + * @ai: attaching information
> + * @aeb: the element to free

The kernel doc is wrong. I'll fix that in v2.

> + *
> + * Allocate an aeb object and initialize the pnum and ec information.
> + * vol_id and lnum are set to UBI_UNKNOWN, and the other fields are
> + * initialized to zero.
> + * Note that the element is not added in any list or RB tree.
> + */
> +struct ubi_ainf_peb *ubi_alloc_aeb(struct ubi_attach_info *ai, int pnum,
> +				   int ec)
> +{
> +	struct ubi_ainf_peb *aeb;
> +
> +	aeb = kmem_cache_zalloc(ai->aeb_slab_cache, GFP_KERNEL);
> +	if (!aeb)
> +		return NULL;
> +
> +	aeb->pnum = pnum;
> +	aeb->ec = ec;
> +	aeb->vol_id = UBI_UNKNOWN;
> +	aeb->lnum = UBI_UNKNOWN;
> +
> +	return aeb;
> +}
> +




More information about the linux-mtd mailing list