lkml.org 
[lkml]   [2020]   [Oct]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.8 587/633] opp: Prevent memory leak in dev_pm_opp_attach_genpd()
    Date
    From: Viresh Kumar <viresh.kumar@linaro.org>

    [ Upstream commit cb60e9602cce1593eb1e9cdc8ee562815078a354 ]

    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>
    ---
    drivers/opp/core.c | 6 ++++++
    1 file changed, 6 insertions(+)

    diff --git a/drivers/opp/core.c b/drivers/opp/core.c
    index 91dcad982d362..11d192fb2e813 100644
    --- a/drivers/opp/core.c
    +++ b/drivers/opp/core.c
    @@ -1918,6 +1918,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;
    @@ -1964,6 +1967,9 @@ struct opp_table *dev_pm_opp_attach_genpd(struct device *dev,
    if (!opp_table)
    return ERR_PTR(-ENOMEM);

    + 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
    --
    2.25.1


    \
     
     \ /
      Last update: 2020-10-27 16:20    [W:5.162 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site