From patchwork Thu Feb 19 11:32:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 44830 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 88FF821554 for ; Thu, 19 Feb 2015 11:34:43 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf5182813wib.2 for ; Thu, 19 Feb 2015 03:34:42 -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=G3wAGAYwDVF4gMsqAPb7uMauKkZj7nxW8B8txANddK4=; b=gEbfqnmXKCM9s/AYwdtZe/yV636Jfpd3XKaxh25YWyjQ4jI8J6Wh4JIfcbl2SIqLBH IPRuzGH5qkp6gY7Fg/w/ehl0pBSQPtd9WvBGNO1T3SRZyUA4FD/KyymuXABVSYAKAvC9 Xq7KMVf+xBOmDIwKw/S6HTlZhIoHq+sG5jujaVzO6EF0h4O85PToLJW5BfYN9ci9H1KY SePimx8fDdrI4982EUO0LSfJOGNfacJZiJe/SdITACkqa7KlH9AgD/euuIKTUflJivRB 1pWVLKOIqN3DD0Adt10d5nqyH8CrlxshiI97PxzoXRC/LF/XIwdsemtkFm1+FHA5nyh2 yWoA== X-Gm-Message-State: ALoCoQmW++juq+OwE1kbaLId8eTLAvk0p2TqjKDJMeARlPkMQ1zNaBQV0UKctWwHO1dYaWz0Svp6 X-Received: by 10.152.6.232 with SMTP id e8mr520339laa.2.1424345682709; Thu, 19 Feb 2015 03:34:42 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.134 with SMTP id dc6ls119946lad.87.gmail; Thu, 19 Feb 2015 03:34:42 -0800 (PST) X-Received: by 10.152.245.38 with SMTP id xl6mr3628050lac.68.1424345682554; Thu, 19 Feb 2015 03:34:42 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id kw11si14759541lac.30.2015.02.19.03.34.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Feb 2015 03:34:42 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbjb6 with SMTP id b6so6879694lbj.12 for ; Thu, 19 Feb 2015 03:34:42 -0800 (PST) X-Received: by 10.152.26.199 with SMTP id n7mr3454223lag.29.1424345682370; Thu, 19 Feb 2015 03:34:42 -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.112.35.133 with SMTP id h5csp431992lbj; Thu, 19 Feb 2015 03:34:41 -0800 (PST) X-Received: by 10.68.98.98 with SMTP id eh2mr7035621pbb.112.1424345680506; Thu, 19 Feb 2015 03:34:40 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bm5si944378pbd.217.2015.02.19.03.34.39; Thu, 19 Feb 2015 03:34:40 -0800 (PST) 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 S1753479AbbBSLeb (ORCPT + 11 others); Thu, 19 Feb 2015 06:34:31 -0500 Received: from mail-pa0-f53.google.com ([209.85.220.53]:38548 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753418AbbBSLe3 (ORCPT ); Thu, 19 Feb 2015 06:34:29 -0500 Received: by padbj1 with SMTP id bj1so8869934pad.5 for ; Thu, 19 Feb 2015 03:34:29 -0800 (PST) X-Received: by 10.70.123.1 with SMTP id lw1mr7239292pdb.26.1424345669511; Thu, 19 Feb 2015 03:34:29 -0800 (PST) Received: from localhost ([122.172.249.58]) by mx.google.com with ESMTPSA id ev2sm23397064pbb.69.2015.02.19.03.34.28 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 19 Feb 2015 03:34:28 -0800 (PST) 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, Viresh Kumar Subject: [PATCH V2 17/20] cpufreq: Initialize policy->kobj while allocating policy Date: Thu, 19 Feb 2015 17:02:19 +0530 Message-Id: <616a114169996c54547a4d9e60c8c003df68b81b.1424345053.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.3.0.rc0.44.ga94655d 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.217.181 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: , policy->kobj is required to be initialized once in the lifetime of a policy. Currently we are initializing it from __cpufreq_add_dev() and that doesn't look to be the best place for doing so as we have to do this on special cases (like: !recover_policy). We can initialize it from a more obvious place cpufreq_policy_alloc() and that will make code look cleaner, specially the error handling part. The error handling part of __cpufreq_add_dev() was doing almost the same thing while recover_policy is true or false. Fix that as well by always calling cpufreq_policy_put_kobj() with an additional parameter to skip notification part of it. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 814a8c70e2b1..4fb5041ebfab 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1125,9 +1125,10 @@ static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu) return policy; } -static struct cpufreq_policy *cpufreq_policy_alloc(int cpu) +static struct cpufreq_policy *cpufreq_policy_alloc(struct device *dev) { struct cpufreq_policy *policy; + int ret; policy = kzalloc(sizeof(*policy), GFP_KERNEL); if (!policy) @@ -1139,6 +1140,13 @@ static struct cpufreq_policy *cpufreq_policy_alloc(int cpu) if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) goto err_free_cpumask; + ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, &dev->kobj, + "cpufreq"); + if (ret) { + pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret); + goto err_free_rcpumask; + } + INIT_LIST_HEAD(&policy->policy_list); init_rwsem(&policy->rwsem); spin_lock_init(&policy->transition_lock); @@ -1146,13 +1154,15 @@ static struct cpufreq_policy *cpufreq_policy_alloc(int cpu) init_completion(&policy->kobj_unregister); INIT_WORK(&policy->update, handle_update); - policy->cpu = cpu; + policy->cpu = dev->id; /* Set this once on allocation */ - policy->kobj_cpu = cpu; + policy->kobj_cpu = dev->id; return policy; +err_free_rcpumask: + free_cpumask_var(policy->related_cpus); err_free_cpumask: free_cpumask_var(policy->cpus); err_free_policy: @@ -1161,13 +1171,14 @@ static struct cpufreq_policy *cpufreq_policy_alloc(int cpu) return NULL; } -static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy) +static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy, bool notify) { struct kobject *kobj; struct completion *cmp; - blocking_notifier_call_chain(&cpufreq_policy_notifier_list, - CPUFREQ_REMOVE_POLICY, policy); + if (notify) + blocking_notifier_call_chain(&cpufreq_policy_notifier_list, + CPUFREQ_REMOVE_POLICY, policy); down_write(&policy->rwsem); cpufreq_add_remove_dev_symlink(policy, false); @@ -1245,7 +1256,7 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) policy = recover_policy ? cpufreq_policy_restore(cpu) : NULL; if (!policy) { recover_policy = false; - policy = cpufreq_policy_alloc(cpu); + policy = cpufreq_policy_alloc(dev); if (!policy) goto nomem_out; } @@ -1276,15 +1287,6 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) policy->user_policy.min = policy->min; policy->user_policy.max = policy->max; - /* prepare interface data */ - ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, - &dev->kobj, "cpufreq"); - if (ret) { - pr_err("%s: failed to init policy->kobj: %d\n", - __func__, ret); - goto err_init_policy_kobj; - } - write_lock_irqsave(&cpufreq_driver_lock, flags); for_each_cpu(j, policy->related_cpus) per_cpu(cpufreq_cpu_data, j) = policy; @@ -1376,18 +1378,12 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) err_out_unregister: err_get_freq: - if (!recover_policy) { - kobject_put(&policy->kobj); - wait_for_completion(&policy->kobj_unregister); - } -err_init_policy_kobj: up_write(&policy->rwsem); if (cpufreq_driver->exit) cpufreq_driver->exit(policy); err_set_policy_cpu: - if (recover_policy) - cpufreq_policy_put_kobj(policy); + cpufreq_policy_put_kobj(policy, recover_policy); cpufreq_policy_free(policy); nomem_out: @@ -1486,7 +1482,7 @@ static int __cpufreq_remove_dev_finish(struct device *dev, /* Free the policy kobjects only if the driver is getting removed. */ if (sif) - cpufreq_policy_put_kobj(policy); + cpufreq_policy_put_kobj(policy, true); /* * Perform the ->exit() even during light-weight tear-down,