From patchwork Mon May 18 05:13:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 48674 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CF92921411 for ; Mon, 18 May 2015 05:14:57 +0000 (UTC) Received: by wixv7 with SMTP id v7sf18254834wix.0 for ; Sun, 17 May 2015 22:14:57 -0700 (PDT) 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=p1eRZGzMnWR3txMYnARxC4s65S3rPS8/Yvawjdr1qBU=; b=K2XkJKHCjZ3IsNmG/J7tfuuC0rH1Ogn4xr7iIXjc0onBWGezSANmWLRs8tpOP2eFuQ kgE6KNfFaO0UB7KjnC2sJec6UISVGrndPC7f5mVVo1rUePFrxdwPST9ADx3bkaeSOPY6 HYU3sVOSVW25pI/mzmtxpsi4HPE1+Am4HQYw7XSg14n9wUvxjjbVA5VeSfhHXSR0709F YCNtKnrGe1q0orU2+MNAtqf9wopfl8zvq646KV9u6Z830buwa+ES3ZZ4UUisrzxYq312 EArTwdjTPKKE/DHaYujhsQeCykPCf1vgb8cvuRLY4z+vpKAHdlqEGmaY6fAfspHDlISp qdCA== X-Gm-Message-State: ALoCoQl+m0E4FqrrMBnxJv7fJe8BTI7cqVpLnNtcZz9l9ZsMdj56xFn9GcuIEq9X/Js+MexIu+YN X-Received: by 10.112.42.236 with SMTP id r12mr16563207lbl.2.1431926097176; Sun, 17 May 2015 22:14:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.68 with SMTP id be4ls91488lab.47.gmail; Sun, 17 May 2015 22:14:57 -0700 (PDT) X-Received: by 10.112.218.67 with SMTP id pe3mr15206408lbc.53.1431926097035; Sun, 17 May 2015 22:14:57 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id aw7si5955995lbc.80.2015.05.17.22.14.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 May 2015 22:14:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by lagv1 with SMTP id v1so202094316lag.3 for ; Sun, 17 May 2015 22:14:56 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr15638767lbc.41.1431926096742; Sun, 17 May 2015 22:14:56 -0700 (PDT) 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.112.108.230 with SMTP id hn6csp3711716lbb; Sun, 17 May 2015 22:14:55 -0700 (PDT) X-Received: by 10.70.52.130 with SMTP id t2mr30939476pdo.34.1431926094792; Sun, 17 May 2015 22:14:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id iu9si2678127pbc.77.2015.05.17.22.14.39; Sun, 17 May 2015 22:14:54 -0700 (PDT) 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 S1751148AbbERFOS (ORCPT + 11 others); Mon, 18 May 2015 01:14:18 -0400 Received: from mail-pd0-f178.google.com ([209.85.192.178]:36787 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751149AbbERFOR (ORCPT ); Mon, 18 May 2015 01:14:17 -0400 Received: by pdfh10 with SMTP id h10so133408958pdf.3 for ; Sun, 17 May 2015 22:14:17 -0700 (PDT) X-Received: by 10.66.102.67 with SMTP id fm3mr40377362pab.25.1431926057220; Sun, 17 May 2015 22:14:17 -0700 (PDT) Received: from localhost ([122.167.226.34]) by mx.google.com with ESMTPSA id eu5sm8589285pbb.44.2015.05.17.22.14.16 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 17 May 2015 22:14:16 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, sboyd@codeaurora.org, prarit@redhat.com, skannan@codeaurora.org, Srivatsa Bhat , Viresh Kumar Subject: [PATCH V5 07/14] cpufreq: Don't allow updating inactive policies from sysfs Date: Mon, 18 May 2015 10:43:30 +0530 Message-Id: <427de81ba345cbaba7e36435e825a4234f0f9514.1431924457.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: References: In-Reply-To: References: 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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) 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: , Later commits would change the way policies are managed today. Policies wouldn't be freed on cpu hotplug (currently they aren't freed only for suspend), and while the CPU is offline, the sysfs cpufreq files would still be present. User may accidentally try to update the sysfs files in following directory: '/sys/devices/system/cpu/cpuX/cpufreq/'. And that would result in undefined behavior as policy wouldn't be active then. Apart from updating the store() routine, we also update __cpufreq_get() which can call cpufreq_out_of_sync(). The later routine tries to update policy->cur and starts notifying kernel about it. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index c08de5e985c7..983961ba2f72 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -875,11 +875,18 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, down_write(&policy->rwsem); + /* Updating inactive policies is invalid, so avoid doing that. */ + if (unlikely(policy_is_inactive(policy))) { + ret = -EPERM; + goto unlock_policy_rwsem; + } + if (fattr->store) ret = fattr->store(policy, buf, count); else ret = -EIO; +unlock_policy_rwsem: up_write(&policy->rwsem); up_read(&cpufreq_rwsem); @@ -1607,6 +1614,10 @@ static unsigned int __cpufreq_get(struct cpufreq_policy *policy) ret_freq = cpufreq_driver->get(policy->cpu); + /* Updating inactive policies is invalid, so avoid doing that. */ + if (unlikely(policy_is_inactive(policy))) + return ret_freq; + if (ret_freq && policy->cur && !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { /* verify no discrepancy between actual and