From patchwork Mon Jun 8 12:55:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 49618 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 20E1021419 for ; Mon, 8 Jun 2015 12:56:50 +0000 (UTC) Received: by wgme6 with SMTP id e6sf32496614wgm.3 for ; Mon, 08 Jun 2015 05:56:49 -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=2FjS3IEfMJVFrgbs1zmHr+8NiV1W0n2LcdUX0RLdGuc=; b=mEbcRJrtuD9M6WlRjIg+LepWjwlMcQF1DUAZJIv3nLkrwmHjeK3xD1Af51ZqF/VHCS RTXGIRHICBbRKBF1y67d9QZdEF4MRDgUqt0sNiTE4fqKR5ulXJ/c1IoGOJHI7gFeLZHs gz2ECjSx860u0eno9atSPP99/fDwG42aVbh+NVhMkxiibJFwaQHKJeTMOmAHjQ3QQzRP sUA3yyldKNNoVlikdfIPfwvjUDEHAqum/V9a2fNzsc3IHqmklX10xNQ+WJIMA02D3L+3 0nvplj/dIV87TLJ6tk2MVARWnIxaNECmj3VCNriZaV5M7pMDyofsc7Iao7emzvx6tHY8 pbZg== X-Gm-Message-State: ALoCoQl7vMTe1We+nifropeOkhXdDXrQbOoUlf9UCvyUbjBSDTMskugGTeSM+pX7O0G0nnH4Qzz+ X-Received: by 10.152.42.208 with SMTP id q16mr16987722lal.9.1433768209337; Mon, 08 Jun 2015 05:56:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.116.108 with SMTP id jv12ls691201lab.9.gmail; Mon, 08 Jun 2015 05:56:49 -0700 (PDT) X-Received: by 10.152.120.135 with SMTP id lc7mr16232329lab.107.1433768209192; Mon, 08 Jun 2015 05:56:49 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id 7si2638229law.133.2015.06.08.05.56.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jun 2015 05:56:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by labpy14 with SMTP id py14so96410055lab.0 for ; Mon, 08 Jun 2015 05:56:49 -0700 (PDT) X-Received: by 10.152.22.99 with SMTP id c3mr16723675laf.32.1433768209073; Mon, 08 Jun 2015 05:56:49 -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 hn6csp1845215lbb; Mon, 8 Jun 2015 05:56:47 -0700 (PDT) X-Received: by 10.70.87.231 with SMTP id bb7mr29308071pdb.70.1433768202665; Mon, 08 Jun 2015 05:56:42 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id df1si4029496pad.84.2015.06.08.05.56.41; Mon, 08 Jun 2015 05:56:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753080AbbFHM4k (ORCPT + 11 others); Mon, 8 Jun 2015 08:56:40 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:33458 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932135AbbFHM4C (ORCPT ); Mon, 8 Jun 2015 08:56:02 -0400 Received: by padev16 with SMTP id ev16so39825288pad.0 for ; Mon, 08 Jun 2015 05:56:01 -0700 (PDT) X-Received: by 10.68.139.225 with SMTP id rb1mr28918432pbb.68.1433768161888; Mon, 08 Jun 2015 05:56:01 -0700 (PDT) Received: from localhost ([122.167.219.251]) by mx.google.com with ESMTPSA id gv10sm2588579pbd.32.2015.06.08.05.56.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 08 Jun 2015 05:56:00 -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 V7 3/6] cpufreq: Initialize policy->kobj while allocating policy Date: Mon, 8 Jun 2015 18:25:29 +0530 Message-Id: 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.50 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 | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 663a934259a4..d890804d561f 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1131,9 +1131,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) @@ -1145,6 +1146,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); @@ -1152,13 +1160,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: @@ -1167,13 +1177,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_remove_dev_symlink(policy); @@ -1273,7 +1284,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; } @@ -1313,15 +1324,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; @@ -1413,18 +1415,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: @@ -1520,7 +1516,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, @@ -1570,7 +1566,7 @@ static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif) return 0; } - cpufreq_policy_put_kobj(policy); + cpufreq_policy_put_kobj(policy, true); cpufreq_policy_free(policy); return 0; }