Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3438475imu; Sun, 11 Nov 2018 15:06:23 -0800 (PST) X-Google-Smtp-Source: AJdET5dztzHrd9IThOJpK3QS9EaOGtbr90xpqQRFQhdAF4L/DDxd8Klo2ec1YA+2okB2KoSaL6nH X-Received: by 2002:a17:902:be07:: with SMTP id r7-v6mr17582523pls.137.1541977583644; Sun, 11 Nov 2018 15:06:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977583; cv=none; d=google.com; s=arc-20160816; b=uNMsFxS737ccHj192rLecoe9yrPe2/dyvec9TNWpkTWOk8bCBhYxFZouA1qtu2eqZO 7WAaRHrI1pCaVOhICJagI+kuaGViW8/FNZEvF9hoZ4BU9r3+8Xe1iRXTqssq6bMkJRBy orbrpojJbpLEtukfLkwIUC5C59AvrUfRbOiXy8yT1hkvr1TtbUsSm84rr7lBexZslB3k iRV+u7bvvl/GDeo6ZnSsHEo9tjuG8p5FWWwufkaKKyTEKU8ZdsWbzbgpxZqhWUllunv3 3Q7Q6ES/Nmu3qKkNGsFKPAFQoYXQrsfINTyFQqRpyd8v8mHTJjs+QUMeXkIawoLtntO5 BtrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dWpkyMbUX8mSdgzM09hYsIUQTmnQqleSHuHM8UTYLAE=; b=SiGvQTeGJnx6kiekdWBShXyqfpAqDDZt1vw8QQCzOuxMfDl1CMPNrapWw50O0Q0qzW U+8yQVxtKUBqd7Ho+MOWDrA17lHSJKTf561cNDwrvhQXhQTrF81kM+0bz+llESUsONlH FgQJMEyWVUwd2POt+/qk2iGQ84Vs3BIi7c8VaufqQVo+IgSJiarV5CwncNQ4kRmcawGn 2M1uBahqHRI+ik5JiAnuxqrarGgM8TMV0QY4kV/bC4XsXlBUzvN2a+7XgVDCFKOo6ony +hDpvrwDNHFQ525yHiXuqP86deXNaejlRMvyB7iMWzdcx7aafwpHz2YB57iA7xSjRdt5 PKgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J4xFhLFy; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si15226869pgn.551.2018.11.11.15.06.08; Sun, 11 Nov 2018 15:06:23 -0800 (PST) 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=J4xFhLFy; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390516AbeKLIzv (ORCPT + 99 others); Mon, 12 Nov 2018 03:55:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:51248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390369AbeKLIWP (ORCPT ); Mon, 12 Nov 2018 03:22:15 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0E42721508; Sun, 11 Nov 2018 22:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975538; bh=nz/SbS24VVlt7/gb2stBZD4We1IOIKPhxCyAmkRHdDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J4xFhLFy7qBCN2a/KjK7GIoDPaf3JfXOEDryuJuTW8NO7tvFfjWr8o68xOomMm2Fw yNcwsBis/bhuRkhjUBXrMTHUitzMQiKyexMncwZCuj6fGGK5d00khcgTnc4V/TZLWv uFgAYm2MTvcgV3FI44HnF9itxIrRzwWnGTJtzzLQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Niklas Cassel , Viresh Kumar , Sasha Levin Subject: [PATCH 4.14 057/222] cpufreq: dt: Try freeing static OPPs only if we have added them Date: Sun, 11 Nov 2018 14:22:34 -0800 Message-Id: <20181111221653.127670060@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/cpufreq-dt.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) --- 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_p } } + 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_p * * 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_p __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_p 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_p 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);