From patchwork Wed Nov 19 09:49:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 41116 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2217920CBB for ; Wed, 19 Nov 2014 09:49:36 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf454388eek.1 for ; Wed, 19 Nov 2014 01:49:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=Lil7mtOH17NiTZtHEFQhN0gNk0kTYriPat/teh256jU=; b=iEw5Ug0eLuiWigpBZk3k9X5bOAwtGUxI+LsvL49lfhoxIKYZFIrPFMcHfhGVDHqRYj WutSLOmQsm5znGTZgQHVdOS29ySCpi2jl/QrfLDX1TpK+BAVHdVM9vpNgz2NXk8XWr/7 AH3bfqJkPDUPkQFD7vZczcXx+4YrBEN2CWRMNvMRBAcx0aSFnrOvt0sAPwF4MTi9Jfst cQpaiS8dUbwp5w0vTHomOHBZtwXPzYgk6wkGE9UIOAYMGwyf6BATWUt0EVwccpWdlLms kzuJoSNaiXH5fcdmiJyIyeK65cTrhOaIAnRGitBKogpyjSMVW3xvrXIEuHVOyeYO/Flw 99pA== X-Gm-Message-State: ALoCoQl8rLe6rjExtAxrRUHJq2BCUmiPnNeEcdY3Wsx7GLv8CJyRJFsfjlD0MUKhdqvakl1ZoJKt X-Received: by 10.152.36.135 with SMTP id q7mr287714laj.8.1416390575150; Wed, 19 Nov 2014 01:49:35 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.170 with SMTP id p10ls289076lal.35.gmail; Wed, 19 Nov 2014 01:49:34 -0800 (PST) X-Received: by 10.112.235.135 with SMTP id um7mr880261lbc.96.1416390574873; Wed, 19 Nov 2014 01:49:34 -0800 (PST) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id rs2si1209313lbb.91.2014.11.19.01.49.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Nov 2014 01:49:34 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by mail-lb0-f177.google.com with SMTP id z12so175418lbi.22 for ; Wed, 19 Nov 2014 01:49:34 -0800 (PST) X-Received: by 10.112.62.166 with SMTP id z6mr4257713lbr.74.1416390574459; Wed, 19 Nov 2014 01:49:34 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp54516lbc; Wed, 19 Nov 2014 01:49:33 -0800 (PST) X-Received: by 10.66.159.201 with SMTP id xe9mr45385450pab.13.1416390572870; Wed, 19 Nov 2014 01:49:32 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c7si1535261pdl.226.2014.11.19.01.49.31 for ; Wed, 19 Nov 2014 01:49:32 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755472AbaKSJt3 (ORCPT + 26 others); Wed, 19 Nov 2014 04:49:29 -0500 Received: from mail-wi0-f182.google.com ([209.85.212.182]:34156 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753748AbaKSJt0 (ORCPT ); Wed, 19 Nov 2014 04:49:26 -0500 Received: by mail-wi0-f182.google.com with SMTP id h11so1177970wiw.15 for ; Wed, 19 Nov 2014 01:49:25 -0800 (PST) X-Received: by 10.180.99.105 with SMTP id ep9mr11814332wib.26.1416390565129; Wed, 19 Nov 2014 01:49:25 -0800 (PST) Received: from localhost.localdomain (AToulouse-656-1-820-36.w109-215.abo.wanadoo.fr. [109.215.21.36]) by mx.google.com with ESMTPSA id p1sm1531302wjy.22.2014.11.19.01.49.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Nov 2014 01:49:24 -0800 (PST) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, maxime.ripard@free-electrons.com Subject: [PATCH] clockevent: sun4i: Fix race condition in the probe code Date: Wed, 19 Nov 2014 10:49:23 +0100 Message-Id: <1416390563-17138-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <546C673F.8000502@linaro.org> References: <546C673F.8000502@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Maxime Ripard The interrupts were activated and the handler registered before the clockevent was registered in the probe function. The interrupt handler, however, was making the assumption that the clockevent device was registered. That could cause a null pointer dereference if the timer interrupt was firing during this narrow window. Fix that by moving the clockevent registration before the interrupt is enabled. Reported-by: Roman Byshko Signed-off-by: Maxime Ripard Cc: stable@vger.kernel.org Signed-off-by: Daniel Lezcano --- drivers/clocksource/sun4i_timer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/clocksource/sun4i_timer.c b/drivers/clocksource/sun4i_timer.c index efb17c3..f4a9c00 100644 --- a/drivers/clocksource/sun4i_timer.c +++ b/drivers/clocksource/sun4i_timer.c @@ -182,6 +182,12 @@ static void __init sun4i_timer_init(struct device_node *node) /* Make sure timer is stopped before playing with interrupts */ sun4i_clkevt_time_stop(0); + sun4i_clockevent.cpumask = cpu_possible_mask; + sun4i_clockevent.irq = irq; + + clockevents_config_and_register(&sun4i_clockevent, rate, + TIMER_SYNC_TICKS, 0xffffffff); + ret = setup_irq(irq, &sun4i_timer_irq); if (ret) pr_warn("failed to setup irq %d\n", irq); @@ -189,12 +195,6 @@ static void __init sun4i_timer_init(struct device_node *node) /* Enable timer0 interrupt */ val = readl(timer_base + TIMER_IRQ_EN_REG); writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG); - - sun4i_clockevent.cpumask = cpu_possible_mask; - sun4i_clockevent.irq = irq; - - clockevents_config_and_register(&sun4i_clockevent, rate, - TIMER_SYNC_TICKS, 0xffffffff); } CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer", sun4i_timer_init);