Skip to content

Commit

Permalink
opp: Prevent memory leak in dev_pm_opp_attach_genpd()
Browse files Browse the repository at this point in the history
If dev_pm_opp_attach_genpd() is called multiple times (once for each CPU
sharing the table), then it would result in unwanted behavior like
memory leak, attaching the domain multiple times, etc.

Handle that by checking and returning earlier if the domains are already
attached. Now that dev_pm_opp_detach_genpd() can get called multiple
times as well, we need to protect that too.

Note that the virtual device pointers aren't returned in this case, as
they may become unavailable to some callers during the middle of the
operation.

Reported-by: Stephan Gerhold <[email protected]>
Signed-off-by: Viresh Kumar <[email protected]>
  • Loading branch information
vireshk committed Sep 16, 2020
1 parent 7162fc2 commit cb60e96
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/opp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,9 @@ static void _opp_detach_genpd(struct opp_table *opp_table)
{
int index;

if (!opp_table->genpd_virt_devs)
return;

for (index = 0; index < opp_table->required_opp_count; index++) {
if (!opp_table->genpd_virt_devs[index])
continue;
Expand Down Expand Up @@ -2006,6 +2009,9 @@ struct opp_table *dev_pm_opp_attach_genpd(struct device *dev,
if (IS_ERR(opp_table))
return opp_table;

if (opp_table->genpd_virt_devs)
return opp_table;

/*
* If the genpd's OPP table isn't already initialized, parsing of the
* required-opps fail for dev. We should retry this after genpd's OPP
Expand Down

0 comments on commit cb60e96

Please sign in to comment.