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

Michael Ellerman mpe at ellerman.id.au
Thu Oct 19 12:16:17 AEDT 2023


Yi Yang <yiyang13 at huawei.com> writes:
> The devm_kasprintf() returns a pointer to dynamically allocated memory.
> that will return NULL when allocate failed.
> Fix it by check return value of devm_kasprintf().
>
> Fixes: acfe63ec1c59 ("mtd: Convert to using %pOFn instead of device_node.name")
> Signed-off-by: Yi Yang <yiyang13 at huawei.com>
> ---
>  drivers/mtd/devices/powernv_flash.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/mtd/devices/powernv_flash.c b/drivers/mtd/devices/powernv_flash.c
> index 66044f4f5bad..b305e555ddbf 100644
> --- a/drivers/mtd/devices/powernv_flash.c
> +++ b/drivers/mtd/devices/powernv_flash.c
> @@ -207,6 +207,10 @@ static int powernv_flash_set_driver_info(struct device *dev,
>  	 * get them
>  	 */
>  	mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
> +	if (mtd->name) {

That seems like the wrong check?

cheers

> +		dev_err(dev, "failed to allocate mtd->name\n");
> +		return -ENOMEM;
> +	}
>  	mtd->type = MTD_NORFLASH;
>  	mtd->flags = MTD_WRITEABLE;
>  	mtd->size = size;
> -- 
> 2.25.1


More information about the Linuxppc-dev mailing list