Re: [PATCH 1/3] pinctrl: mcp23s08: check return value of devm_kasprintf()

From: Andy Shevchenko
Date: Thu Jun 15 2023 - 07:02:56 EST


On Thu, Jun 15, 2023 at 01:53:31PM +0300, Claudiu Beznea wrote:
> devm_kasprintf() returns a pointer to dynamically allocated memory.
> Pointer could be NULL in case allocation fails. Check pointer validity.
> Identified with coccinelle (kmerr.cocci script).

Not that this may happen, but okay.

...

> @@ -119,6 +119,9 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev,
> return -EINVAL;
> }
>
> + if (!name || !mcp->chip.label)
> + return -ENOMEM;

I prefer to see 4 independent checks for each of the devm_kasprintf() calls.

--
With Best Regards,
Andy Shevchenko