[PATCH] ubifs: using vmalloc_array() to handle the code

Zhihao Cheng chengzhihao1 at huawei.com
Wed Oct 22 01:14:13 PDT 2025


在 2025/10/22 16:02, tanze 写道:
> Change array_size() to vmalloc_array(), Due to vmalloc_array()
> is optimized better,uses fewer instructions, and handles
> overflow more concisely
> 
> Signed-off-by: tanze <tanze at kylinos.cn>
> ---
>   fs/ubifs/lpt.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
> 

Reviewed-by: Zhihao Cheng <chengzhihao1 at huawei.com>
> diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
> index 441d0beca4cf..dde0aa3287f4 100644
> --- a/fs/ubifs/lpt.c
> +++ b/fs/ubifs/lpt.c
> @@ -628,8 +628,8 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
>   	pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL);
>   	nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_KERNEL);
>   	buf = vmalloc(c->leb_size);
> -	ltab = vmalloc(array_size(sizeof(struct ubifs_lpt_lprops),
> -				  c->lpt_lebs));
> +	ltab = vmalloc_array(c->lpt_lebs,
> +			     sizeof(struct ubifs_lpt_lprops));
>   	if (!pnode || !nnode || !buf || !ltab || !lsave) {
>   		err = -ENOMEM;
>   		goto out;
> @@ -1777,8 +1777,8 @@ static int lpt_init_rd(struct ubifs_info *c)
>   {
>   	int err, i;
>   
> -	c->ltab = vmalloc(array_size(sizeof(struct ubifs_lpt_lprops),
> -				     c->lpt_lebs));
> +	c->ltab = vmalloc_array(c->lpt_lebs,
> +				sizeof(struct ubifs_lpt_lprops));
>   	if (!c->ltab)
>   		return -ENOMEM;
>   
> @@ -1846,8 +1846,8 @@ static int lpt_init_wr(struct ubifs_info *c)
>   {
>   	int err, i;
>   
> -	c->ltab_cmt = vmalloc(array_size(sizeof(struct ubifs_lpt_lprops),
> -					 c->lpt_lebs));
> +	c->ltab_cmt = vmalloc_array(c->lpt_lebs,
> +				    sizeof(struct ubifs_lpt_lprops));
>   	if (!c->ltab_cmt)
>   		return -ENOMEM;
>   
> 




More information about the linux-mtd mailing list