* [PATCH] gpio: nomadik: Add check for clk_enable()
@ 2025-04-12 19:31 Chenyuan Yang
2025-04-13 7:44 ` Linus Walleij
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Chenyuan Yang @ 2025-04-12 19:31 UTC (permalink / raw)
To: linus.walleij, brgl, theo.lebrun
Cc: linux-arm-kernel, linux-gpio, linux-kernel, Chenyuan Yang
Add check for the return value of clk_enable() to catch
the potential error.
This is similar to the commit 8332e6670997
("spi: zynq-qspi: Add check for clk_enable()").
Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
Fixes: 966942ae4936 ("gpio: nomadik: extract GPIO platform driver from drivers/pinctrl/nomadik/")
---
drivers/gpio/gpio-nomadik.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-nomadik.c b/drivers/gpio/gpio-nomadik.c
index fa19a44943fd..dbc4cdddf4df 100644
--- a/drivers/gpio/gpio-nomadik.c
+++ b/drivers/gpio/gpio-nomadik.c
@@ -262,8 +262,11 @@ static unsigned int nmk_gpio_irq_startup(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(gc);
+ int ret;
- clk_enable(nmk_chip->clk);
+ ret = clk_enable(nmk_chip->clk);
+ if (ret)
+ return ret;
nmk_gpio_irq_unmask(d);
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] gpio: nomadik: Add check for clk_enable()
2025-04-12 19:31 [PATCH] gpio: nomadik: Add check for clk_enable() Chenyuan Yang
@ 2025-04-13 7:44 ` Linus Walleij
2025-04-13 20:00 ` Bartosz Golaszewski
2025-04-14 9:24 ` Théo Lebrun
2 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2025-04-13 7:44 UTC (permalink / raw)
To: Chenyuan Yang
Cc: brgl, theo.lebrun, linux-arm-kernel, linux-gpio, linux-kernel
On Sat, Apr 12, 2025 at 9:31 PM Chenyuan Yang <chenyuan0y@gmail.com> wrote:
> Add check for the return value of clk_enable() to catch
> the potential error.
>
> This is similar to the commit 8332e6670997
> ("spi: zynq-qspi: Add check for clk_enable()").
>
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> Fixes: 966942ae4936 ("gpio: nomadik: extract GPIO platform driver from drivers/pinctrl/nomadik/")
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gpio: nomadik: Add check for clk_enable()
2025-04-12 19:31 [PATCH] gpio: nomadik: Add check for clk_enable() Chenyuan Yang
2025-04-13 7:44 ` Linus Walleij
@ 2025-04-13 20:00 ` Bartosz Golaszewski
2025-04-14 9:24 ` Théo Lebrun
2 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-04-13 20:00 UTC (permalink / raw)
To: linus.walleij, theo.lebrun, Chenyuan Yang
Cc: Bartosz Golaszewski, linux-arm-kernel, linux-gpio, linux-kernel
On Sat, 12 Apr 2025 14:31:53 -0500, Chenyuan Yang wrote:
> Add check for the return value of clk_enable() to catch
> the potential error.
>
> This is similar to the commit 8332e6670997
> ("spi: zynq-qspi: Add check for clk_enable()").
>
>
> [...]
Applied, thanks!
[1/1] gpio: nomadik: Add check for clk_enable()
https://git.kernel.org/brgl/linux/c/4521e0884c261fd286c02da942e9e8596bf2e7cf
Best regards,
--
Bartosz Golaszewski <brgl@bgdev.pl>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gpio: nomadik: Add check for clk_enable()
2025-04-12 19:31 [PATCH] gpio: nomadik: Add check for clk_enable() Chenyuan Yang
2025-04-13 7:44 ` Linus Walleij
2025-04-13 20:00 ` Bartosz Golaszewski
@ 2025-04-14 9:24 ` Théo Lebrun
2025-04-14 12:11 ` Chenyuan Yang
2 siblings, 1 reply; 7+ messages in thread
From: Théo Lebrun @ 2025-04-14 9:24 UTC (permalink / raw)
To: Chenyuan Yang, linus.walleij, brgl
Cc: linux-arm-kernel, linux-gpio, linux-kernel
Hello Chenyuan, Linus, Bartosz,
On Sat Apr 12, 2025 at 9:31 PM CEST, Chenyuan Yang wrote:
> Add check for the return value of clk_enable() to catch
> the potential error.
>
> This is similar to the commit 8332e6670997
> ("spi: zynq-qspi: Add check for clk_enable()").
>
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> Fixes: 966942ae4936 ("gpio: nomadik: extract GPIO platform driver from drivers/pinctrl/nomadik/")
> ---
> drivers/gpio/gpio-nomadik.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-nomadik.c b/drivers/gpio/gpio-nomadik.c
> index fa19a44943fd..dbc4cdddf4df 100644
> --- a/drivers/gpio/gpio-nomadik.c
> +++ b/drivers/gpio/gpio-nomadik.c
> @@ -262,8 +262,11 @@ static unsigned int nmk_gpio_irq_startup(struct irq_data *d)
> {
> struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
> struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(gc);
> + int ret;
>
> - clk_enable(nmk_chip->clk);
> + ret = clk_enable(nmk_chip->clk);
> + if (ret)
> + return ret;
> nmk_gpio_irq_unmask(d);
> return 0;
> }
Returning a negative value whereas the ->irq_startup() [0] return value
is an unsigned int? From some quick godbolt testing and briefly reading
the spec it looks safe to do a round trip (signed->unsigned->signed),
though not ideal to my eyes.
The caller is __irq_startup() [1].
As for why irq_startup returns an unsigned int, I am unsure. The kernel
Git history isn't enough to know more. The startup field in struct
hw_interrupt_type appeared on v2.3.14 [2], so no commit message to
explain decisions.
Seeing the __irq_startup() code, my proposal would be to turn the return
value to a signed int, but I haven't exhaustively checked codepaths.
Thanks,
[0]: https://elixir.bootlin.com/linux/v6.13.7/source/include/linux/irq.h#L503
[1]: https://elixir.bootlin.com/linux/v6.13.7/source/kernel/irq/chip.c#L244
[2]: https://elixir.bootlin.com/linux/2.3.14/source/include/linux/irq.h#L21
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gpio: nomadik: Add check for clk_enable()
2025-04-14 9:24 ` Théo Lebrun
@ 2025-04-14 12:11 ` Chenyuan Yang
2025-04-14 18:30 ` Bartosz Golaszewski
2025-04-16 8:35 ` Linus Walleij
0 siblings, 2 replies; 7+ messages in thread
From: Chenyuan Yang @ 2025-04-14 12:11 UTC (permalink / raw)
To: Théo Lebrun
Cc: linus.walleij, brgl, linux-arm-kernel, linux-gpio, linux-kernel
On Mon, Apr 14, 2025 at 4:24 AM Théo Lebrun <theo.lebrun@bootlin.com> wrote:
>
> Hello Chenyuan, Linus, Bartosz,
>
> On Sat Apr 12, 2025 at 9:31 PM CEST, Chenyuan Yang wrote:
> > Add check for the return value of clk_enable() to catch
> > the potential error.
> >
> > This is similar to the commit 8332e6670997
> > ("spi: zynq-qspi: Add check for clk_enable()").
> >
> > Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> > Fixes: 966942ae4936 ("gpio: nomadik: extract GPIO platform driver from drivers/pinctrl/nomadik/")
> > ---
> > drivers/gpio/gpio-nomadik.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpio/gpio-nomadik.c b/drivers/gpio/gpio-nomadik.c
> > index fa19a44943fd..dbc4cdddf4df 100644
> > --- a/drivers/gpio/gpio-nomadik.c
> > +++ b/drivers/gpio/gpio-nomadik.c
> > @@ -262,8 +262,11 @@ static unsigned int nmk_gpio_irq_startup(struct irq_data *d)
> > {
> > struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
> > struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(gc);
> > + int ret;
> >
> > - clk_enable(nmk_chip->clk);
> > + ret = clk_enable(nmk_chip->clk);
> > + if (ret)
> > + return ret;
> > nmk_gpio_irq_unmask(d);
> > return 0;
> > }
>
> Returning a negative value whereas the ->irq_startup() [0] return value
> is an unsigned int? From some quick godbolt testing and briefly reading
> the spec it looks safe to do a round trip (signed->unsigned->signed),
> though not ideal to my eyes.
>
> The caller is __irq_startup() [1].
>
> As for why irq_startup returns an unsigned int, I am unsure. The kernel
> Git history isn't enough to know more. The startup field in struct
> hw_interrupt_type appeared on v2.3.14 [2], so no commit message to
> explain decisions.
>
> Seeing the __irq_startup() code, my proposal would be to turn the return
> value to a signed int, but I haven't exhaustively checked codepaths.
Good catch! I agree that using a signed int could be a better option.
Dear Linus and Bartosz, could you please share your thoughts? If
you’re on board with the change, I’ll go ahead and send a new patch.
> Thanks,
>
> [0]: https://elixir.bootlin.com/linux/v6.13.7/source/include/linux/irq.h#L503
> [1]: https://elixir.bootlin.com/linux/v6.13.7/source/kernel/irq/chip.c#L244
> [2]: https://elixir.bootlin.com/linux/2.3.14/source/include/linux/irq.h#L21
>
> --
> Théo Lebrun, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
-Chenyuan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gpio: nomadik: Add check for clk_enable()
2025-04-14 12:11 ` Chenyuan Yang
@ 2025-04-14 18:30 ` Bartosz Golaszewski
2025-04-16 8:35 ` Linus Walleij
1 sibling, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-04-14 18:30 UTC (permalink / raw)
To: Chenyuan Yang
Cc: Théo Lebrun, linus.walleij, linux-arm-kernel, linux-gpio,
linux-kernel
On Mon, Apr 14, 2025 at 2:11 PM Chenyuan Yang <chenyuan0y@gmail.com> wrote:
>
> On Mon, Apr 14, 2025 at 4:24 AM Théo Lebrun <theo.lebrun@bootlin.com> wrote:
> >
> > As for why irq_startup returns an unsigned int, I am unsure. The kernel
> > Git history isn't enough to know more. The startup field in struct
> > hw_interrupt_type appeared on v2.3.14 [2], so no commit message to
> > explain decisions.
> >
> > Seeing the __irq_startup() code, my proposal would be to turn the return
> > value to a signed int, but I haven't exhaustively checked codepaths.
>
> Good catch! I agree that using a signed int could be a better option.
>
> Dear Linus and Bartosz, could you please share your thoughts? If
> you’re on board with the change, I’ll go ahead and send a new patch.
>
Ok, I'm backing out this one then.
Bartosz
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gpio: nomadik: Add check for clk_enable()
2025-04-14 12:11 ` Chenyuan Yang
2025-04-14 18:30 ` Bartosz Golaszewski
@ 2025-04-16 8:35 ` Linus Walleij
1 sibling, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2025-04-16 8:35 UTC (permalink / raw)
To: Chenyuan Yang
Cc: Théo Lebrun, brgl, linux-arm-kernel, linux-gpio,
linux-kernel
On Mon, Apr 14, 2025 at 2:11 PM Chenyuan Yang <chenyuan0y@gmail.com> wrote:
> On Mon, Apr 14, 2025 at 4:24 AM Théo Lebrun <theo.lebrun@bootlin.com> wrote:
> > Seeing the __irq_startup() code, my proposal would be to turn the return
> > value to a signed int, but I haven't exhaustively checked codepaths.
>
> Good catch! I agree that using a signed int could be a better option.
>
> Dear Linus and Bartosz, could you please share your thoughts? If
> you’re on board with the change, I’ll go ahead and send a new patch.
Yeah that would be great, thanks!
Thanks for noticing this as well Theo, I think your team is the
most important user of this code right now.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-04-16 10:31 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-12 19:31 [PATCH] gpio: nomadik: Add check for clk_enable() Chenyuan Yang
2025-04-13 7:44 ` Linus Walleij
2025-04-13 20:00 ` Bartosz Golaszewski
2025-04-14 9:24 ` Théo Lebrun
2025-04-14 12:11 ` Chenyuan Yang
2025-04-14 18:30 ` Bartosz Golaszewski
2025-04-16 8:35 ` 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).