* [PATCH v2] pinctrl: mcp23s08: check return value of devm_kasprintf()
@ 2023-06-21 10:04 Claudiu Beznea
2023-06-21 13:36 ` Andy Shevchenko
2023-08-10 7:56 ` Linus Walleij
0 siblings, 2 replies; 3+ messages in thread
From: Claudiu Beznea @ 2023-06-21 10:04 UTC (permalink / raw)
To: linus.walleij, andriy.shevchenko; +Cc: linux-gpio, linux-kernel, Claudiu Beznea
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).
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] pinctrl: mcp23s08: check return value of devm_kasprintf()
2023-06-21 10:04 [PATCH v2] pinctrl: mcp23s08: check return value of devm_kasprintf() Claudiu Beznea
@ 2023-06-21 13:36 ` Andy Shevchenko
2023-08-10 7:56 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2023-06-21 13:36 UTC (permalink / raw)
To: Claudiu Beznea; +Cc: linus.walleij, linux-gpio, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] pinctrl: mcp23s08: check return value of devm_kasprintf()
2023-06-21 10:04 [PATCH v2] pinctrl: mcp23s08: check return value of devm_kasprintf() Claudiu Beznea
2023-06-21 13:36 ` Andy Shevchenko
@ 2023-08-10 7:56 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2023-08-10 7:56 UTC (permalink / raw)
To: Claudiu Beznea; +Cc: andriy.shevchenko, linux-gpio, linux-kernel
On Wed, Jun 21, 2023 at 12:04 PM Claudiu Beznea
<claudiu.beznea@microchip.com> 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).
>
> Fixes: 0f04a81784fe ("pinctrl: mcp23s08: Split to three parts: core, I²C, SPI")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Patch applied!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-10 7:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-21 10:04 [PATCH v2] pinctrl: mcp23s08: check return value of devm_kasprintf() Claudiu Beznea
2023-06-21 13:36 ` Andy Shevchenko
2023-08-10 7:56 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).