From patchwork Fri May 8 06:23:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 48151 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0AE7A2121F for ; Fri, 8 May 2015 06:25:03 +0000 (UTC) Received: by wizk4 with SMTP id k4sf4249705wiz.2 for ; Thu, 07 May 2015 23:25:02 -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=GEy/VgztvU92r2OKUy2wRQNaXecCzQJdzNKgoPCcgK0=; b=mYNsDmJDumCHqlxPCdthGnLoBwvN9OYOogzSArXIO7OWiJdEITBQTvEDDRN8tcKIlw pwh8OJq4orNfms8JjYQM4hIQbmPRLBmJFPTFfcKM+ZWqXDIcu5JMbg+XYJ4wvqmyQcRo 7Sbdxn3svVvpT40egTswbjVNpmOrcdLnc/VuaxjJUMpyDOZoYg37zKvmOdiKjIv++Xso Tf0CtonO32zQ88W4yxAch8zRzXnOSbn4JvqloMIo5UVY2C7KJDJwpPCnntZ6EDqbuQFQ XEXE090mDBOIphH6do1Ylh+/81vPJHtRghLLuf/FPdtOasEjx7DyJk82OJXplr3ZQZju XYIQ== X-Gm-Message-State: ALoCoQleHI4pLUJ8T/Pis/3sCTOisuKJb5pe6DcGSQ/X8lQNLfQoW1SSQvD9wKg0IkcVy/jmhdUJ X-Received: by 10.180.98.130 with SMTP id ei2mr1053277wib.0.1431066302313; Thu, 07 May 2015 23:25:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.231 with SMTP id i7ls281411lae.85.gmail; Thu, 07 May 2015 23:25:02 -0700 (PDT) X-Received: by 10.152.203.162 with SMTP id kr2mr1698948lac.68.1431066302156; Thu, 07 May 2015 23:25:02 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id oc2si2694198lbb.1.2015.05.07.23.25.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 May 2015 23:25:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by layy10 with SMTP id y10so46032172lay.0 for ; Thu, 07 May 2015 23:25:01 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr1645983lbc.41.1431066301877; Thu, 07 May 2015 23:25:01 -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 hn6csp269265lbb; Thu, 7 May 2015 23:25:01 -0700 (PDT) X-Received: by 10.66.234.134 with SMTP id ue6mr3933324pac.146.1431066300158; Thu, 07 May 2015 23:25:00 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t17si5783046pdi.227.2015.05.07.23.24.59; Thu, 07 May 2015 23:25:00 -0700 (PDT) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751326AbbEHGY6 (ORCPT + 11 others); Fri, 8 May 2015 02:24:58 -0400 Received: from mail-pd0-f180.google.com ([209.85.192.180]:33058 "EHLO mail-pd0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751319AbbEHGY6 (ORCPT ); Fri, 8 May 2015 02:24:58 -0400 Received: by pdbnk13 with SMTP id nk13so66954301pdb.0 for ; Thu, 07 May 2015 23:24:58 -0700 (PDT) X-Received: by 10.70.34.97 with SMTP id y1mr3858170pdi.101.1431066280396; Thu, 07 May 2015 23:24:40 -0700 (PDT) Received: from localhost ([122.172.243.237]) by mx.google.com with ESMTPSA id fp3sm3992349pdb.52.2015.05.07.23.24.38 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 07 May 2015 23:24:39 -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 V3 07/14] cpufreq: Don't allow updating inactive-policies from sysfs Date: Fri, 8 May 2015 11:53:50 +0530 Message-Id: <6ad4377106496d9d148005c902602c66eb307930.1431065963.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.48 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 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index bd8a47b5054e..652a843a553b 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -887,11 +887,22 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, down_write(&policy->rwsem); + /* + * Policy might not be active currently, and so we shouldn't try + * updating any values here. policy->cpus is cleared for inactive policy + * and so cpufreq_cpu_get_raw() should fail. + */ + 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); @@ -1619,6 +1630,14 @@ static unsigned int __cpufreq_get(struct cpufreq_policy *policy) ret_freq = cpufreq_driver->get(policy->cpu); + /* + * Policy might not be active currently, and so we shouldn't try + * updating any values here. policy->cpus is cleared for inactive policy + * and so cpufreq_cpu_get_raw() should fail. + */ + 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