From patchwork Wed Oct 31 23:10:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 149910 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp109743ljp; Wed, 31 Oct 2018 16:20:41 -0700 (PDT) X-Google-Smtp-Source: AJdET5fw7uhhdknffeCKxerGXlCy1uIgoO0hYFJ4g/bmZwVl+PGa2hyTLGrq7UBjst5E6vUc4A7+ X-Received: by 2002:a17:902:b612:: with SMTP id b18-v6mr5334702pls.205.1541028041282; Wed, 31 Oct 2018 16:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541028041; cv=none; d=google.com; s=arc-20160816; b=i8fbRxeHblR8XA3lq8bnAL426jmi509u9xTYZezpVA4p81bkC0YooJqVV4WAkiXISM 55n5LVgoO1YngqZq9KudeCDpN53twI7XgtFt7qvYLmJ1ElFijE1Y9Vwr/LZfOnJ6Rz1V CFF4qwAZjfoLXg4P4NStSxDobb0GeMoU+S88yZxLW4bxBTBheCCF1n/BEDDKu00wTR4p +5eMHqYeFpLMeo6hgbWTgI8v1fLLmPJgMaMJb8OPrIjUp9VQsTxulJUbv4pxmLr8Jwq7 upZERgD44OLmUKJGt82eGeEDZRPBxBBJwbFUptVKVhE/38TdpVFYR090l+yB1E64KYYM UgvA== 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=vb8uQZh3yyXwp8IVcFMsO3bjq2QkWeoDTR19a9O2NKQ=; b=xadoCfgxdfkeOR+blPli2Ha4/ms1FF5BEdawZlcBM+VxNnJNA9ERwzj+GOttPa/z3R L0XnG/9cfJmfU39TGOiReMMBheaDq1fU0SsVeJ7evgG4peY27JAVBBZ1d7AYWj9EOBqD T2rjUgt4Rna2M15LtGT5huIliMmdfElI0H7LrpETBAbqX6DMAcJ5wSKyxF66hSiIkVI6 HKxKvSzCDxnn6CDgUnXneuViquQgJKAuEJHG6v95SJbNRImFvDjHkkQPSOxNcuQsviSO 37u4bEiqui1/QZdErA6wU6tAgnBtkmMDlYdb9dBg2kOROF9wpC/aHHNLVizi9FYN/5uX cMQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yUrngDFg; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si29136833plu.316.2018.10.31.16.20.41; Wed, 31 Oct 2018 16:20:41 -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=@kernel.org header.s=default header.b=yUrngDFg; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731972AbeKAIUx (ORCPT + 32 others); Thu, 1 Nov 2018 04:20:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:34820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731561AbeKAILV (ORCPT ); Thu, 1 Nov 2018 04:11:21 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BBB2D2087A; Wed, 31 Oct 2018 23:11:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027468; bh=LH+zed8WRzz62gAU/eBrvzz+wby9v9JQ8HI+zX8Z9ek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yUrngDFgQ/UwMYs00afyJxMy1Xo2QNT+JUGUEmdpahlIu2sUy3l4sxstrJYTum0zl 6QpmhVVp5nMOc9UA8H9YVc4YqZYY8cZhpg9CsxvjUIrYiRlYg3/qEXrV+Vs7OX1EP0 yKd+6gCYx4UwVnRKY3gkxibSQhxJx4t4MIseVVH0= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Viresh Kumar , Sasha Levin Subject: [PATCH AUTOSEL 4.9 15/48] cpufreq: dt: Try freeing static OPPs only if we have added them Date: Wed, 31 Oct 2018 19:10:21 -0400 Message-Id: <20181031231054.29333-15-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031231054.29333-1-sashal@kernel.org> References: <20181031231054.29333-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Viresh Kumar [ Upstream commit 51c99dd2c06b234575661fa1e0a1dea6c3ef566f ] 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 Signed-off-by: Sasha Levin --- drivers/cpufreq/cpufreq-dt.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) -- 2.17.1 diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 4d3ec92cbabf..1496617b05d5 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[] = { @@ -197,6 +198,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. @@ -207,7 +217,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 @@ -233,19 +244,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; @@ -284,10 +286,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_regulator(opp_table); out_put_clk: @@ -302,7 +305,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_regulator(priv->opp_table);