public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Liang He <windhl@126.com>
To: vireshk@kernel.org, nm@ti.com, sboyd@kernel.org,
	linux-pm@vger.kernel.org, windhl@126.com
Subject: [PATCH v2 2/2] OPP: Fix refcount leak bug for opp
Date: Mon, 18 Jul 2022 21:36:32 +0800	[thread overview]
Message-ID: <20220718133632.937290-2-windhl@126.com> (raw)
In-Reply-To: <20220718133632.937290-1-windhl@126.com>

In _opp_add_static_v2(), we need call of_node_get() for the new
reference created when "new_opp->np = np;" as new_opp is escaped out.
Here we should also take care of the of_node_put() when 'new_opp' is
freed based on the function description: "The opp can be controlled
... and may be removed by dev_pm_opp_remove".
For example, _opp_add_static_v2() is called by _of_add_opp_table_v2()
in a for_each_available_child_of_node() which will automatically
increase and decrease the refcount. So we need an additional
of_node_get() for the new reference created in _opp_add_static_v2().

Signed-off-by: Liang He <windhl@126.com>
---
 drivers/opp/core.c | 1 +
 drivers/opp/of.c   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index cc2671322e41..2f7988a05cb7 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -1549,6 +1549,7 @@ static void _opp_kref_release(struct kref *kref)
 	list_del(&opp->node);
 	mutex_unlock(&opp_table->lock);
 
+	of_node_put(opp->np);
 	/*
 	 * Notify the changes in the availability of the operable
 	 * frequency/voltage list.
diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 374544afe9e4..ac4a3ff12677 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -937,7 +937,7 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,
 
 	new_opp->turbo = of_property_read_bool(np, "turbo-mode");
 
-	new_opp->np = np;
+	new_opp->np = of_node_get(np);
 	new_opp->dynamic = false;
 	new_opp->available = true;
 
-- 
2.25.1


  reply	other threads:[~2022-07-18 13:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 13:36 [PATCH v2 1/2] OPP: Fix refcount leak bug for opp_table Liang He
2022-07-18 13:36 ` Liang He [this message]
2022-07-19  5:39   ` [PATCH v2 2/2] OPP: Fix refcount leak bug for opp Viresh Kumar
2022-07-19  5:38 ` [PATCH v2 1/2] OPP: Fix refcount leak bug for opp_table Viresh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220718133632.937290-2-windhl@126.com \
    --to=windhl@126.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=sboyd@kernel.org \
    --cc=vireshk@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox