From: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
To: Viresh Kumar <vireshk@kernel.org>, Nishanth Menon <nm@ti.com>,
Stephen Boyd <sboyd@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] opp: fix of_node leak for unsupported entries
Date: Fri, 03 Jan 2020 20:36:20 +0100 [thread overview]
Message-ID: <a8060fe5b23929e2e5c9bf5735e63b302124f66c.1578077228.git.mirq-linux@rere.qmqm.pl> (raw)
When parsing OPP v2 table, unsupported entries return NULL from
_opp_add_static_v2(). In this case node reference is leaked.
Make _opp_add_static_v2() always assume ownership of the reference
to fix this.
Commit 7978db344719 ("PM / OPP: Add missing of_node_put(np)") already
fixed this for the error returns. The leak remained for filtered-out
entries from the initial code commit. The Fixes-tagged commit is just
a last one that altered the code around.
Fixes: 11e1a1648298 ("opp: Don't decrement uninitialized list_kref")
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
drivers/opp/of.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 1cbb58240b80..fba515e432a4 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -555,8 +555,10 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,
bool rate_not_available = false;
new_opp = _opp_allocate(opp_table);
- if (!new_opp)
- return ERR_PTR(-ENOMEM);
+ if (!new_opp) {
+ ret = -ENOMEM;
+ goto free_node;
+ }
ret = of_property_read_u64(np, "opp-hz", &rate);
if (ret < 0) {
@@ -646,6 +648,8 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,
_of_opp_free_required_opps(opp_table, new_opp);
free_opp:
_opp_free(new_opp);
+free_node:
+ of_node_put(np);
return ERR_PTR(ret);
}
@@ -677,7 +681,6 @@ static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table)
ret = PTR_ERR(opp);
dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,
ret);
- of_node_put(np);
return ret;
} else if (opp) {
count++;
--
2.20.1
next reply other threads:[~2020-01-03 19:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-03 19:36 Michał Mirosław [this message]
2020-01-03 19:36 ` [PATCH 2/2] opp: quiet down WARN when no valid OPPs remain Michał Mirosław
2020-01-07 6:41 ` Viresh Kumar
2020-01-07 9:58 ` Michał Mirosław
2020-01-07 11:30 ` Viresh Kumar
2020-01-07 13:57 ` Michał Mirosław
2020-01-08 6:49 ` Viresh Kumar
2020-01-08 8:17 ` Viresh Kumar
2020-01-07 6:31 ` [PATCH 1/2] opp: fix of_node leak for unsupported entries Viresh Kumar
2020-01-07 6:36 ` Viresh Kumar
2020-01-07 14:04 ` Michał Mirosław
2020-01-08 7:33 ` Viresh Kumar
2020-01-08 10:38 ` Michał Mirosław
2020-01-08 10:44 ` 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=a8060fe5b23929e2e5c9bf5735e63b302124f66c.1578077228.git.mirq-linux@rere.qmqm.pl \
--to=mirq-linux@rere.qmqm.pl \
--cc=linux-kernel@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).