From patchwork Mon Mar 9 04:20:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 45523 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EFCAD20285 for ; Mon, 9 Mar 2015 04:20:40 +0000 (UTC) Received: by wibbs8 with SMTP id bs8sf9751779wib.3 for ; Sun, 08 Mar 2015 21:20:40 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=eylYzhBIsHDSd4tadNdZJIRAAvNyExlZgYBwXfFc904=; b=XC8YCQHdowO6BMFys4z4JUUqirLHRjtm6eErNwdh2odOY6eZDaDmHKkXB+8czBUnpU +jm+raSUcnrKxYYVOAUn+f66KUJBzvZqfvAW63Kpey8VBas+HnhRQIpQMmzZLLzRgMwF 6K9JoENVaSpo+llHXhDzxEYXkEoK3bJkLyWj2ZPkUnyisjV44nnrVy7VG2h7BefU8Q93 Ie/TB0GHq8xmitfMLq5+xMPlQUX6Tx+S3aNhbX+xWzLLGJIQRGA4Gkfc6lG6y53lpmjz XJxJ8TJKP3Phht0IO+PukmsGtGmi9WRFI0c4BLRHEX/CvHdlqsloW+j68DNCce8zrHVT EKJg== X-Gm-Message-State: ALoCoQmtqkcpH4slHpSySYCarxSwJgzb/92IjKo/X1z4hmqfII3+dGFNomkQLeB3AwV1BI9B4v+W X-Received: by 10.194.11.70 with SMTP id o6mr3621002wjb.6.1425874840277; Sun, 08 Mar 2015 21:20:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.225 with SMTP id n1ls265145lah.52.gmail; Sun, 08 Mar 2015 21:20:39 -0700 (PDT) X-Received: by 10.112.225.137 with SMTP id rk9mr22907558lbc.11.1425874839124; Sun, 08 Mar 2015 21:20:39 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id ap5si13211986lac.158.2015.03.08.21.20.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Mar 2015 21:20:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbvp9 with SMTP id p9so45447439lbv.8 for ; Sun, 08 Mar 2015 21:20:39 -0700 (PDT) X-Received: by 10.152.197.34 with SMTP id ir2mr23703223lac.36.1425874838980; Sun, 08 Mar 2015 21:20:38 -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.35.133 with SMTP id h5csp1236079lbj; Sun, 8 Mar 2015 21:20:37 -0700 (PDT) X-Received: by 10.70.53.226 with SMTP id e2mr49127088pdp.25.1425874837059; Sun, 08 Mar 2015 21:20:37 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si5629547pas.91.2015.03.08.21.20.35; Sun, 08 Mar 2015 21:20:37 -0700 (PDT) Received-SPF: none (google.com: stable-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 S1751701AbbCIEUe (ORCPT + 1 other); Mon, 9 Mar 2015 00:20:34 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:39730 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750830AbbCIEUe (ORCPT ); Mon, 9 Mar 2015 00:20:34 -0400 Received: by pdbft15 with SMTP id ft15so31490282pdb.6 for ; Sun, 08 Mar 2015 21:20:33 -0700 (PDT) X-Received: by 10.66.156.229 with SMTP id wh5mr48680625pab.119.1425874833634; Sun, 08 Mar 2015 21:20:33 -0700 (PDT) Received: from localhost ([122.166.181.26]) by mx.google.com with ESMTPSA id x4sm16697446pas.40.2015.03.08.21.20.32 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 08 Mar 2015 21:20:33 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , stable@vger.kernel.org Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, santosh.shilimkar@oracle.com, ethan.zhao@oracle.com, Tomeu Vizoso , "Rafael J. Wysocki" Subject: [PATCH] cpufreq: Ref the policy object sooner Date: Mon, 9 Mar 2015 09:50:22 +0530 Message-Id: <1ba2266de234ebbafd680a520565361f5071df71.1425874657.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.3.0.rc0.44.ga94655d Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@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.180 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: , From: Tomeu Vizoso Upstream commit id: 6d4e81ed89c0 Do it before it's assigned to cpufreq_cpu_data, otherwise when a driver tries to get the cpu frequency during initialization the policy kobj is referenced and we get this warning: ------------[ cut here ]------------ WARNING: CPU: 1 PID: 64 at include/linux/kref.h:47 kobject_get+0x64/0x70() Modules linked in: CPU: 1 PID: 64 Comm: irq/77-tegra-ac Not tainted 3.18.0-rc4-next-20141114ccu-00050-g3eff942 #326 [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack+0x98/0xd8) [] (dump_stack) from [] (warn_slowpath_common+0x84/0xb4) [] (warn_slowpath_common) from [] (warn_slowpath_null+0x1c/0x24) [] (warn_slowpath_null) from [] (kobject_get+0x64/0x70) [] (kobject_get) from [] (cpufreq_cpu_get+0x88/0xc8) [] (cpufreq_cpu_get) from [] (cpufreq_get+0xc/0x64) [] (cpufreq_get) from [] (actmon_thread_isr+0x134/0x198) [] (actmon_thread_isr) from [] (irq_thread_fn+0x1c/0x40) [] (irq_thread_fn) from [] (irq_thread+0x134/0x174) [] (irq_thread) from [] (kthread+0xdc/0xf4) [] (kthread) from [] (ret_from_fork+0x14/0x3c) ---[ end trace b7bd64a81b340c59 ]--- Cc: 3.18 # 3.18 Signed-off-by: Tomeu Vizoso Acked-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki --- drivers/cpufreq/cpufreq.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 4473eba1d6b0..ae27ea61799a 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -898,46 +898,31 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy, struct freq_attr **drv_attr; int ret = 0; - /* prepare interface data */ - ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, - &dev->kobj, "cpufreq"); - if (ret) - return ret; - /* set up files for this cpu device */ drv_attr = cpufreq_driver->attr; while ((drv_attr) && (*drv_attr)) { ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); if (ret) - goto err_out_kobj_put; + return ret; drv_attr++; } if (cpufreq_driver->get) { ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); if (ret) - goto err_out_kobj_put; + return ret; } ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); if (ret) - goto err_out_kobj_put; + return ret; if (cpufreq_driver->bios_limit) { ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); if (ret) - goto err_out_kobj_put; + return ret; } - ret = cpufreq_add_dev_symlink(policy); - if (ret) - goto err_out_kobj_put; - - return ret; - -err_out_kobj_put: - kobject_put(&policy->kobj); - wait_for_completion(&policy->kobj_unregister); - return ret; + return cpufreq_add_dev_symlink(policy); } static void cpufreq_init_policy(struct cpufreq_policy *policy) @@ -1196,6 +1181,8 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) goto err_set_policy_cpu; } + down_write(&policy->rwsem); + /* related cpus should atleast have policy->cpus */ cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus); @@ -1208,9 +1195,17 @@ 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; + } } - down_write(&policy->rwsem); write_lock_irqsave(&cpufreq_driver_lock, flags); for_each_cpu(j, policy->cpus) per_cpu(cpufreq_cpu_data, j) = policy; @@ -1301,6 +1296,11 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) per_cpu(cpufreq_cpu_data, j) = NULL; 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)