From patchwork Wed Oct 31 23:08:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 149901 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp100898ljp; Wed, 31 Oct 2018 16:10:11 -0700 (PDT) X-Google-Smtp-Source: AJdET5fsSEAZw1uhJD09dlYCY0Cf+vI2d/fcVjzMmLstVesd/6KQhC8NjVADQWwwKNwuD+P5aXnK X-Received: by 2002:a62:c42:: with SMTP id u63-v6mr5319799pfi.43.1541027411676; Wed, 31 Oct 2018 16:10:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541027411; cv=none; d=google.com; s=arc-20160816; b=Pssft2ALQMjD3yV0FPrXHq5g3CLe2cut9SbWKsIdtS7UgTkjYtG7IEAfxheEQeFN/V cYxtTjbSwYg0VqNLuXc+dAp2sytMRDw78k87usVB4fR8F1cjSCDQtKMWDwJVRS6UubTz 7WGUUCDD0QhdZUcrO1Q9MDCnmKoiEUvjlyJSQPpf8UQeF1khCwoTt/tsJBROsAhSEkI5 +TQeRy7lhJdM7QmfX0hrNrwf5z9Gie8ypWV8bWjBLDSsaBe2sDfsPRmJ/agQ4FOQye+3 oag/xQhHd+89RogPlP0HKmxKYK/XbznRwPlC+PgLGTv90JOaLC78fdmrT76m/wZJqdnm x1fQ== 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=n1PvcJ4LPyrxwvxXHv51ifMoQLQ2r2A3YE8T6BeR81Y=; b=QFfPlpLEEGdP0YZQ9tXnolNOaSeamw0FLQHiK559sRV8hPqboUqP3A+jhso885sKBC 0THDOVgeMeKg/VtuXybMNjanuY8ETWM00SE9SXzLkx2i8N5DLhbj4C8QHsev6X/3qXTL 6lxLY7f3dxcoErf2hQvagibEoGU1kE7wYcHJHkOcwvxH/uZAfm9jcG5IgcDto6P3oGHm 2TL01jNzn91XYFx3Zt0OXj/x4G3K8WPDbgpaXJu4lAZK1Z6A+3PqwH+ZfExSb85cuCMf PbfD53ZlYMPv12AE8VFXyShx7qd32C23Pb55bi8MZ3P5dhymv05G+1vbhPAcPFqQXnUP md3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XlGjw8bG; 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 16-v6si29951413pgp.175.2018.10.31.16.10.11; Wed, 31 Oct 2018 16:10:11 -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=XlGjw8bG; 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 S1730971AbeKAIKU (ORCPT + 32 others); Thu, 1 Nov 2018 04:10:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:60954 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729626AbeKAIKT (ORCPT ); Thu, 1 Nov 2018 04:10:19 -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 A8D6F20843; Wed, 31 Oct 2018 23:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027407; bh=fpzFFQYaO/o9Gy9nAlp02qd2x6D8zc9WonXtl/icoMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XlGjw8bGLC5bRlM6XAU36x3t8h2YASaSQDulRaKoJvnyfcxo9f30UyBdJhVBt67ee xxwV+hVhcizilfR0KaEJPyXlTCzsFLolTQbGbU8sgenc5MOMhf4DIafEnVyQaBle3s ie12onHgX9o74TDImnJXHrkl+Ozu8uRIpF4P29bE= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Viresh Kumar , Sasha Levin Subject: [PATCH AUTOSEL 4.14 20/73] cpufreq: dt: Try freeing static OPPs only if we have added them Date: Wed, 31 Oct 2018 19:08:55 -0400 Message-Id: <20181031230948.29203-20-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230948.29203-1-sashal@kernel.org> References: <20181031230948.29203-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 d83ab94d041a..ca6ee9f389b6 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[] = { @@ -196,6 +197,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. @@ -206,7 +216,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 @@ -232,19 +243,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; @@ -280,10 +282,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: @@ -298,7 +301,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);