From patchwork Tue Jan 27 08:36:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 43831 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f200.google.com (mail-we0-f200.google.com [74.125.82.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DB01F2409D for ; Tue, 27 Jan 2015 08:37:49 +0000 (UTC) Received: by mail-we0-f200.google.com with SMTP id m14sf6819162wev.3 for ; Tue, 27 Jan 2015 00:37:49 -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=gifq9kYaSivrOMUQVrSVklk0iYJGH4i96tJv4VTW/6c=; b=PORbQgIrCFR4YGn2iIo85SJr7V4YNBRIh95ib63kA64i7OdvkF9+bBP6hY5Sew1mO9 O6lcauRneHyF/AfPMDCgZH7pJPTZlRJ64n7x2J2clFTU8o2kQHvHTKhrFIqxyESjCCEn EKeVtkHzTfG689vOBFmLOOXX4Gj14wQAyqAFOh+9wLvwT1gJsJXFXZr6xkCPTSUqVc/r Z+FucyAvtKAD9AGL1d2I4/iUQBIUjmsmwLL7PdpH2CgbxyzLkufAHwr9OvKVeV4FTYrU i/3NjX/7Nk6MJjJfN+KMPGZuj8oFT791Cj4ID0x7PuvsipxMory4XnI4TeJ3FEO2n/JY tIFw== X-Gm-Message-State: ALoCoQnvDCNL4Ik4r7Kgjk3sfi2GIedD9fZvxdb7Oz7d9iOmbcEpmrN4DlDt3kJ2KRkzxNNDQeow X-Received: by 10.152.87.15 with SMTP id t15mr27080laz.9.1422347869047; Tue, 27 Jan 2015 00:37:49 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.197.2 with SMTP id iq2ls6329lac.2.gmail; Tue, 27 Jan 2015 00:37:48 -0800 (PST) X-Received: by 10.152.207.37 with SMTP id lt5mr157250lac.66.1422347868831; Tue, 27 Jan 2015 00:37:48 -0800 (PST) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id w3si534236law.82.2015.01.27.00.37.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 00:37:48 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id z12so11797931lbi.7 for ; Tue, 27 Jan 2015 00:37:48 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr141555laa.80.1422347868732; Tue, 27 Jan 2015 00:37:48 -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 h5csp1025629lbj; Tue, 27 Jan 2015 00:37:47 -0800 (PST) X-Received: by 10.70.132.39 with SMTP id or7mr206045pdb.90.1422347860884; Tue, 27 Jan 2015 00:37:40 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g8si627522pdk.182.2015.01.27.00.37.40; Tue, 27 Jan 2015 00:37: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 S1757924AbbA0Ihj (ORCPT + 11 others); Tue, 27 Jan 2015 03:37:39 -0500 Received: from mail-pa0-f43.google.com ([209.85.220.43]:36354 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757922AbbA0Ihi (ORCPT ); Tue, 27 Jan 2015 03:37:38 -0500 Received: by mail-pa0-f43.google.com with SMTP id eu11so17194245pac.2 for ; Tue, 27 Jan 2015 00:37:37 -0800 (PST) X-Received: by 10.66.66.46 with SMTP id c14mr124464pat.136.1422347857292; Tue, 27 Jan 2015 00:37:37 -0800 (PST) Received: from localhost ([122.178.198.250]) by mx.google.com with ESMTPSA id zr4sm842256pbb.18.2015.01.27.00.37.36 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 27 Jan 2015 00:37:36 -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 15/18] cpufreq: Initialize policy->kobj while allocating policy Date: Tue, 27 Jan 2015 14:06:21 +0530 Message-Id: <96534b5472118c3f6efcdfb6d9df8d306fddffc9.1422346933.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.176 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 while its allocated. 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 some steps. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index fde0a75f9692..4a97d7428d25 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1067,9 +1067,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) @@ -1081,6 +1082,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_LIST_HEAD(&policy->fallback_list); init_rwsem(&policy->rwsem); @@ -1089,13 +1097,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: @@ -1104,13 +1114,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); @@ -1171,7 +1182,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; } else { @@ -1206,15 +1217,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) if (!recover_policy) { 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); @@ -1305,19 +1307,12 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) write_lock_irqsave(&cpufreq_driver_lock, flags); list_del(&policy->policy_list); write_unlock_irqrestore(&cpufreq_driver_lock, flags); - - 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: @@ -1452,7 +1447,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,