[PATCH] opp: core: Fix off by one in dev_pm_opp_get_bw()

Dan Carpenter posted 1 patch 1 year, 2 months ago
drivers/opp/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] opp: core: Fix off by one in dev_pm_opp_get_bw()
Posted by Dan Carpenter 1 year, 2 months ago
The "opp->bandwidth" array has "opp->opp_table->path_count" number of
elements.  It's allocated in _opp_allocate().  So this > needs to be >=
to prevent an out of bounds access.

Fixes: d78653dcd8bf ("opp: core: implement dev_pm_opp_get_bw")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/opp/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index d4a0030a0228..09a1432561f6 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -121,7 +121,7 @@ unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index)
 		return 0;
 	}
 
-	if (index > opp->opp_table->path_count)
+	if (index >= opp->opp_table->path_count)
 		return 0;
 
 	if (!opp->bandwidth)
-- 
2.45.2
Re: [PATCH] opp: core: Fix off by one in dev_pm_opp_get_bw()
Posted by Viresh Kumar 1 year, 2 months ago
On 30-11-24, 13:07, Dan Carpenter wrote:
> The "opp->bandwidth" array has "opp->opp_table->path_count" number of
> elements.  It's allocated in _opp_allocate().  So this > needs to be >=
> to prevent an out of bounds access.
> 
> Fixes: d78653dcd8bf ("opp: core: implement dev_pm_opp_get_bw")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/opp/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index d4a0030a0228..09a1432561f6 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -121,7 +121,7 @@ unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index)
>  		return 0;
>  	}
>  
> -	if (index > opp->opp_table->path_count)
> +	if (index >= opp->opp_table->path_count)
>  		return 0;
>  
>  	if (!opp->bandwidth)

Applied. Thanks.

-- 
viresh