[PATCH v2] mtd: Add check and kfree() for kcalloc()

Miquel Raynal miquel.raynal at bootlin.com
Tue Feb 4 01:17:07 PST 2025


Hello,

> --- a/drivers/mtd/mtdpstore.c
> +++ b/drivers/mtd/mtdpstore.c
> @@ -418,10 +418,17 @@ static void mtdpstore_notify_add(struct mtd_info *mtd)
>  
>  	longcnt = BITS_TO_LONGS(div_u64(mtd->size, info->kmsg_size));
>  	cxt->rmmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
> +	if (!cxt->rmmap)
> +		goto end;

We prefer to return immediately in this case.

Also, any reasons not to use devm_kcalloc()? This would be the correct
approach as of today as long as the lifetime of the device is known.

Thanks,
Miquèl



More information about the linux-mtd mailing list