@@ -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++;
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(-)