From patchwork Thu Oct 4 04:16:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148090 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp453605lji; Wed, 3 Oct 2018 21:17:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV60S2QokIyTgehlHzkRDvAw7BGHOmge8pkODXKPPRqOosjTNcer76JdN9mIIu6k3yX9gUQZZ X-Received: by 2002:a63:e141:: with SMTP id h1-v6mr4038996pgk.47.1538626620088; Wed, 03 Oct 2018 21:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538626620; cv=none; d=google.com; s=arc-20160816; b=WYFptTUPfnyZsrdjw/WBKuIzuK8Kjj+bRBhwhQhCq6D5hJ014Y6zNBo66Sap6gkACs wFMDUVgpDZ2oXehuI5UQQQRCHQDUe2yrbSXpu1rqpxvRAMzmmptqkEhyAI8e4matEJL8 A6GIKnM/hKEmSAyNxP3bm8i8sgO5hgY6Eb5KQ9EbahmFdJdrQSGhguftgB7ZcFz99CAd eJoL+zCvzpt/CuvKeD4YwD+Mwu0x7ZVsindZGGytcEd9FWOOzwH3Cymm+57zijedqtzT 0yxBDuCaWpIAWk4ixX4nLq66Zk15WxOT/+oC9PjuO4zBgw17VJN32VIYl0y3Lq/DDVbB RvhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=+O/nJKlKvJKvAgRGQDY3iXasacOdOlADyrAzR7qH0as=; b=iGJsydeJ3DlB5i0S5Pe/Eyq8FnRWnuJ9ui9lefKFKQUcQS85jl0hnmZYSVPnFiL0pg JzY3WNgXllcSsOLJjqllCh3Sz5fxjsdDCoCwE42UMFTyftGpgSxRBpRLMnqXcl/6QYjF 6VKZy6I4OP0JV63hdi7BihLc4KC+qBYiypC72hWeOSl6vpfX6ctx9Wk2E9OvjRjuQVgH n0hsobQIBsr/E9UFMXDdAo49f7BW9EjChRPUPuF96sfFJ+Ho2yRsvuOe+V/RH29SXCxh h0QWObyBYQu7kEiDDICGeFqFgLUboixKnlQG0JyElOEpsSH1jDmlb6Bq585pNDzoBDOD DYqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gFb74++5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j7-v6si3839822pfk.203.2018.10.03.21.16.59; Wed, 03 Oct 2018 21:17:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gFb74++5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727319AbeJDLIL (ORCPT + 32 others); Thu, 4 Oct 2018 07:08:11 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34868 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbeJDLIK (ORCPT ); Thu, 4 Oct 2018 07:08:10 -0400 Received: by mail-pf1-f195.google.com with SMTP id p12-v6so2721311pfh.2 for ; Wed, 03 Oct 2018 21:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+O/nJKlKvJKvAgRGQDY3iXasacOdOlADyrAzR7qH0as=; b=gFb74++5sBSXBRKyRh9zoskCFGBN0c5YX2PiIweIlXc2TjGMH/aoj3Zq2ALHwLEN4P GypB9imQMIOXMANH/NQNTTVSW5n+Ht9OUqCviu1QCl2IBYjRSR5hyMc/rGCRChly8OVX tg5KcI9qNsaAHsoKMhlR+1gM2aq1ONfI2SmPI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+O/nJKlKvJKvAgRGQDY3iXasacOdOlADyrAzR7qH0as=; b=J2uwyLTL/wj8s/jaKjkiQZ9FXXDQBJYLwi1c+TdQwoRjFBwugSuHuF8gwllfkQ876u atZsnRq1o2WXJjIGVIiFwBMSE2WXE7+sRUdc4u8OvStHjn2T27aP4WTGTyUQrOB7UaWi eQOGxAV/dP69O3JNe8Wmjy0Niw/0kUYGyb/WKyKQh6OB7QD1PNqiSPPO72nef8w/L9ID 34DbUvmDBHdYx/upj5XeCiLtwleYJxdPsxg/g0jjaT+W90fV2o0OJglMa5Lb+VGuy/Pa MDDueoC5vhnAOqji3FNRtF9Y3a3eJgOWqhGvZS3acfzbSm3Vl/PwKpknuBQaf1JgD4C1 udtA== X-Gm-Message-State: ABuFfojzVnvU/NbjuvjHbdbt4mvuEohFodU7GPcXF4eYTex3yTY/a/Qw L8vVkixTBMzB7a2mqhTmb/KV/+8f7Oc= X-Received: by 2002:a63:65c7:: with SMTP id z190-v6mr4054400pgb.146.1538626611807; Wed, 03 Oct 2018 21:16:51 -0700 (PDT) Received: from localhost ([122.172.76.11]) by smtp.gmail.com with ESMTPSA id c79-v6sm5304901pfc.92.2018.10.03.21.16.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 21:16:51 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , niklas.cassel@linaro.org, d-gerlach@ti.com, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] cpufreq: dt: Try freeing static OPPs only if we have added them Date: Thu, 4 Oct 2018 09:46:22 +0530 Message-Id: <51c99dd2c06b234575661fa1e0a1dea6c3ef566f.1538625101.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We can not call dev_pm_opp_of_cpumask_remove_table() freely anymore since the latest OPP core updates as that uses reference counting to free resources. There are cases where no static OPPs are added (using DT) for a platform and trying to remove the OPP table may end up decrementing refcount which is already zero and hence generating warnings. Lets track if we were able to add static OPPs or not and then only remove the table based on that. Some reshuffling of code is also done to do that. Reported-by: Niklas Cassel Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq-dt.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 0a9ebf00be46..e58bfcb1169e 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -32,6 +32,7 @@ struct private_data { struct device *cpu_dev; struct thermal_cooling_device *cdev; const char *reg_name; + bool have_static_opps; }; static struct freq_attr *cpufreq_dt_attr[] = { @@ -204,6 +205,15 @@ static int cpufreq_init(struct cpufreq_policy *policy) } } + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) { + ret = -ENOMEM; + goto out_put_regulator; + } + + priv->reg_name = name; + priv->opp_table = opp_table; + /* * Initialize OPP tables for all policy->cpus. They will be shared by * all CPUs which have marked their CPUs shared with OPP bindings. @@ -214,7 +224,8 @@ static int cpufreq_init(struct cpufreq_policy *policy) * * OPPs might be populated at runtime, don't check for error here */ - dev_pm_opp_of_cpumask_add_table(policy->cpus); + if (!dev_pm_opp_of_cpumask_add_table(policy->cpus)) + priv->have_static_opps = true; /* * But we need OPP table to function so if it is not there let's @@ -240,19 +251,10 @@ static int cpufreq_init(struct cpufreq_policy *policy) __func__, ret); } - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) { - ret = -ENOMEM; - goto out_free_opp; - } - - priv->reg_name = name; - priv->opp_table = opp_table; - ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table); if (ret) { dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret); - goto out_free_priv; + goto out_free_opp; } priv->cpu_dev = cpu_dev; @@ -282,10 +284,11 @@ static int cpufreq_init(struct cpufreq_policy *policy) out_free_cpufreq_table: dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table); -out_free_priv: - kfree(priv); out_free_opp: - dev_pm_opp_of_cpumask_remove_table(policy->cpus); + if (priv->have_static_opps) + dev_pm_opp_of_cpumask_remove_table(policy->cpus); + kfree(priv); +out_put_regulator: if (name) dev_pm_opp_put_regulators(opp_table); out_put_clk: @@ -300,7 +303,8 @@ static int cpufreq_exit(struct cpufreq_policy *policy) cpufreq_cooling_unregister(priv->cdev); dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table); - dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); + if (priv->have_static_opps) + dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); if (priv->reg_name) dev_pm_opp_put_regulators(priv->opp_table);