* [PATCH v3] pinctrl: stm32: check devm_kasprintf() returned value
@ 2024-09-06 10:03 Ma Ke
2024-09-23 9:15 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2024-09-06 10:03 UTC (permalink / raw)
To: linus.walleij, mcoquelin.stm32, alexandre.torgue,
bartosz.golaszewski, patrice.chotard, antonio.borneo, s.shtylyov,
valentin.caron, peng.fan, make24, akpm
Cc: linux-gpio, linux-stm32, linux-arm-kernel, linux-kernel, stable
devm_kasprintf() can return a NULL pointer on failure but this returned
value is not checked. Fix this lack and check the returned value.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 32c170ff15b0 ("pinctrl: stm32: set default gpio line names using pin names")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v3:
- modified the code style according to suggestions.
Changes in v2:
- modified the patch according to suggestions, added braces;
- modified the typo.
---
drivers/pinctrl/stm32/pinctrl-stm32.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index a8673739871d..5b7fa77c1184 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -1374,10 +1374,15 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
for (i = 0; i < npins; i++) {
stm32_pin = stm32_pctrl_get_desc_pin_from_gpio(pctl, bank, i);
- if (stm32_pin && stm32_pin->pin.name)
+ if (stm32_pin && stm32_pin->pin.name) {
names[i] = devm_kasprintf(dev, GFP_KERNEL, "%s", stm32_pin->pin.name);
- else
+ if (!names[i]) {
+ err = -ENOMEM;
+ goto err_clk;
+ }
+ } else {
names[i] = NULL;
+ }
}
bank->gpio_chip.names = (const char * const *)names;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] pinctrl: stm32: check devm_kasprintf() returned value
2024-09-06 10:03 [PATCH v3] pinctrl: stm32: check devm_kasprintf() returned value Ma Ke
@ 2024-09-23 9:15 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2024-09-23 9:15 UTC (permalink / raw)
To: Ma Ke
Cc: mcoquelin.stm32, alexandre.torgue, bartosz.golaszewski,
patrice.chotard, antonio.borneo, s.shtylyov, valentin.caron,
peng.fan, akpm, linux-gpio, linux-stm32, linux-arm-kernel,
linux-kernel, stable
On Fri, Sep 6, 2024 at 12:03 PM Ma Ke <make24@iscas.ac.cn> wrote:
> devm_kasprintf() can return a NULL pointer on failure but this returned
> value is not checked. Fix this lack and check the returned value.
>
> Found by code review.
>
> Cc: stable@vger.kernel.org
> Fixes: 32c170ff15b0 ("pinctrl: stm32: set default gpio line names using pin names")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
Patch applied for fixes.
Thanks for working on these malloc details, much appreciated!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-23 9:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-06 10:03 [PATCH v3] pinctrl: stm32: check devm_kasprintf() returned value Ma Ke
2024-09-23 9:15 ` 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).