mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Claudiu Beznea <claudiu.beznea@microchip.com>
Cc: linus.walleij@linaro.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] pinctrl: mcp23s08: check return value of devm_kasprintf()
Date: Wed, 21 Jun 2023 16:36:00 +0300	[thread overview]
Message-ID: <ZJL8wPGxs9SDquQi@smile.fi.intel.com> (raw)
In-Reply-To: <20230621100409.1608395-1-claudiu.beznea@microchip.com>

On Wed, Jun 21, 2023 at 01:04:09PM +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).

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Fixes: 0f04a81784fe ("pinctrl: mcp23s08: Split to three parts: core, I²C, SPI")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
> 
> Changes in v2:
> - use independent checks for devm_kasprintf()
> 
>  drivers/pinctrl/pinctrl-mcp23s08_spi.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/pinctrl/pinctrl-mcp23s08_spi.c b/drivers/pinctrl/pinctrl-mcp23s08_spi.c
> index 9ae10318f6f3..ea059b9c5542 100644
> --- a/drivers/pinctrl/pinctrl-mcp23s08_spi.c
> +++ b/drivers/pinctrl/pinctrl-mcp23s08_spi.c
> @@ -91,18 +91,28 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev,
>  		mcp->reg_shift = 0;
>  		mcp->chip.ngpio = 8;
>  		mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s08.%d", addr);
> +		if (!mcp->chip.label)
> +			return -ENOMEM;
>  
>  		config = &mcp23x08_regmap;
>  		name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr);
> +		if (!name)
> +			return -ENOMEM;
> +
>  		break;
>  
>  	case MCP_TYPE_S17:
>  		mcp->reg_shift = 1;
>  		mcp->chip.ngpio = 16;
>  		mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s17.%d", addr);
> +		if (!mcp->chip.label)
> +			return -ENOMEM;
>  
>  		config = &mcp23x17_regmap;
>  		name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr);
> +		if (!name)
> +			return -ENOMEM;
> +
>  		break;
>  
>  	case MCP_TYPE_S18:
> -- 
> 2.34.1
> 

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-06-21 13:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 10:04 Claudiu Beznea
2023-06-21 13:36 ` Andy Shevchenko [this message]
2023-08-10  7:56 ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZJL8wPGxs9SDquQi@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®