Message ID | 20231129063730.31184-1-liuhaoran14@163.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [sh/highlander] psw: Add error handling in psw_irq_handler | expand |
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
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
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 */
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(+)