All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] opp: fix of_node leak for unsupported entries
@ 2020-01-03 19:36 Michał Mirosław
  2020-01-03 19:36 ` [PATCH 2/2] opp: quiet down WARN when no valid OPPs remain Michał Mirosław
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Michał Mirosław @ 2020-01-03 19:36 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd; +Cc: linux-pm, linux-kernel

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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-01-08 10:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-03 19:36 [PATCH 1/2] opp: fix of_node leak for unsupported entries Michał Mirosław
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.