[PATCH] mtd: rawnand: meson: check return value of devm_kasprintf()

Miquel Raynal miquel.raynal at bootlin.com
Wed Oct 18 05:19:36 PDT 2023


Hi Yi,

yiyang13 at huawei.com wrote on Wed, 18 Oct 2023 09:20:47 +0000:

> The devm_kasprintf() returns a pointer to dynamically allocated memory.
> that will return NULL when allocate failed.

May I propose rewording of the commit log?
"
devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful by
checking the pointer validity.
"

> Fix it by check return value of devm_kasprintf().
> 
> Fixes: 1e4d3ba66888 ("mtd: rawnand: meson: fix the clock")
> Signed-off-by: Yi Yang <yiyang13 at huawei.com>
> ---
>  drivers/mtd/nand/raw/meson_nand.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
> index 378f28ce6a74..2c6ae781bb0c 100644
> --- a/drivers/mtd/nand/raw/meson_nand.c
> +++ b/drivers/mtd/nand/raw/meson_nand.c
> @@ -1134,6 +1134,11 @@ static int meson_nfc_clk_init(struct meson_nfc *nfc)
>  	init.name = devm_kasprintf(nfc->dev,
>  				   GFP_KERNEL, "%s#div",
>  				   dev_name(nfc->dev));
> +	if (init.name) {
> +		dev_err(nfc->dev, "failed to allocate init.name\n");

No need for error messages upon memory allocation failures.

> +		return -ENOMEM;
> +	}
> +
>  	init.ops = &clk_divider_ops;
>  	nfc_divider_parent_data[0].fw_name = "device";
>  	init.parent_data = nfc_divider_parent_data;

These comments are also applicable to your two other patches.

Thanks,
Miquèl



More information about the linux-mtd mailing list