opp: Prevent memory leak in dev_pm_opp_attach_genpd()
authorViresh Kumar <viresh.kumar@linaro.org>
Mon, 31 Aug 2020 05:52:37 +0000 (11:22 +0530)
committerViresh Kumar <viresh.kumar@linaro.org>
Wed, 16 Sep 2020 08:32:33 +0000 (14:02 +0530)
commitcb60e9602cce1593eb1e9cdc8ee562815078a354
tree7792c3633929ecf7cc09fff114849934d2f47432
parent7162fc2e4edae990e04ea7b0ad7f0106d97c9b41
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>
drivers/opp/core.c