From patchwork Mon Jan 11 17:35:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 59563 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2253272lbb; Mon, 11 Jan 2016 09:40:22 -0800 (PST) X-Received: by 10.66.155.8 with SMTP id vs8mr182835809pab.18.1452534021894; Mon, 11 Jan 2016 09:40:21 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xe7si40968276pab.3.2016.01.11.09.40.21; Mon, 11 Jan 2016 09:40:21 -0800 (PST) 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 S1761329AbcAKRkR (ORCPT + 29 others); Mon, 11 Jan 2016 12:40:17 -0500 Received: from foss.arm.com ([217.140.101.70]:57248 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761161AbcAKRha (ORCPT ); Mon, 11 Jan 2016 12:37:30 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 26F7F5F7; Mon, 11 Jan 2016 09:36:55 -0800 (PST) Received: from e106622-lin.cambridge.arm.com (e106622-lin.cambridge.arm.com [10.1.208.152]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1C64C3F24D; Mon, 11 Jan 2016 09:37:27 -0800 (PST) From: Juri Lelli To: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, peterz@infradead.org, rjw@rjwysocki.net, viresh.kumar@linaro.org, mturquette@baylibre.com, steve.muckle@linaro.org, vincent.guittot@linaro.org, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, juri.lelli@arm.com Subject: [RFC PATCH 09/19] cpufreq: fix warning for show_scaling_available_governors unlocked access to cpufreq_governor_list Date: Mon, 11 Jan 2016 17:35:50 +0000 Message-Id: <1452533760-13787-10-git-send-email-juri.lelli@arm.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1452533760-13787-1-git-send-email-juri.lelli@arm.com> References: <1452533760-13787-1-git-send-email-juri.lelli@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org show_scaling_available_governors iterates through cpufreq_governor_list without holding cpufreq_governor_mutex; this generates the following warning: [ 700.910381] ------------[ cut here ]------------ [ 700.924282] WARNING: CPU: 2 PID: 1756 at kernel/drivers/cpufreq/cpufreq.c:700 show_scaling_available_governors+0x6f/0xb8() [ 700.965473] Modules linked in: [ 700.974637] CPU: 2 PID: 1756 Comm: cat Tainted: G W 4.4.0-rc2+ #299 [ 700.996813] Hardware name: ARM-Versatile Express [ 701.010674] [] (unwind_backtrace) from [] (show_stack+0x11/0x14) [ 701.033905] [] (show_stack) from [] (dump_stack+0x55/0x78) [ 701.055561] [] (dump_stack) from [] (warn_slowpath_common+0x59/0x84) [ 701.079839] [] (warn_slowpath_common) from [] (warn_slowpath_null+0x17/0x1c) [ 701.106182] [] (warn_slowpath_null) from [] (show_scaling_available_governors+0x6f/0xb8) [ 701.135656] [] (show_scaling_available_governors) from [] (show+0x27/0x38) [ 701.161488] [] (show) from [] (sysfs_kf_seq_show+0x5f/0xa0) [ 701.183409] [] (sysfs_kf_seq_show) from [] (kernfs_seq_show+0x1b/0x1c) [ 701.208188] [] (kernfs_seq_show) from [] (seq_read+0x129/0x33c) [ 701.231161] [] (seq_read) from [] (__vfs_read+0x1b/0x84) [ 701.252300] [] (__vfs_read) from [] (vfs_read+0x5f/0xb0) [ 701.273436] [] (vfs_read) from [] (SyS_read+0x39/0x68) [ 701.294049] [] (SyS_read) from [] (ret_fast_syscall+0x1/0x1a) [ 701.316484] ---[ end trace 5dd15744a4da127c ]--- Fix this by locking cpufreq_governor_mutex before for_each_governor(). Cc: "Rafael J. Wysocki" Cc: Viresh Kumar Signed-off-by: Juri Lelli --- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.2.2 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index d065435..d91fdb8 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -694,7 +694,7 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy, goto out; } - lockdep_assert_held(&cpufreq_governor_mutex); + mutex_lock(&cpufreq_governor_mutex); for_each_governor(t) { if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) - (CPUFREQ_NAME_LEN + 2))) @@ -702,6 +702,7 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy, i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name); } out: + mutex_unlock(&cpufreq_governor_mutex); i += sprintf(&buf[i], "\n"); return i; }