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

Andy Shevchenko andriy.shevchenko at linux.intel.com
Thu Jun 15 04:02:46 PDT 2023


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





More information about the linux-arm-kernel mailing list