From patchwork Thu Sep 12 11:36:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 20002 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f198.google.com (mail-qc0-f198.google.com [209.85.216.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D2CB420F59 for ; Thu, 12 Sep 2013 11:36:52 +0000 (UTC) Received: by mail-qc0-f198.google.com with SMTP id l13sf7334202qcy.1 for ; Thu, 12 Sep 2013 04:36:52 -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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=1bpe3re4K1VltYz2zn84Wj6rnHb/1dYTpX0k06T1btk=; b=aLg/eFf/Ontb3LUkZMRueTkRQNy7ZqFH7zo1S+sEbFUtFXl2BLNrMiVxATKoVOrSkd lptMn9LP5xv/uNFxqdyGgfMWrHvjyFfJpy0gI3XcPimu7I8J1Ddwg8wsfe5dvaciXWy7 dHTWMgvGL9V4ztBuWfNnVld35mMwJr0gaxK5bzE7Wx11iGk/IJmmNKGHj1mV9iLqW9bf eo2dfHtWHtBRXTHN0hwWbwzeZuCy4v68Ss4LYaoqW6nVc/5bfQgly6Bra3NPy7IE0w7T 6JVK8Gz082GNsKUGUBDfom13N7Nxuf3nQzdrUH7o1XG9a7h9s+NtxzBCv0SPly+1gAWX TGaQ== X-Gm-Message-State: ALoCoQmUv7tpsPwlkAXiyVE39AIXJloOLoKo54Gt7pi++roRXoGFWoePv6V9yaZQ1VVB1QnNtz6K X-Received: by 10.236.0.232 with SMTP id 68mr2647585yhb.16.1378985812335; Thu, 12 Sep 2013 04:36:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.26.102 with SMTP id k6ls685221qeg.5.gmail; Thu, 12 Sep 2013 04:36:52 -0700 (PDT) X-Received: by 10.220.181.136 with SMTP id by8mr6343089vcb.11.1378985812098; Thu, 12 Sep 2013 04:36:52 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id c11si1045671vej.128.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Sep 2013 04:36:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id ij15so7037788vcb.2 for ; Thu, 12 Sep 2013 04:36:52 -0700 (PDT) X-Received: by 10.220.74.69 with SMTP id t5mr6285516vcj.18.1378985812005; Thu, 12 Sep 2013 04:36:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp15285vcz; Thu, 12 Sep 2013 04:36:51 -0700 (PDT) X-Received: by 10.66.158.196 with SMTP id ww4mr9032121pab.57.1378985810676; Thu, 12 Sep 2013 04:36:50 -0700 (PDT) Received: from mail-pb0-f48.google.com (mail-pb0-f48.google.com [209.85.160.48]) by mx.google.com with ESMTPS id u4si2643032pbi.304.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Sep 2013 04:36:50 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.48 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.160.48; Received: by mail-pb0-f48.google.com with SMTP id ma3so10362177pbc.7 for ; Thu, 12 Sep 2013 04:36:50 -0700 (PDT) X-Received: by 10.68.212.106 with SMTP id nj10mr7143267pbc.74.1378985810088; Thu, 12 Sep 2013 04:36:50 -0700 (PDT) Received: from localhost ([106.197.30.106]) by mx.google.com with ESMTPSA id et3sm4241565pbc.43.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 12 Sep 2013 04:36:49 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Viresh Kumar Subject: [PATCH V2] cpufreq: use correct values of cpus in __cpufreq_remove_dev_finish() Date: Thu, 12 Sep 2013 17:06:33 +0530 Message-Id: <01cdf0d2a0523bd0c2bc73d63055df0bf477b5fb.1378984168.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e 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.220.171 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This broke after a recent change "cedb70a cpufreq: Split __cpufreq_remove_dev() into two parts" from Srivatsa.. Consider a scenario where we have two CPUs in a policy (0 & 1) and we are removing cpu 1. On the call to __cpufreq_remove_dev_prepare() we have cleared 1 from policy->cpus and now on a call to __cpufreq_remove_dev_finish() we read cpumask_weight of policy->cpus, which will come as 1 and this code will behave as if we are removing the last cpu from policy :) Fix it by clearing cpu mask in __cpufreq_remove_dev_finish() instead of __cpufreq_remove_dev_prepare(). Reviewed-by: Srivatsa S. Bhat Signed-off-by: Viresh Kumar --- V1->V2: - sent separately without cleanup patches - use cpumask_any_but() instead of cpumask_first() drivers/cpufreq/cpufreq.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 43c24aa..dbfe219 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1125,7 +1125,7 @@ static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy, int ret; /* first sibling now owns the new sysfs dir */ - cpu_dev = get_cpu_device(cpumask_first(policy->cpus)); + cpu_dev = get_cpu_device(cpumask_any_but(policy->cpus, old_cpu)); /* Don't touch sysfs files during light-weight tear-down */ if (frozen) @@ -1189,12 +1189,9 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, policy->governor->name, CPUFREQ_NAME_LEN); #endif - WARN_ON(lock_policy_rwsem_write(cpu)); + lock_policy_rwsem_read(cpu); cpus = cpumask_weight(policy->cpus); - - if (cpus > 1) - cpumask_clear_cpu(cpu, policy->cpus); - unlock_policy_rwsem_write(cpu); + unlock_policy_rwsem_read(cpu); if (cpu != policy->cpu) { if (!frozen) @@ -1237,9 +1234,12 @@ static int __cpufreq_remove_dev_finish(struct device *dev, return -EINVAL; } - lock_policy_rwsem_read(cpu); + WARN_ON(lock_policy_rwsem_write(cpu)); cpus = cpumask_weight(policy->cpus); - unlock_policy_rwsem_read(cpu); + + if (cpus > 1) + cpumask_clear_cpu(cpu, policy->cpus); + unlock_policy_rwsem_write(cpu); /* If cpu is last user of policy, free policy */ if (cpus == 1) {