Re: [PATCH v2] mtd: Add check and kfree() for kcalloc()
From: Miquel Raynal
Date: Tue Feb 04 2025 - 04:17:37 EST
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