* [PATCH] pinctrl: nomadik: Add error handling for find_nmk_gpio_from_pin
@ 2025-02-20 8:50 Wentao Liang
2025-02-20 12:14 ` Markus Elfring
2025-02-27 20:23 ` Linus Walleij
0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2025-02-20 8:50 UTC (permalink / raw)
To: linus.walleij
Cc: linux-arm-kernel, linux-gpio, linux-kernel, Wentao Liang, stable
When find_nmk_gpio_from_pin fails to find a valid GPIO chip
for the given pin, the bit variable remains uninitialized. This
uninitialized value is then passed to __nmk_gpio_set_mode,
leading to undefined behavior and undesired address access.
To fix this, add error handling to check the return value of
find_nmk_gpio_from_pin. Log an error message indicating an
invalid pin offset and return -EINVAL immediately If the function
fails.
Fixes: 75d270fda64d ("gpio: nomadik: request dynamic ID allocation")
Cc: stable@vger.kernel.org # 6.9+
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/pinctrl/nomadik/pinctrl-nomadik.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/nomadik/pinctrl-nomadik.c b/drivers/pinctrl/nomadik/pinctrl-nomadik.c
index f4f10c60c1d2..4155137b0674 100644
--- a/drivers/pinctrl/nomadik/pinctrl-nomadik.c
+++ b/drivers/pinctrl/nomadik/pinctrl-nomadik.c
@@ -985,7 +985,7 @@ static int nmk_gpio_request_enable(struct pinctrl_dev *pctldev,
unsigned int pin)
{
struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
- struct nmk_gpio_chip *nmk_chip;
+ struct nmk_gpio_chip *nmk_chip, *r;
struct gpio_chip *chip;
unsigned int bit;
@@ -1002,7 +1002,12 @@ static int nmk_gpio_request_enable(struct pinctrl_dev *pctldev,
dev_dbg(npct->dev, "enable pin %u as GPIO\n", pin);
- find_nmk_gpio_from_pin(pin, &bit);
+ r = find_nmk_gpio_from_pin(pin, &bit);
+ if (!r) {
+ dev_err(npct->dev,
+ "invalid pin offset %d\n", pin);
+ return -EINVAL;
+ }
clk_enable(nmk_chip->clk);
/* There is no glitch when converting any pin to GPIO */
--
2.42.0.windows.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] pinctrl: nomadik: Add error handling for find_nmk_gpio_from_pin
2025-02-20 8:50 [PATCH] pinctrl: nomadik: Add error handling for find_nmk_gpio_from_pin Wentao Liang
@ 2025-02-20 12:14 ` Markus Elfring
2025-02-27 20:23 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-02-20 12:14 UTC (permalink / raw)
To: vulab, linux-gpio, linux-arm-kernel, Linus Walleij; +Cc: stable, LKML
…
> To fix this, add error handling to check the return value of
> find_nmk_gpio_from_pin. Log an error message indicating an
> invalid pin offset and return -EINVAL immediately If the function
if the function call?
> fails.
failed?
* You may occasionally put more than 66 characters into text lines
of such a change description.
* How do you think about to append parentheses to function names?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pinctrl: nomadik: Add error handling for find_nmk_gpio_from_pin
2025-02-20 8:50 [PATCH] pinctrl: nomadik: Add error handling for find_nmk_gpio_from_pin Wentao Liang
2025-02-20 12:14 ` Markus Elfring
@ 2025-02-27 20:23 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2025-02-27 20:23 UTC (permalink / raw)
To: Wentao Liang; +Cc: linux-arm-kernel, linux-gpio, linux-kernel, stable
Hi Wentao,
thanks for your patch!
On Thu, Feb 20, 2025 at 9:51 AM Wentao Liang <vulab@iscas.ac.cn> wrote:
> When find_nmk_gpio_from_pin fails to find a valid GPIO chip
> for the given pin, the bit variable remains uninitialized. This
> uninitialized value is then passed to __nmk_gpio_set_mode,
> leading to undefined behavior and undesired address access.
>
> To fix this, add error handling to check the return value of
> find_nmk_gpio_from_pin. Log an error message indicating an
> invalid pin offset and return -EINVAL immediately If the function
> fails.
>
> Fixes: 75d270fda64d ("gpio: nomadik: request dynamic ID allocation")
> Cc: stable@vger.kernel.org # 6.9+
Unnecessary to tag for stable. It is not causing regressions.
Skip this and apply for nonurgent fixes.
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-27 20:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-20 8:50 [PATCH] pinctrl: nomadik: Add error handling for find_nmk_gpio_from_pin Wentao Liang
2025-02-20 12:14 ` Markus Elfring
2025-02-27 20:23 ` 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).