From patchwork Tue Mar 13 16:19:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10279871 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 B70266038F for ; Tue, 13 Mar 2018 16:25:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A76AF284B3 for ; Tue, 13 Mar 2018 16:25:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BC9028B22; Tue, 13 Mar 2018 16:25:24 +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 0451B284B3 for ; Tue, 13 Mar 2018 16:25:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 63B446E5A4; Tue, 13 Mar 2018 16:25:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1FE086E5A4 for ; Tue, 13 Mar 2018 16:25:19 +0000 (UTC) Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0LgXtF-1eGd0T0wNx-00nzzh; Tue, 13 Mar 2018 17:19:56 +0100 From: Arnd Bergmann To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie Subject: [PATCH] [v2] drm/i915/pmu: avoid -Wmaybe-uninitialized warning Date: Tue, 13 Mar 2018 17:19:31 +0100 Message-Id: <20180313161952.552083-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:u65WKnmySMO/FelMrDXo7VnOyCqGV8M3jI0/A5LNAT6pJqaUZE0 wcUi2Wr0wQ7+FbaU3A5pcUFwLUqjd2464PjfemppuaVVIyhmTwWAAfRbE29D+O1S1KgPCZ/ Sv1rP1MzDm9vkV5BU+nb/M5YcxKYIPoWlGLHc5U+qTcA9qhKY4BUO7lY+HouW9SAZFZmUgT tmZ1YGFWQ2or4DjeM2MHw== X-UI-Out-Filterresults: notjunk:1; V01:K0:hT3uCVa3mV4=:D9btpAoKQUpjB19cGkQ6mw GN3R8mXhtwK3pv+AHuQaillbHm+4q1O7CnyWYjQiLzTnX/nxbQpupTzgv4Jfgf6T/fXJEXUmI Dtym9zpAZFOD0nEsgfE8nQU/qSfbqZWIXwvmyZ8wU3M2WLq63rX7uCtV8Pk49dq4Wcuk+CKYu uKVwDmlElPmjB2XpUwfgDa7U5wZiP8E3H4UVzTTC1uShomjSzYSeIi7+YDgKpgu5HYoMlHRfB YES2vK9gLeCWjdcZTz3ahV3uzyqAtEs3SwHPPXwC5LozIqNZJf0M5D6IpWKsfL04uGOpgz9VO Qgb8ZkmYtSfsjTFZeV3w74AfXHQdAKKzt/tNXNPm/OLv2QpdRgksXxaBmk8msRBl9uRa2PXqH Poer3oJvvGbfkR0cEfEX+QOtv3LRkTNL3aDSrmsINakwD3e6o8F893W+I7Ag0TXzkF2ThprAb Fh193BIzJqGakJR6hL3vNl2loNuM8C5jFu0sIxoF595kImCBEtutF8zsHyx6nW/EmkToC071i 5nIL/OhFe2T8tw2AEtmTUgPu8vjVndAJ8h4Fovr2l2KEmEHy6lDXo7o4fkHL0VDttgZkkwjWI vA4S17Xw5B82ZI8MGQoivhV8qLdUMXDJluW01x/IrYVmyZDQsQY9oXGFcZ6iOWcTgpN2GbLB9 fzOgwNumODZlaNjUvjvxOM5uwPGsanGhC9Vc16Zc0DjujqH+Sr+Pxlfm7vHwda/qICzaOlOIL xynT5v5g89oiMXssndCacL9+9Hkwy3TwB8w13g== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Tvrtko Ursulin , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Michal Wajdeczko MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 Reviewed-by: Chris Wilson --- v2: removed unused function argument, fixed 'break' statement. --- 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..d6b9b6b5fb98 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -412,10 +412,9 @@ static u64 __get_rc6(struct drm_i915_private *i915) return val; } -static u64 get_rc6(struct drm_i915_private *i915, bool locked) +static u64 get_rc6(struct drm_i915_private *i915) { #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,7 +506,15 @@ 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); + if (!locked) { + unsigned long flags; + + spin_lock_irqsave(&i915->pmu.lock, flags); + val = get_rc6(i915); + spin_unlock_irqrestore(&i915->pmu.lock, flags); + } else { + val = get_rc6(i915); + } break; } }