[PATCH] [sh/highlander] psw: Add error handling in psw_irq_handler

Haoran Liu posted 1 patch 2 years, 1 month ago
There is a newer version of this series
arch/sh/boards/mach-highlander/psw.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] [sh/highlander] psw: Add error handling in psw_irq_handler
Posted by Haoran Liu 2 years, 1 month ago
This patch adds error handling for the platform_get_drvdata call
within the psw_irq_handler function in
arch/sh/boards/mach-highlander/psw.c. Previously, the absence of
error checking could lead to unexpected behavior if
platform_get_drvdata returned a null pointer.

Signed-off-by: Haoran Liu <liuhaoran14@163.com>
---
 arch/sh/boards/mach-highlander/psw.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/sh/boards/mach-highlander/psw.c b/arch/sh/boards/mach-highlander/psw.c
index d445c54f74e4..e079215e50e3 100644
--- a/arch/sh/boards/mach-highlander/psw.c
+++ b/arch/sh/boards/mach-highlander/psw.c
@@ -21,6 +21,12 @@ static irqreturn_t psw_irq_handler(int irq, void *arg)
 	unsigned int l, mask;
 	int ret = 0;
 
+	if (!psw) {
+		pr_err("psw_irq_handler: No push_switch data associated
+			with platform_device\n");
+		return IRQ_NONE;
+	}
+
 	l = __raw_readw(PA_DBSW);
 
 	/* Nothing to do if there's no state change */
-- 
2.17.1
Re: [PATCH] [sh/highlander] psw: Add error handling in psw_irq_handler
Posted by Geert Uytterhoeven 2 years ago
Hi Haoran,

On Wed, Nov 29, 2023 at 7:38 AM Haoran Liu <liuhaoran14@163.com> wrote:
> This patch adds error handling for the platform_get_drvdata call
> within the psw_irq_handler function in
> arch/sh/boards/mach-highlander/psw.c. Previously, the absence of
> error checking could lead to unexpected behavior if
> platform_get_drvdata returned a null pointer.

Can you please tell me how you detected this issue?
Thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH] [sh/highlander] psw: Add error handling in psw_irq_handler
Posted by Geert Uytterhoeven 2 years ago
Hi Haoran,

On Wed, Nov 29, 2023 at 7:38 AM Haoran Liu <liuhaoran14@163.com> wrote:
> This patch adds error handling for the platform_get_drvdata call
> within the psw_irq_handler function in
> arch/sh/boards/mach-highlander/psw.c. Previously, the absence of
> error checking could lead to unexpected behavior if
> platform_get_drvdata returned a null pointer.
>
> Signed-off-by: Haoran Liu <liuhaoran14@163.com>

Thanks for your patch!

> --- a/arch/sh/boards/mach-highlander/psw.c
> +++ b/arch/sh/boards/mach-highlander/psw.c
> @@ -21,6 +21,12 @@ static irqreturn_t psw_irq_handler(int irq, void *arg)
>         unsigned int l, mask;
>         int ret = 0;
>
> +       if (!psw) {
> +               pr_err("psw_irq_handler: No push_switch data associated
> +                       with platform_device\n");
> +               return IRQ_NONE;
> +       }
> +
>         l = __raw_readw(PA_DBSW);
>
>         /* Nothing to do if there's no state change */

This means the button is pressed, and the interrupt fired, in
between the calls to request_irq() and platform_set_drvdata() in
arch/sh/drivers/push-switch.c:switch_drv_probe()?

The same issue can happen with arch/sh/boards/mach-landisk/psw.c.
I think the proper solution is to fix this inside the push switch
driver, by moving the call to request_irq() after the call to
platform_set_drvdata() (and doing the reverse in switch_drv_remove()).

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds