Re: [PATCH] misc: tps6594-pfsm: Add NULL check in tps6594_pfsm_probe

From: Greg KH
Date: Thu Apr 10 2025 - 07:51:47 EST


On Thu, Apr 10, 2025 at 06:52:53PM +0800, Charles Han wrote:
> devm_kasprintf() can return a NULL pointer on failure,but this
> returned value in tps6594_pfsm_probe() is not checked.
> Add NULL check in tps6594_pfsm_probe(), to handle kernel NULL
> pointer dereference error.
>
> Fixes: a0df3ef087f8 ("misc: tps6594-pfsm: Add driver for TI TPS6594 PFSM")
> Signed-off-by: Charles Han <hanchunchao@xxxxxxxxxx>
> ---
> drivers/misc/tps6594-pfsm.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/misc/tps6594-pfsm.c b/drivers/misc/tps6594-pfsm.c
> index 0a24ce44cc37..05c4e081a8d2 100644
> --- a/drivers/misc/tps6594-pfsm.c
> +++ b/drivers/misc/tps6594-pfsm.c
> @@ -281,6 +281,11 @@ static int tps6594_pfsm_probe(struct platform_device *pdev)
> pfsm->miscdev.minor = MISC_DYNAMIC_MINOR;
> pfsm->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "pfsm-%ld-0x%02x",
> tps->chip_id, tps->reg);
> + if (!pfsm->miscdev.name) {
> + devm_kfree(dev, pfsm);
> + return -ENOMEM;
> + }

How was this found and tested?

thanks,

greg k-h