Skip to content

Commit

Permalink
opp: Free static OPPs on errors while adding them
Browse files Browse the repository at this point in the history
The static OPPs aren't getting freed properly, if errors occur while
adding them. Fix that by calling _put_opp_list_kref() and putting their
reference on failures.

Fixes: 11e1a16 ("opp: Don't decrement uninitialized list_kref")
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
  • Loading branch information
Viresh Kumar committed Dec 10, 2019
1 parent e42617b commit ba00331
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions drivers/opp/of.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,15 +678,17 @@ static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table)
dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,
ret);
of_node_put(np);
return ret;
goto put_list_kref;
} else if (opp) {
count++;
}
}

/* There should be one of more OPP defined */
if (WARN_ON(!count))
return -ENOENT;
if (WARN_ON(!count)) {
ret = -ENOENT;
goto put_list_kref;
}

list_for_each_entry(opp, &opp_table->opp_list, node)
pstate_count += !!opp->pstate;
Expand All @@ -695,7 +697,8 @@ static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table)
if (pstate_count && pstate_count != count) {
dev_err(dev, "Not all nodes have performance state set (%d: %d)\n",
count, pstate_count);
return -ENOENT;
ret = -ENOENT;
goto put_list_kref;
}

if (pstate_count)
Expand All @@ -704,6 +707,11 @@ static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table)
opp_table->parsed_static_opps = true;

return 0;

put_list_kref:
_put_opp_list_kref(opp_table);

return ret;
}

/* Initializes OPP tables based on old-deprecated bindings */
Expand Down Expand Up @@ -738,6 +746,7 @@ static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table)
if (ret) {
dev_err(dev, "%s: Failed to add OPP %ld (%d)\n",
__func__, freq, ret);
_put_opp_list_kref(opp_table);
return ret;
}
nr -= 2;
Expand Down

0 comments on commit ba00331

Please sign in to comment.