Skip to content

Commit 1024e69

Browse files
vireshkgregkh
authored andcommitted
opp: Prevent memory leak in dev_pm_opp_attach_genpd()
[ Upstream commit cb60e96 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 27e52f1 commit 1024e69

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
@@ -1949,6 +1949,9 @@ static void _opp_detach_genpd(struct opp_table *opp_table)
19491949
{
19501950
int index;
19511951

1952+
if (!opp_table->genpd_virt_devs)
1953+
return;
1954+
19521955
for (index = 0; index < opp_table->required_opp_count; index++) {
19531956
if (!opp_table->genpd_virt_devs[index])
19541957
continue;
@@ -1995,6 +1998,9 @@ struct opp_table *dev_pm_opp_attach_genpd(struct device *dev,
19951998
if (!opp_table)
19961999
return ERR_PTR(-ENOMEM);
19972000

2001+
if (opp_table->genpd_virt_devs)
2002+
return opp_table;
2003+
19982004
/*
19992005
* If the genpd's OPP table isn't already initialized, parsing of the
20002006
* required-opps fail for dev. We should retry this after genpd's OPP

0 commit comments

Comments
 (0)