[PATCH] sun4i: guard against missing event handler

68 views
Skip to first unread message

tu...@linux-sunxi.org

unread,
Oct 6, 2012, 12:14:32 PM10/6/12
to d...@linux-sunxi.org, Emilio López
From: Emilio López <tu...@tuxfamily.org>

If we kexec the kernel, we are more likely to get an IRQ handle
request without a valid handler pointer set up. Make sure the
pointer is valid before running it.

arch/arm/mach-msm/timer.c takes the same approach.

Signed-off-by: Emilio López <tu...@tuxfamily.org>
---
arch/arm/mach-sun4i/clock/aw_clocksrc.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/arch/arm/mach-sun4i/clock/aw_clocksrc.c b/arch/arm/mach-sun4i/clock/aw_clocksrc.c
index eee0227..7b222ba 100644
--- a/arch/arm/mach-sun4i/clock/aw_clocksrc.c
+++ b/arch/arm/mach-sun4i/clock/aw_clocksrc.c
@@ -174,6 +174,8 @@ static void aw_set_clkevt_mode(enum clock_event_mode mode, struct clock_event_de
break;
}

+ case CLOCK_EVT_MODE_SHUTDOWN:
+ case CLOCK_EVT_MODE_UNUSED:
default:
{
/* disable clock event device */
@@ -253,9 +255,12 @@ static irqreturn_t aw_clkevt_irq(int irq, void *handle)
CLKSRC_DBG("aw_clkevt_irq!\n");
/* clear pending */
TMR_REG_IRQ_STAT = (1<<1);
+
+ if(unlikely(aw_clock_event.event_handler == NULL))
+ return IRQ_HANDLED;
+
/* clock event interrupt handled */
aw_clock_event.event_handler(&aw_clock_event);
-
return IRQ_HANDLED;
}

--
1.7.5.4

tu...@linux-sunxi.org

unread,
Oct 5, 2012, 1:02:15 PM10/5/12
to d...@linux-sunxi.org, Emilio López

Alejandro Mery

unread,
Oct 8, 2012, 3:16:46 PM10/8/12
to linux...@googlegroups.com
On 05/10/12 19:02, tu...@linux-sunxi.org wrote:
> From: Emilio López <tu...@tuxfamily.org>
>
> If we kexec the kernel, we are more likely to get an IRQ handle
> request without a valid handler pointer set up. Make sure the
> pointer is valid before running it.
>
> arch/arm/mach-msm/timer.c takes the same approach.
>
> Signed-off-by: Emilio López <tu...@tuxfamily.org>
> ---
> arch/arm/mach-sun4i/clock/aw_clocksrc.c | 7 ++++++-
> 1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/arch/arm/mach-sun4i/clock/aw_clocksrc.c b/arch/arm/mach-sun4i/clock/aw_clocksrc.c
> index eee0227..7b222ba 100644
> --- a/arch/arm/mach-sun4i/clock/aw_clocksrc.c
> +++ b/arch/arm/mach-sun4i/clock/aw_clocksrc.c
> @@ -174,6 +174,8 @@ static void aw_set_clkevt_mode(enum clock_event_mode mode, struct clock_event_de
> break;
> }
>
> + case CLOCK_EVT_MODE_SHUTDOWN:
> + case CLOCK_EVT_MODE_UNUSED:
> default:
> {

if they are handled by default, why adding them explicitly?


> /* disable clock event device */
> @@ -253,9 +255,12 @@ static irqreturn_t aw_clkevt_irq(int irq, void *handle)
> CLKSRC_DBG("aw_clkevt_irq!\n");
> /* clear pending */
> TMR_REG_IRQ_STAT = (1<<1);
> +
> + if(unlikely(aw_clock_event.event_handler == NULL))
> + return IRQ_HANDLED;
> +
> /* clock event interrupt handled */
> aw_clock_event.event_handler(&aw_clock_event);
> -
> return IRQ_HANDLED;

what about merging both?
if (aw_clock_event.event_handler)
aw_clock_event.event_handler(&aw_clock_event);
return IRQ_HANDLED;


tu...@linux-sunxi.org

unread,
Oct 8, 2012, 6:59:14 PM10/8/12
to d...@linux-sunxi.org, Emilio López
From: Emilio López <tu...@linux-sunxi.org>

If we kexec the kernel, we are more likely to get an IRQ handle
request without a valid handler pointer set up. Make sure the
pointer is valid before running it.

This happens just one time on kexec boot, so use likely to hint
the compiler adequately.

arch/arm/mach-msm/timer.c takes the same approach.

Signed-off-by: Emilio López <tu...@linux-sunxi.org>
---
arch/arm/mach-sun4i/clock/aw_clocksrc.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/arch/arm/mach-sun4i/clock/aw_clocksrc.c b/arch/arm/mach-sun4i/clock/aw_clocksrc.c
index eee0227..31a14d7 100644
--- a/arch/arm/mach-sun4i/clock/aw_clocksrc.c
+++ b/arch/arm/mach-sun4i/clock/aw_clocksrc.c
@@ -253,8 +253,10 @@ static irqreturn_t aw_clkevt_irq(int irq, void *handle)
CLKSRC_DBG("aw_clkevt_irq!\n");
/* clear pending */
TMR_REG_IRQ_STAT = (1<<1);
+
/* clock event interrupt handled */
- aw_clock_event.event_handler(&aw_clock_event);
+ if(likely(aw_clock_event.event_handler != NULL))
+ aw_clock_event.event_handler(&aw_clock_event);

return IRQ_HANDLED;
}
--
1.7.5.4

Alejandro Mery

unread,
Oct 9, 2012, 7:54:15 PM10/9/12
to linux...@googlegroups.com
On 09/10/12 00:59, tu...@linux-sunxi.org wrote:
> From: Emilio L�pez <tu...@linux-sunxi.org>
>
> If we kexec the kernel, we are more likely to get an IRQ handle
> request without a valid handler pointer set up. Make sure the
> pointer is valid before running it.
>
> This happens just one time on kexec boot, so use likely to hint
> the compiler adequately.
>
> arch/arm/mach-msm/timer.c takes the same approach.

thank you. applied to sun5i as well.

Reply all
Reply to author
Forward
0 new messages