Skip to content

Commit cb60e96

Browse files
committed
opp: Prevent memory leak in dev_pm_opp_attach_genpd()
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 <stephan@gerhold.net> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 7162fc2 commit cb60e96

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

drivers/opp/core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,9 @@ static void _opp_detach_genpd(struct opp_table *opp_table)
19601960
{
19611961
int index;
19621962

1963+
if (!opp_table->genpd_virt_devs)
1964+
return;
1965+
19631966
for (index = 0; index < opp_table->required_opp_count; index++) {
19641967
if (!opp_table->genpd_virt_devs[index])
19651968
continue;
@@ -2006,6 +2009,9 @@ struct opp_table *dev_pm_opp_attach_genpd(struct device *dev,
20062009
if (IS_ERR(opp_table))
20072010
return opp_table;
20082011

2012+
if (opp_table->genpd_virt_devs)
2013+
return opp_table;
2014+
20092015
/*
20102016
* If the genpd's OPP table isn't already initialized, parsing of the
20112017
* required-opps fail for dev. We should retry this after genpd's OPP

0 commit comments

Comments
 (0)