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: 131501 Delivered-To: patch@linaro.org Received: by 10.80.210.197 with SMTP id q5csp1031237edg; Tue, 13 Mar 2018 09:20:17 -0700 (PDT) X-Google-Smtp-Source: AG47ELuv+hZzGSL3xa8waEsqPDBBRk3WYG9YA9SYNHt3R45xgaIKiMwDuGArzB5lZyS039q40idO X-Received: by 10.101.92.6 with SMTP id u6mr949884pgr.440.1520958017611; Tue, 13 Mar 2018 09:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520958017; cv=none; d=google.com; s=arc-20160816; b=MhQSIoRGqNYHk9tU2L9sGrvtJeqcCb7LIB5ZgsLqSPGmYrPvTTxlicYU13eSuB7tcn AATBRdihp3uIfopcXYDspoSYHJB2ob4I2kDC1QyACTDD/HVAHSY87w4Ho0dnLqYk+Wjd d0k8CE/sLSYmfd873VZHG91pdXjx1++TGDTVk07MVSpCQp4BeQBW+47tPRtjV2GX23rh oKJLH1yQo1moYh/FYPlDE+R5bEoXZgaIPIZVdIV2nfPwIPlFlknxFkP8j30dUbeS7kHr T8GruOs1RmNNQX59gwpKqboNRD0Xmr4YlW4zTz/hWZr/Kci4Ymw3Yw9g5A033TrlKOs3 PYKw== 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=kH6j8b9yFapTfZfgn8I3IpPyBQMnDOEVF5QHFVXYZcs=; b=gpaQRsM1StBqq6Dmv3JwU/seplOCVhY2GfvbbE46eJmYEpIT4Q3mjPVrVDKlqRU5wp tGey1JhduUIVF1OIDccURALajKkFbAp9pQBHc6l2NYk3INdJWHIbmaNimc4qcy9UTAQO WxeFT29n2y56vounY/jvtBTXRf0rhU5CORWM8+u+nEHsA8++DKuZBCVb4wNZ8A6E7Pzf HtOu90AgINEcjbQFFK4Kctiog3bZ784OG+Q0LHV2HstlMRdeVZWQyi268SxME0wC9kcw GGrtYyBauLrdEr9SofnWjBk5MM6+kVwtSKcsHSWB0tzvkIkjt37MTH/GmiO/ls0C2b0v VanA== 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 23si374869pfs.275.2018.03.13.09.20.17; Tue, 13 Mar 2018 09:20:17 -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 S933931AbeCMQUN (ORCPT + 28 others); Tue, 13 Mar 2018 12:20:13 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:47723 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932951AbeCMQUI (ORCPT ); Tue, 13 Mar 2018 12:20:08 -0400 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 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] [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:cCVg6YZBdAQ=:y60Ch4LNUKUSaCE8hl3C4M uSPAnz02uWMQoT5WPV2Gt8kugZNS8cG6zSZOl+Sfmmm6sVbFgYZvmXd7ZDK7fWYiwVVdH52n2 +RVqR+HGwKU4GP1b/VsyfhtwA/wEuqp+HRk+3rX0JAZpYHnGm5aN4wpOnpR9QdHTk/S6ZP/G2 +/f2o2CDIZDtqoRxt4E54XgbtRXQ86IWaj1Esp80d0sb3yotSbpLM2mneijjLT1VJ+MbAFZfk ncFG6Yqa1OUg54FmF2c+WMn/roVbusU2dMNnXlvH9YJO1JNoT1H+eOVOLgLk5qXolWGIvKQv5 jSWsvYgCRto7dlP9KlfZgW2ad7SECpOVwRdheycFjizU+TViWsldxFYLFUVuL3ZU6iOBvqjhv 0anlHTzifYQz0nARmDmCAXYt3eAGs1nbfFFQNaO6V5WCjAEYmrhFWm+MUBi/WKOY3+0zFXWFA uuVZLRAXKUAQ23YJ3e2mi/hXP8X1hpC89K0T8747ag1gMso/CHJY00vllmDqqBTMHbrA7pdhd Eiu0w5T4oNpvcDhvBEkRXikQQFmGe0qAuYUHkJSGrL70GWlnSByMuvJod/iijyzpEUhrQhhfy caO6q3xirPN7RHAOgbdfyslQrisZ0v7pOE+FROpVW1gufBIDBSfXgidGwhp79bgrFGQu2yIhe cSAiS082pt5Nmrynv7rUy0CZUhI1PgJahVRsaXobp7f+wllA3MXr8oNk/Tv+QfEsAFP18U9Yl JSo/FPGVIKlUa7FKKwc+BfNl1e4KJSgwHX/vWg== 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 --- v2: removed unused function argument, fixed 'break' statement. --- drivers/gpu/drm/i915/i915_pmu.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) -- 2.9.0 Reviewed-by: Chris Wilson 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; } }