Skip to content

Commit

Permalink
OPP: Don't set OPP recursively for a parent genpd
Browse files Browse the repository at this point in the history
Like other frameworks (clk, regulator, etc.) genpd core too takes care
of propagation to performance state to parent genpds. The OPP core
shouldn't attempt the same, or it may result in undefined behavior.

Add checks at various places to take care of the same.

Reviewed-by: Ulf Hansson <[email protected]>
Tested-by: Stephan Gerhold <[email protected]>
Signed-off-by: Viresh Kumar <[email protected]>
  • Loading branch information
vireshk committed Nov 28, 2023
1 parent e37440e commit 9251414
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 15 additions & 1 deletion drivers/opp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,12 @@ static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev,
return -EINVAL;
}

/* Genpd core takes care of propagation to parent genpd */
if (opp_table->is_genpd) {
dev_err(dev, "%s: Operation not supported for genpds\n", __func__);
return -EOPNOTSUPP;
}

/* Checking only the first one is enough ? */
if (opp_table->required_devs[0])
return 0;
Expand Down Expand Up @@ -2453,8 +2459,16 @@ static int _opp_set_required_devs(struct opp_table *opp_table,
if (opp_table->required_devs[0])
return 0;

for (i = 0; i < opp_table->required_opp_count; i++)
for (i = 0; i < opp_table->required_opp_count; i++) {
/* Genpd core takes care of propagation to parent genpd */
if (required_devs[i] && opp_table->is_genpd &&
opp_table->required_opp_tables[i]->is_genpd) {
dev_err(dev, "%s: Operation not supported for genpds\n", __func__);
return -EOPNOTSUPP;
}

opp_table->required_devs[i] = required_devs[i];
}

return 0;
}
Expand Down
7 changes: 5 additions & 2 deletions drivers/opp/of.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,11 @@ static int _link_required_opps(struct dev_pm_opp *opp, struct opp_table *opp_tab
*/
if (required_table->is_genpd && opp_table->required_opp_count == 1 &&
!opp_table->required_devs[0]) {
if (!WARN_ON(opp->level != OPP_LEVEL_UNSET))
opp->level = opp->required_opps[0]->level;
/* Genpd core takes care of propagation to parent genpd */
if (!opp_table->is_genpd) {
if (!WARN_ON(opp->level != OPP_LEVEL_UNSET))
opp->level = opp->required_opps[0]->level;
}
}

return 0;
Expand Down

0 comments on commit 9251414

Please sign in to comment.