Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp177349imd; Wed, 31 Oct 2018 16:52:38 -0700 (PDT) X-Google-Smtp-Source: AJdET5crL9P4PryO4XFQh3qXbeNTSVno7xociOe9fQhPKC2X+btNzz2MuI4nQZOxB2rnSB4XHFPa X-Received: by 2002:a62:1a92:: with SMTP id a140-v6mr5340791pfa.219.1541029958725; Wed, 31 Oct 2018 16:52:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029958; cv=none; d=google.com; s=arc-20160816; b=w5lo1y3W7se0ZP98EGro+qQfJE6Gq9UgBYE1UGO+PE0bC+7YX6vZq4BUd0rKQcgWDj 3vOK1LNmUZQ/sBR/QwNYTrUxX/qlMy8zlQiJ5Ru7irdhjI/eSH88EAO0CY7S+uFSe5Yq N4eFQcNi43dZUaj3twkTbKoocoEaglFCNp0HfqNlSqhH0w4301xaC/iMMGci9kc8HD0h 5/eBQeSBqRM0N/kxEM+MELGI8R39GCUSmu/lAUGuKayGvZPS7ImXBEL9AYSIMhuJAKGN zXut4WmFWm88rhTjIt9h52jrDGwOkeld90Lz9HchI5LijeM26jjp889NN4yJvY/BZE4R 1XyQ== 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=I6I/+c4SD5rsUDUlMREsnggf5fF5Gg9VBpT0/rp9Ppk=; b=A0YrZ5zouHE5nAxg09tX5tq5bN0Kxt5KZaCpAo2NNJrdppUxs8INOxfZJEq7PoY7o/ zuT9DYXkHP+Xt5lR+UuolYjiKXt1/CLOovmnTbQr3dK5aX3+MImKL92r2wksJsmfRVOj ixeum0hUSd66qYXQZFkfN3zignRlMeXlNReykXGVL46QRu+3Dd+yUixqQ+zHBr8UIzrv T8I8RJcdKBndyWaImp6N+acbIrEbSvRRp7uxjC7Y/N/NWEyU91UNfB//2tCSxNZa9Ght pnT4MKjGq8c/nzDtaeuVZm6tPE6Ea6iE2Zt7ih+9A+EZuNHFSB9Gzn+HdiL2uaExmkx0 YD2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zIuYon3z; 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 bb4-v6si27890727plb.170.2018.10.31.16.52.23; Wed, 31 Oct 2018 16:52:38 -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=zIuYon3z; 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 S1727998AbeKAIG0 (ORCPT + 99 others); Thu, 1 Nov 2018 04:06:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:53318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727945AbeKAIGZ (ORCPT ); Thu, 1 Nov 2018 04:06:25 -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 7466120838; Wed, 31 Oct 2018 23:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027174; bh=VBXsMqhmxXoiCeVeo9pOALxeXQzW0h+eRtgfqb5gFCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zIuYon3zBfU3Zb2lNPOZsgia5ZVPO26/tVVOBa2YUWrXF0v25WZ5MlO62bQsRRSlY pA9J8rKQcr+23V8twL9pS4c5+cqpeWigiP1oywuXBWMGse+c5Zc5EORcZ7ZcdvIdvM fseenFEXfKJiHQS2cr7lGUegvLPpUDQjyiQ/K/1A= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Viresh Kumar , Sasha Levin Subject: [PATCH AUTOSEL 4.19 036/146] cpufreq: dt: Try freeing static OPPs only if we have added them Date: Wed, 31 Oct 2018 19:03:51 -0400 Message-Id: <20181031230541.28822-36-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-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(-) 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); -- 2.17.1