From patchwork Wed Feb 25 10:31:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 45035 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f200.google.com (mail-we0-f200.google.com [74.125.82.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EE5E920502 for ; Wed, 25 Feb 2015 10:31:44 +0000 (UTC) Received: by wesk11 with SMTP id k11sf2142071wes.3 for ; Wed, 25 Feb 2015 02:31:44 -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=GomV2lAMjA0mFg0JkIUHmslEJG+2gEArkKsBDawfxGRl1UD4Igc6H0VvEjsCcM9GBN 93pRSrq8Ol8eJZ/eWDc0GVAj1nDCuuLi6ZhfOabNfcdAOMSviWMQ6o5Dy/B8P9Ji/y0u Cjvacc56LcO/xfHgomLHU2H6kuoriQfG3SGK5tjEgioQrniAozJ789gtMy5ZD96bqDvS XwQo5sFChQtMc8ZgAiWFJ+LkVCArtDhjlJqL6JQVL2Raj3N73VFF3bjmQ6sr1QbNZJdL qglIU5+xd5xg2EzQgXl14zvde8EAY99q2sEAlumXt+7c9ILioH6ISbBPvO7ceAsuj7Re wJCg== X-Gm-Message-State: ALoCoQlgrukWaM1xgp1Q9IfoT/MiozgIPM9ACTXteQrlkv+gpY0WM2EVLohnKt03ywZq94ccZazM X-Received: by 10.180.80.35 with SMTP id o3mr2783130wix.0.1424860304144; Wed, 25 Feb 2015 02:31:44 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.201 with SMTP id m9ls798793lah.6.gmail; Wed, 25 Feb 2015 02:31:43 -0800 (PST) X-Received: by 10.152.87.84 with SMTP id v20mr2098456laz.81.1424860303929; Wed, 25 Feb 2015 02:31:43 -0800 (PST) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id b5si25483424laf.90.2015.02.25.02.31.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 02:31:43 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbiw7 with SMTP id w7so2831030lbi.10 for ; Wed, 25 Feb 2015 02:31:43 -0800 (PST) X-Received: by 10.112.188.165 with SMTP id gb5mr2169427lbc.35.1424860303768; Wed, 25 Feb 2015 02:31:43 -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 h5csp2525700lbj; Wed, 25 Feb 2015 02:31:43 -0800 (PST) X-Received: by 10.68.65.42 with SMTP id u10mr4076115pbs.81.1424860302589; Wed, 25 Feb 2015 02:31:42 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fc8si3276250pab.129.2015.02.25.02.31.40; Wed, 25 Feb 2015 02:31:42 -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 S1753296AbbBYKbZ (ORCPT + 28 others); Wed, 25 Feb 2015 05:31:25 -0500 Received: from mail-wi0-f171.google.com ([209.85.212.171]:41983 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752643AbbBYKbW (ORCPT ); Wed, 25 Feb 2015 05:31:22 -0500 Received: by mail-wi0-f171.google.com with SMTP id ex7so11652061wid.4 for ; Wed, 25 Feb 2015 02:31:21 -0800 (PST) X-Received: by 10.180.149.206 with SMTP id uc14mr38819275wib.57.1424860281359; Wed, 25 Feb 2015 02:31:21 -0800 (PST) Received: from localhost.localdomain (135-224-190-109.dsl.ovh.fr. [109.190.224.135]) by mx.google.com with ESMTPSA id nb9sm24522798wic.3.2015.02.25.02.31.19 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Feb 2015 02:31:20 -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 11:31:15 +0100 Message-Id: <1424860276-18334-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424860276-18334-1-git-send-email-daniel.lezcano@linaro.org> References: <54EDA19F.7050903@linaro.org> <1424860276-18334-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.176 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: