From patchwork Fri Aug 26 14:20:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 9301371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C7A4E601C0 for ; Fri, 26 Aug 2016 14:24:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B885E294E8 for ; Fri, 26 Aug 2016 14:24:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD161295EB; Fri, 26 Aug 2016 14:24:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9BCC7294E8 for ; Fri, 26 Aug 2016 14:24:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bdI2C-00073W-Qy; Fri, 26 Aug 2016 14:23:04 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bdI1e-0006lk-7P for linux-arm-kernel@lists.infradead.org; Fri, 26 Aug 2016 14:22:34 +0000 Received: by mail-wm0-x234.google.com with SMTP id f65so280506898wmi.0 for ; Fri, 26 Aug 2016 07:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=O8SRaabe8s4cg5CWhk1A2KPVo9zaV96mhqWArHaoows=; b=GCJ/K3HtZjTPos4iWj8Wr8pLbJExN7imAarzwbc/TtuTsw2yHZSfFXamWr7xrCnZIg cVZyg9oz4v9ntQTF0K9aOuhZCejrptJKsd9IGfxsbSkhr903Qg4Np8Ix3Bh9oSSEcuGd rO6s22QwI9ML8aZ3p9ssl5ySzDHvyKU6PhcUI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=O8SRaabe8s4cg5CWhk1A2KPVo9zaV96mhqWArHaoows=; b=Ayq8yXVm1OLDycBqWzXlzcLupKm58CDedSYjieRUWhiGYoa7mio5RcfeWs/8+T42++ fjNLr9DfXoPwP/wX11e5ocR1TwOx4QxIxFxdmhhL0YFCHn/7z3jDgzRqFL0QbYMd+m0s aOl6BZO5nwTZKihcb4yIcs/HCqhvsthENCX8Fn4GVn4H0RkLzLhPY3Z5XMD8eF90Hvea FYONzAAcLzhwXPA/DTZ0Xe12ox9GU0M2jkxdBpmKVF8hbqCB3ArOs3VMcetzbnBl+ee0 pDhwh/xLsfy7A0oSocdpGjqXDylvPz/4zVbLr+sMLuGZxZxeYWCQPYWAn5ooJppu23Yv BrWw== X-Gm-Message-State: AEkooutFI2ltPzHfP1b+Vt1DP59/Ps6xlShvCFxTX95V4neCC4ojmr8Wa9Dske5543WD0LkU X-Received: by 10.28.222.8 with SMTP id v8mr37137801wmg.55.1472221328246; Fri, 26 Aug 2016 07:22:08 -0700 (PDT) Received: from localhost.localdomain (lft31-1-88-121-166-205.fbx.proxad.net. [88.121.166.205]) by smtp.gmail.com with ESMTPSA id m5sm3168940wmd.1.2016.08.26.07.22.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Aug 2016 07:22:07 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de, mingo@kernel.org Subject: [PATCH 3/3] clocksource/drivers/sun4i: Clear interrupts after stopping timer in probe function Date: Fri, 26 Aug 2016 16:20:45 +0200 Message-Id: <1472221245-14265-3-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1472221245-14265-1-git-send-email-daniel.lezcano@linaro.org> References: <57C05026.7010905@linaro.org> <1472221245-14265-1-git-send-email-daniel.lezcano@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160826_072230_546588_9D4B2CBB X-CRM114-Status: GOOD ( 14.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , stable@vger.kernel.org, Chen-Yu Tsai , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Chen-Yu Tsai The bootloader (U-boot) sometimes uses this timer for various delays. It uses it as a ongoing counter, and does comparisons on the current counter value. The timer counter is never stopped. In some cases when the user interacts with the bootloader, or lets it idle for some time before loading Linux, the timer may expire, and an interrupt will be pending. This results in an unexpected interrupt when the timer interrupt is enabled by the kernel, at which point the event_handler isn't set yet. This results in a NULL pointer dereference exception, panic, and no way to reboot. Clear any pending interrupts after we stop the timer in the probe function to avoid this. Cc: stable@vger.kernel.org Signed-off-by: Chen-Yu Tsai Signed-off-by: Daniel Lezcano Acked-by: Maxime Ripard --- drivers/clocksource/sun4i_timer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/clocksource/sun4i_timer.c b/drivers/clocksource/sun4i_timer.c index 97669ee..c83452c 100644 --- a/drivers/clocksource/sun4i_timer.c +++ b/drivers/clocksource/sun4i_timer.c @@ -123,12 +123,16 @@ static struct clock_event_device sun4i_clockevent = { .set_next_event = sun4i_clkevt_next_event, }; +static void sun4i_timer_clear_interrupt(void) +{ + writel(TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_ST_REG); +} static irqreturn_t sun4i_timer_interrupt(int irq, void *dev_id) { struct clock_event_device *evt = (struct clock_event_device *)dev_id; - writel(0x1, timer_base + TIMER_IRQ_ST_REG); + sun4i_timer_clear_interrupt(); evt->event_handler(evt); return IRQ_HANDLED; @@ -208,6 +212,9 @@ static int __init sun4i_timer_init(struct device_node *node) /* Make sure timer is stopped before playing with interrupts */ sun4i_clkevt_time_stop(0); + /* clear timer0 interrupt */ + sun4i_timer_clear_interrupt(); + sun4i_clockevent.cpumask = cpu_possible_mask; sun4i_clockevent.irq = irq;