Skip to contentSkip to conversation

opp: core: Fix off by one in dev_pm_opp_get_bw()

PATCH Applied Dan Carpenter 2 participants 2 messages Nov 30, 2024 – Dec 2, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 opp: core: Fix off by one in dev_pm_opp_get_bw()

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")
---
 drivers/opp/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/opp/core.c +1 -1
index d4a0030a0228..09a1432561f6 100644
@@ -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)
Signature · 1 line
2.45.2
Applied
#1 lore raw
Quoted 15 lines · Dan Carpenter

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")
---
 drivers/opp/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/opp/core.c +0 -0
index d4a0030a0228..09a1432561f6 100644

drivers/opp/core.c unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index) · line 127

Quoted 8 lines
drivers/opp/core.c +1 -1
@@ -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.

Signature · 1 line
viresh