linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] opp: core: Check for pending links before reading required_opp pointers
@ 2021-08-22 17:44 Marijn Suijten
  2021-08-23  7:15 ` Viresh Kumar
  0 siblings, 1 reply; 2+ messages in thread
From: Marijn Suijten @ 2021-08-22 17:44 UTC (permalink / raw)
  To: phone-devel
  Cc: ~postmarketos/upstreaming, AngeloGioacchino Del Regno,
	Konrad Dybcio, Martin Botka, Jami Kettunen, Pavel Dubrova,
	Marijn Suijten, Viresh Kumar, Nishanth Menon, Stephen Boyd,
	Hsin-Yi Wang, linux-pm, linux-kernel

Commit 4fa82a87ba55 ("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: 4fa82a87ba55 ("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>
---
 drivers/opp/core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index b335c077f215..4dd26a165c91 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -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
@@ -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);
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] opp: core: Check for pending links before reading required_opp pointers
  2021-08-22 17:44 [PATCH] opp: core: Check for pending links before reading required_opp pointers Marijn Suijten
@ 2021-08-23  7:15 ` Viresh Kumar
  0 siblings, 0 replies; 2+ messages in thread
From: Viresh Kumar @ 2021-08-23  7:15 UTC (permalink / raw)
  To: Marijn Suijten
  Cc: phone-devel, ~postmarketos/upstreaming,
	AngeloGioacchino Del Regno, Konrad Dybcio, Martin Botka,
	Jami Kettunen, Pavel Dubrova, Viresh Kumar, Nishanth Menon,
	Stephen Boyd, Hsin-Yi Wang, linux-pm, linux-kernel

On 22-08-21, 19:44, Marijn Suijten wrote:
> Commit 4fa82a87ba55 ("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: 4fa82a87ba55 ("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>
> ---
>  drivers/opp/core.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index b335c077f215..4dd26a165c91 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -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
> @@ -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);

Applied. Thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-23  7:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-22 17:44 [PATCH] opp: core: Check for pending links before reading required_opp pointers Marijn Suijten
2021-08-23  7:15 ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).