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: 131452 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp647254ljb; Tue, 13 Mar 2018 05:09:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELth4dcU5a7Cwhf27hCDZN8ZLbYBrM211HAczbky1vjhVZBDYgzdPnEM/GFPF/UXoiz388XV X-Received: by 10.101.96.5 with SMTP id m5mr317728pgu.374.1520942949585; Tue, 13 Mar 2018 05:09:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520942949; cv=none; d=google.com; s=arc-20160816; b=fW4+5/R0kLmPc57CG4nZvKBBVcyW7I8oh5iih8l3g7KPPMDtxYwZ1YBpRC2QBT5dre LUHLlXZ1gUBSmw4VUjkcamAB+mnLm7gov7HjpwTdUCMdmSwBbYumiI8jZdXKxZzlhIdK d/fUGz//6QADofDhSV5K0RgI6B/7+jsq7ggVUYrEoA0EXaTA6M3kw5S20VpaBDWVfQnK eg6i65NQuMewBQF2c1B1MEvo3hp09rOLPz56STDvs5LkQpWVHg5om84ObNOjbOX/KLZD 4gIuUYLvTgCHBfTN48tbpOtihgTl+D2rd4Po+5YluZMtkldJZQncIC6OBKiCSDX1F1rE h4Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=COWNkewrTj0l5j4OUSrE8rLR+Ec9/RVqk9ZgQE3k3r4=; b=phmUhQOPWBbF2IeEdzZpIMODmf9kPk678PrQ42i7aBYGwi2OnEjrV7/CxX7URvv5Jb 9Gx4P348iEbLK5/3v0csBpxNhZNP0QEA1Ee8LOC0vDtAIdMpDgk3NCE8YMowjB13JIGC Zjx2T12n5veWalX4FsjW2XHTWIBVvSSW1vvW2Bqs/931peyVF35TBuiPqSiJuX/PB8f9 DwFk2cAdx9gaEWL7CEs+FG6/jdsSab0Pp1rOovNu1pX248bQ0IhQ5c6CRrC65QLpymo3 oN2a5FR5cSWpoh5pJsMbMXL21PDy//0pHbcIrBjk03/eyfG9LJhe54g5kAFehfSd8cMa /00w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w31-v6si47230pla.315.2018.03.13.05.09.09; Tue, 13 Mar 2018 05:09:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933574AbeCMMJF (ORCPT + 28 others); Tue, 13 Mar 2018 08:09:05 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:42593 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933497AbeCMMJC (ORCPT ); Tue, 13 Mar 2018 08:09:02 -0400 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 Cc: Arnd Bergmann , Tvrtko Ursulin , Chris Wilson , Michal Wajdeczko , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/i915/pmu: avoid -Wmaybe-uninitialized warning 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== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.9.0 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); + } } }