From patchwork Tue Mar 4 03:44:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 25643 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 130CC206F3 for ; Tue, 4 Mar 2014 03:44:41 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id fb1sf1938539pad.0 for ; Mon, 03 Mar 2014 19:44:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=re7jHNVDi721AZRRiFDFnUo6s6IVsu0GI6e1i7IPPpc=; b=ZgI4Bo7vuBJ9/vNcB3crYhoBYc6wa2tBeFAjYDHdfPztnOdcDgRUeyQC5paxeJ1mSo nZn/pO1TQGGr0ZcE4MaxKK+WwJNePz5d7YS5NVZo2n2qWcfQqCMhTnhyZhxYjn5ZxGPG aTCye2vIZMLwNCwyuiT+Ts+sc0qa4wnBlgL+RkLKZijN4eFCd9hVuRiH+k8QjGmg7YwS 0wMLaYM15n1WwvYaOlEEVPC5VLvOr5iJ/nBb/uO5OmHIU3a4hMeMNlJD0vM0I51buZDq FDWF5j74RuSkKkWpRCPhXkbvSwQ4svNvIpC66LG+HoDrOJlf42nYwpw4IltEH1VZzWt7 a1wQ== X-Gm-Message-State: ALoCoQlr75+otMnw9/o4J+I4mV72PNfHcihhegXDj8/IJ4cW8X+41pSCIRzYa31Slv4FlF6GPWEI X-Received: by 10.66.66.109 with SMTP id e13mr1469777pat.1.1393904681272; Mon, 03 Mar 2014 19:44:41 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.88.101 with SMTP id s92ls2478320qgd.82.gmail; Mon, 03 Mar 2014 19:44:41 -0800 (PST) X-Received: by 10.58.161.205 with SMTP id xu13mr9759881veb.4.1393904681159; Mon, 03 Mar 2014 19:44:41 -0800 (PST) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id e10si3672735vcn.16.2014.03.03.19.44.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Mar 2014 19:44:41 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id oy12so2704304veb.4 for ; Mon, 03 Mar 2014 19:44:41 -0800 (PST) X-Received: by 10.58.132.203 with SMTP id ow11mr20197359veb.1.1393904681069; Mon, 03 Mar 2014 19:44:41 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.130.193 with SMTP id u1csp98959vcs; Mon, 3 Mar 2014 19:44:40 -0800 (PST) X-Received: by 10.68.247.201 with SMTP id yg9mr7358280pbc.148.1393904680176; Mon, 03 Mar 2014 19:44:40 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yp10si12656363pab.98.2014.03.03.19.44.39; Mon, 03 Mar 2014 19:44:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756165AbaCDDob (ORCPT + 11 others); Mon, 3 Mar 2014 22:44:31 -0500 Received: from mail-pd0-f172.google.com ([209.85.192.172]:41779 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756160AbaCDDo2 (ORCPT ); Mon, 3 Mar 2014 22:44:28 -0500 Received: by mail-pd0-f172.google.com with SMTP id p10so4555867pdj.17 for ; Mon, 03 Mar 2014 19:44:28 -0800 (PST) X-Received: by 10.66.144.102 with SMTP id sl6mr3393356pab.96.1393904668157; Mon, 03 Mar 2014 19:44:28 -0800 (PST) Received: from localhost (z88l218.static.ctm.net. [202.175.88.218]) by mx.google.com with ESMTPSA id yx3sm15052541pbb.6.2014.03.03.19.44.25 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Mar 2014 19:44:27 -0800 (PST) From: Viresh Kumar To: rjw@rjwysocki.net, skannan@codeaurora.org Cc: linaro-kernel@lists.linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, srivatsa.bhat@linux.vnet.ibm.com, Viresh Kumar Subject: [PATCH V2 2/3] cpufreq: Initialize policy before making it available for others to use Date: Tue, 4 Mar 2014 11:44:00 +0800 Message-Id: <99ab97f08241ac295eae898b48587fedda13f340.1393904428.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org> References: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org> In-Reply-To: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org> References: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Policy must be fully initialized before it is being made available for use by others. Otherwise cpufreq_cpu_get() would be able to grab a half initialized policy structure that might not have affected_cpus (for example) filled. And so anybody accessing those fields will get the wrong value and hence the results would be unpredictable. So, in order to fix this lets do all the necessary initialization before we make policy structure available via cpufreq_cpu_get(). With this we can guarantee that any code accessing fields of policy would be stable enough, as policy would be completely initialized by now. Signed-off-by: Viresh Kumar --- V1->V2: - Improved commit logs drivers/cpufreq/cpufreq.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index fff2968..3c6f9a5 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1114,6 +1114,20 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, goto err_set_policy_cpu; } + /* related cpus should atleast have policy->cpus */ + cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus); + + /* + * affected cpus must always be the one, which are online. We aren't + * managing offline cpus here. + */ + cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); + + if (!frozen) { + policy->user_policy.min = policy->min; + policy->user_policy.max = policy->max; + } + write_lock_irqsave(&cpufreq_driver_lock, flags); for_each_cpu(j, policy->cpus) per_cpu(cpufreq_cpu_data, j) = policy; @@ -1167,20 +1181,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, } } - /* related cpus should atleast have policy->cpus */ - cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus); - - /* - * affected cpus must always be the one, which are online. We aren't - * managing offline cpus here. - */ - cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); - - if (!frozen) { - policy->user_policy.min = policy->min; - policy->user_policy.max = policy->max; - } - blocking_notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_START, policy);