From patchwork Tue Aug 6 17:23:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 18811 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f199.google.com (mail-ye0-f199.google.com [209.85.213.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4689525DF6 for ; Tue, 6 Aug 2013 17:24:37 +0000 (UTC) Received: by mail-ye0-f199.google.com with SMTP id l12sf707452yen.6 for ; Tue, 06 Aug 2013 10:24:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=HXXeblwnNkFJtVx4Ktn2pY++8L+RQqmpG00XxnbYQfo=; b=I51coWcUak5qnyGUaIW6bgBgHJOiZ3yLznBe9OYB2gTB/cbo2atlvGWMyqO++h5f8i KVw8uuoUY0deQB8G0YnnoqPppvffGSBc3cTHDBbyJ0FCunkx5hf08whg/l5jwH2sybOf qhKy5p82CA70Jz0bD21h3GM4yaiYyH65VoJbBa3wv2uxUsaCZ3wz0gM5TKCwD+Bh2A9O OtcpBuirS33TTr/1VF4C+WfkDikxEoY0OhnE23nnoGHWEHuy9KGpYyyJJH6wZlBUuMil SAE+mWtVoDN/woqW3z8QQyLQZyfsA6lbcmP6x0xj3aanCwTTWgSYiXpNBN9ATGzr9UTI bb6w== X-Received: by 10.236.44.140 with SMTP id n12mr883815yhb.6.1375809876836; Tue, 06 Aug 2013 10:24:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.97.197 with SMTP id ec5ls290141qeb.26.gmail; Tue, 06 Aug 2013 10:24:36 -0700 (PDT) X-Received: by 10.58.128.71 with SMTP id nm7mr698951veb.51.1375809876724; Tue, 06 Aug 2013 10:24:36 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id rx10si540431vdc.8.2013.08.06.10.24.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 Aug 2013 10:24:36 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.172 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.172; Received: by mail-ve0-f172.google.com with SMTP id oz10so720438veb.17 for ; Tue, 06 Aug 2013 10:24:36 -0700 (PDT) X-Gm-Message-State: ALoCoQl9vbhPGEb/i8ladepPJ4tWt40Z/1O5bwq/AYiQVBXvCdCYlhsnfesJcg3+DV0/nNhDQreL X-Received: by 10.58.6.210 with SMTP id d18mr656498vea.96.1375809876609; Tue, 06 Aug 2013 10:24:36 -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.221.11.8 with SMTP id pc8csp157169vcb; Tue, 6 Aug 2013 10:24:36 -0700 (PDT) X-Received: by 10.68.50.138 with SMTP id c10mr2698955pbo.136.1375809875547; Tue, 06 Aug 2013 10:24:35 -0700 (PDT) Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com [209.85.220.48]) by mx.google.com with ESMTPS id qb10si3069424pac.278.2013.08.06.10.24.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 Aug 2013 10:24:35 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.48 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.220.48; Received: by mail-pa0-f48.google.com with SMTP id kp13so1015031pab.7 for ; Tue, 06 Aug 2013 10:24:35 -0700 (PDT) X-Received: by 10.68.211.233 with SMTP id nf9mr2813188pbc.26.1375809875123; Tue, 06 Aug 2013 10:24:35 -0700 (PDT) Received: from localhost ([122.172.193.46]) by mx.google.com with ESMTPSA id fa5sm3158363pbb.3.2013.08.06.10.24.31 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 06 Aug 2013 10:24:34 -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, srivatsa.bhat@linux.vnet.ibm.com, Viresh Kumar Subject: [PATCH V2 08/11] cpufreq: Fix broken usage of governor->owner's refcount Date: Tue, 6 Aug 2013 22:53:10 +0530 Message-Id: <28d948514a30b279afb99ff156bc3a3f74234641.1375809311.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: 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.172 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: , Governor's owner refcount usage was broken. We should increment refcount only when CPUFREQ_GOV_POLICY_INIT event has come and should decrement only if CPUFREQ_GOV_POLICY_EXIT has come. Currently there can be situations where governor is in use but we have allowed it to be unloaded which may result in undefined behavior. Lets fix it. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index fe04b79..62eddb6 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1708,8 +1708,9 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, } } - if (!try_module_get(policy->governor->owner)) - return -EINVAL; + if (event == CPUFREQ_GOV_POLICY_INIT) + if (!try_module_get(policy->governor->owner)) + return -EINVAL; pr_debug("__cpufreq_governor for CPU %u, event %u\n", policy->cpu, event); @@ -1718,6 +1719,8 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, if ((!policy->governor_enabled && (event == CPUFREQ_GOV_STOP)) || (policy->governor_enabled && (event == CPUFREQ_GOV_START))) { mutex_unlock(&cpufreq_governor_lock); + if (event == CPUFREQ_GOV_POLICY_INIT) + module_put(policy->governor->owner); return -EBUSY; } @@ -1745,11 +1748,8 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, mutex_unlock(&cpufreq_governor_lock); } - /* we keep one module reference alive for - each CPU governed by this CPU */ - if ((event != CPUFREQ_GOV_START) || ret) - module_put(policy->governor->owner); - if ((event == CPUFREQ_GOV_STOP) && !ret) + if (((event == CPUFREQ_GOV_POLICY_INIT) && ret) || + ((event == CPUFREQ_GOV_POLICY_EXIT) && !ret)) module_put(policy->governor->owner); return ret;