From patchwork Tue Mar 13 12:08:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10278461 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 9CB0960231 for ; Tue, 13 Mar 2018 12:09:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D3F528FBA for ; Tue, 13 Mar 2018 12:09:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8151C28FBE; Tue, 13 Mar 2018 12:09:03 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1134F28FBA for ; Tue, 13 Mar 2018 12:09:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D88756E291; Tue, 13 Mar 2018 12:09:01 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.134]) by gabe.freedesktop.org (Postfix) with ESMTPS id 83A516E291; Tue, 13 Mar 2018 12:08:59 +0000 (UTC) Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue007 [212.227.15.129]) with ESMTPA (Nemesis) id 0LlLpD-1eKSAu3fGR-00bNaQ; Tue, 13 Mar 2018 13:08:52 +0100 From: Arnd Bergmann To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie Date: Tue, 13 Mar 2018 13:08:29 +0100 Message-Id: <20180313120848.2658626-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:1C9NSNSxaU5N/FWz8jy8lnk6fXnxY6XUaKse+PTo0KLES56ylvw p+AqT5dDoee9LaW5p6Ge64fMdihWff1Z9yB2iWSVuLq7LCmtr5yMTeaIRIFF8vxOdWhkKhw K4vAzfdq5/uyF+tnauv5ajaiRDDL7tJcWRyzMR7dOoWAbR7iu3fZ7LT+bjsXWNqJqBWn0AE vI7AxxElhk+vo8ieoD/VA== X-UI-Out-Filterresults: notjunk:1; V01:K0:ax2aEcaHqPA=:C5PvGOiPe8pAJh266/fS19 3EKLEEJ31orGyHP2V0BPS42o66jZek0SLoYIjPVqVlP2hEidQzc1hgPa8KFFq1aKvSSil347W mUGAgLzNp2E485VTpxBv8zaSmrNS2kdIggms8JYbeXaX9T8Mrgg1xDU2BOjJgA1XYH0iGK3JG pAmhvxVnL50HadG8/Rm3hPxN4RLP1/tp11pLDofkHC9a5HBFS9a2gsF9QfIEDG+2ABt47aiGq /zqQTZoB3jUNt6QDueUerFUFfcV9jhr7aFWHPU4AM18P/NLUHPRINDF3cpdHAg31Hc2Xp+Ujh kM1H0UjnNcnXToJPSzXPNFV0zqY4VZmdo7gSgaBg054GbFJ05fBryZMukQRFIMF4tn+JoHPD+ g/DLki/v99o8RX+iiVh7HuiXTnx6FttobUIWqJLch8o+Sjv/o9C/11cEE4wLrZsdxw+iKRsTc JDNq1Jlk466lQ7U+5tmAg9j6Jzi1Mc/Xd1bGlL4+zQE+Ljo64ZkYkUYfSfHxgbeA9g5QINv0i 3z0VdBzE02AQW5gpxCABYTpxgpzlZn+Kes6gmRejZ57dt4q79W8ULpJsAl2YpfOGzADWzelk6 M1D2+3HyKnRWOY2H/dzwm5MDI9vB9iKkrntICw5ozFT1TTIqf6XdnF7KiV068HQ+fdc9tX25g TypPDNbeaeLZIK7duXxvliVfMg9XV6vG31ERv7+/xr1QhyELkXQhG3ENHw8+zeAMlg3sYZb/8 l9h4DsIIbshLsIdSGk/NU94tPLsmTr9eKr2p4g== Subject: [Intel-gfx] [PATCH] drm/i915/pmu: avoid -Wmaybe-uninitialized warning X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP The conditional spinlock confuses gcc into thinking the 'flags' value might contain uninitialized data: drivers/gpu/drm/i915/i915_pmu.c: In function '__i915_pmu_event_read': arch/x86/include/asm/paravirt_types.h:573:3: error: 'flags' may be used uninitialized in this function [-Werror=maybe-uninitialized] The code is correct, but it's easy to see how the compiler gets confused here. This avoids the problem by pulling the lock outside of the function into its only caller. Fixes: 1fe699e30113 ("drm/i915/pmu: Fix sleep under atomic in RC6 readout") Signed-off-by: Arnd Bergmann --- drivers/gpu/drm/i915/i915_pmu.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c index 4bc7aefa9541..2c8c705d1f18 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -415,7 +415,6 @@ static u64 __get_rc6(struct drm_i915_private *i915) static u64 get_rc6(struct drm_i915_private *i915, bool locked) { #if IS_ENABLED(CONFIG_PM) - unsigned long flags; u64 val; if (intel_runtime_pm_get_if_in_use(i915)) { @@ -428,18 +427,12 @@ static u64 get_rc6(struct drm_i915_private *i915, bool locked) * previously. */ - if (!locked) - spin_lock_irqsave(&i915->pmu.lock, flags); - if (val >= i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) { i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = 0; i915->pmu.sample[__I915_SAMPLE_RC6].cur = val; } else { val = i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur; } - - if (!locked) - spin_unlock_irqrestore(&i915->pmu.lock, flags); } else { struct pci_dev *pdev = i915->drm.pdev; struct device *kdev = &pdev->dev; @@ -452,9 +445,6 @@ static u64 get_rc6(struct drm_i915_private *i915, bool locked) * on top of the last known real value, as the approximated RC6 * counter value. */ - if (!locked) - spin_lock_irqsave(&i915->pmu.lock, flags); - spin_lock_irqsave(&kdev->power.lock, flags2); if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) @@ -470,9 +460,6 @@ static u64 get_rc6(struct drm_i915_private *i915, bool locked) val = jiffies_to_nsecs(val); val += i915->pmu.sample[__I915_SAMPLE_RC6].cur; i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = val; - - if (!locked) - spin_unlock_irqrestore(&i915->pmu.lock, flags); } return val; @@ -519,8 +506,16 @@ static u64 __i915_pmu_event_read(struct perf_event *event, bool locked) val = count_interrupts(i915); break; case I915_PMU_RC6_RESIDENCY: - val = get_rc6(i915, locked); - break; + if (!locked) { + unsigned long flags; + + spin_lock_irqsave(&i915->pmu.lock, flags); + val = get_rc6(i915, locked); + spin_unlock_irqrestore(&i915->pmu.lock, flags); + break; + } else { + val = get_rc6(i915, locked); + } } }