Skip to content

Commit

Permalink
opp: core: Check for pending links before reading required_opp pointers
Browse files Browse the repository at this point in the history
Commit 4fa82a8 ("opp: Allow required-opps to be used for non genpd
use cases") dereferences the pointers in required_opp_tables but these
might be set to an ERR_PTR if the list still has lazy links pending,
resulting in segfaults.  Prior to this patch IS_ERR was also checked on
required_opp_tables[i] before reading ->is_genpd inside
_opp_table_alloc_required_tables, which is at the same time the
predicate to add this table to the lazy list.  This segfault is solved
by reordering the checks to bail on lazy pending tables before reading
->is_genpd.

Fixes: 4fa82a8 ("opp: Allow required-opps to be used for non genpd use cases")
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
  • Loading branch information
Marijn Suijten authored and Viresh Kumar committed Aug 23, 2021
1 parent c3ddfe6 commit 19526d0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/opp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,10 @@ static int _set_required_opps(struct device *dev,
if (!required_opp_tables)
return 0;

/* required-opps not fully initialized yet */
if (lazy_linking_pending(opp_table))
return -EBUSY;

/*
* We only support genpd's OPPs in the "required-opps" for now, as we
* don't know much about other use cases. Error out if the required OPP
Expand All @@ -903,10 +907,6 @@ static int _set_required_opps(struct device *dev,
return -ENOENT;
}

/* required-opps not fully initialized yet */
if (lazy_linking_pending(opp_table))
return -EBUSY;

/* Single genpd case */
if (!genpd_virt_devs)
return _set_required_opp(dev, dev, opp, 0);
Expand Down

0 comments on commit 19526d0

Please sign in to comment.