Skip to contentSkip to conversation

OPP: of: Fix potential multiplication overflow when calculating freq

PATCH Applied Colin Ian King 2 participants 2 messages Aug 26 – Aug 31

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

PATCH 1/1 OPP: of: Fix potential multiplication overflow when calculating freq

The multiplication be32_to_cpup(val++) * 1000 is performed using 32 bit unsigned integers and hence uses a 32 bit multiplication; this will overflow if be32_to_cpup(val++) is greater than 4294967 (which is very unlikely at present). The result is assigned to an unsigned long (which is a 64 bit value on 64 bit systems), so fix this potential overflow by casting the first operand of the multiplication to an unsigned int.

Fixes b496dfbc94ab ("PM / OPP: Initialize OPP table from device tree")
---
 drivers/opp/of.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/opp/of.c +1 -1
index c02e20632fa6..9c4fd1f0e944 100644
@@ -1039,7 +1039,7 @@ static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table)
 
 	val = prop->value;
 	while (nr) {
-		unsigned long freq = be32_to_cpup(val++) * 1000;
+		unsigned long freq = (unsigned long)be32_to_cpup(val++) * 1000;
 		unsigned long volt = be32_to_cpup(val++);
 		struct dev_pm_opp_data data = {
 			.freq = freq,
Signature · 1 line
2.55.0
Applied
#1 lore raw
Quoted 8 lines · Colin Ian King

The multiplication be32_to_cpup(val++) * 1000 is performed using 32 bit unsigned integers and hence uses a 32 bit multiplication; this will overflow if be32_to_cpup(val++) is greater than 4294967 (which is very unlikely at present). The result is assigned to an unsigned long (which is a 64 bit value on 64 bit systems), so fix this potential overflow by casting the first operand of the multiplication to an unsigned int.

Quoted 6 lines
Fixes b496dfbc94ab ("PM / OPP: Initialize OPP table from device tree")
---
 drivers/opp/of.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied. Thanks.

Signature · 1 line
viresh