From patchwork Wed Feb 25 11:19:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 45042 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D2A3720502 for ; Wed, 25 Feb 2015 11:19:33 +0000 (UTC) Received: by lbiw7 with SMTP id w7sf2373145lbi.0 for ; Wed, 25 Feb 2015 03:19:32 -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=LGeSmCOCWfLQWlBienv47E4fBZQ2QjBYSmY6xZt78sY=; b=kxi1DvjkleernP/9+b2yCm/SVha+wMIIumpxjTKegwcf9sjvBgsz3JAKPKIJ13AFa+ UEkd1kj+ylNrr4XP9lNetHhLOm1lRFzRwA9EQKFKbdsadfFlpwwqGBGW0CVM7p4P13n+ chLsZtQJHWnGRbO+JLnNU2Fvh6zpyYql1rmh8oQCqxr5GIZrvFhM0a/WTYehcyfyb/UV 2BtWT9R5P57fP/sm7OFmgma1F+3q34myg/+GU7TMX567v2oJhP4HA9bEXMKzB6ORt9GH wU2pugeX3XUGoql/qtO0tn3+uU8uz+MObZ2RPTsFPOTyAQaKfge81UIbq6xtBgNGROiB d2XA== X-Gm-Message-State: ALoCoQnSpvcJ8X+PlfkcPXNgcrbeDjuIAhTeCT/+gw4MbQI/COW/Gpg2kqKBsUOdX3WbATdx2WON X-Received: by 10.152.1.5 with SMTP id 5mr395412lai.4.1424863172511; Wed, 25 Feb 2015 03:19:32 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.136 with SMTP id 8ls813335lau.1.gmail; Wed, 25 Feb 2015 03:19:32 -0800 (PST) X-Received: by 10.112.85.165 with SMTP id i5mr2373973lbz.7.1424863172333; Wed, 25 Feb 2015 03:19:32 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id np9si28569300lbb.0.2015.02.25.03.19.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 03:19:32 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbdu10 with SMTP id u10so3093679lbd.7 for ; Wed, 25 Feb 2015 03:19:32 -0800 (PST) X-Received: by 10.152.8.33 with SMTP id o1mr2427630laa.56.1424863172195; Wed, 25 Feb 2015 03:19:32 -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.35.133 with SMTP id h5csp2549488lbj; Wed, 25 Feb 2015 03:19:31 -0800 (PST) X-Received: by 10.70.118.234 with SMTP id kp10mr4710893pdb.20.1424863170248; Wed, 25 Feb 2015 03:19:30 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pr2si49307392pdb.188.2015.02.25.03.19.28; Wed, 25 Feb 2015 03:19:30 -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 S1753328AbbBYLTZ (ORCPT + 28 others); Wed, 25 Feb 2015 06:19:25 -0500 Received: from mail-wg0-f41.google.com ([74.125.82.41]:43899 "EHLO mail-wg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753281AbbBYLTX (ORCPT ); Wed, 25 Feb 2015 06:19:23 -0500 Received: by wggy19 with SMTP id y19so2908323wgg.10 for ; Wed, 25 Feb 2015 03:19:22 -0800 (PST) X-Received: by 10.180.75.200 with SMTP id e8mr37893096wiw.95.1424863162363; Wed, 25 Feb 2015 03:19:22 -0800 (PST) Received: from mai.lan (135-224-190-109.dsl.ovh.fr. [109.190.224.135]) by mx.google.com with ESMTPSA id m4sm24687356wik.20.2015.02.25.03.19.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Feb 2015 03:19:21 -0800 (PST) From: Daniel Lezcano To: mingo@kernel.org, tglx@linutronix.de Cc: matthias.bgg@gmail.com, robert.jarzmik@free.fr, linux@roeck-us.net, linux@rempel-privat.de, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] clocksource: mtk: Fix race conditions in probe code Date: Wed, 25 Feb 2015 12:19:18 +0100 Message-Id: <1424863159-20620-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424863159-20620-1-git-send-email-daniel.lezcano@linaro.org> References: <54EDAF91.8060308@linaro.org> <1424863159-20620-1-git-send-email-daniel.lezcano@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.169 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: Matthias Brugger We have two race conditions in the probe code which could lead to a null pointer dereference in the interrupt handler. The interrupt handler accesses the clockevent device, which may not yet be registered. First race condition happens when the interrupt handler gets registered before the interrupts get disabled. The second race condition happens when the interrupts get enabled, but the clockevent device is not yet registered. Fix that by disabling the interrupts before we register the interrupt and enable the interrupts after the clockevent device got registered. Reported-by: Gongbae Park Signed-off-by: Matthias Brugger Cc: stable@vger.kernel.org Signed-off-by: Daniel Lezcano --- drivers/clocksource/mtk_timer.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/clocksource/mtk_timer.c b/drivers/clocksource/mtk_timer.c index 32a3d25..68ab423 100644 --- a/drivers/clocksource/mtk_timer.c +++ b/drivers/clocksource/mtk_timer.c @@ -224,6 +224,8 @@ static void __init mtk_timer_init(struct device_node *node) } rate = clk_get_rate(clk); + mtk_timer_global_reset(evt); + if (request_irq(evt->dev.irq, mtk_timer_interrupt, IRQF_TIMER | IRQF_IRQPOLL, "mtk_timer", evt)) { pr_warn("failed to setup irq %d\n", evt->dev.irq); @@ -232,8 +234,6 @@ static void __init mtk_timer_init(struct device_node *node) evt->ticks_per_jiffy = DIV_ROUND_UP(rate, HZ); - mtk_timer_global_reset(evt); - /* Configure clock source */ mtk_timer_setup(evt, GPT_CLK_SRC, TIMER_CTRL_OP_FREERUN); clocksource_mmio_init(evt->gpt_base + TIMER_CNT_REG(GPT_CLK_SRC), @@ -241,10 +241,11 @@ static void __init mtk_timer_init(struct device_node *node) /* Configure clock event */ mtk_timer_setup(evt, GPT_CLK_EVT, TIMER_CTRL_OP_REPEAT); - mtk_timer_enable_irq(evt, GPT_CLK_EVT); - clockevents_config_and_register(&evt->dev, rate, 0x3, 0xffffffff); + + mtk_timer_enable_irq(evt, GPT_CLK_EVT); + return; err_clk_disable: