Skip to content

Commit 12c0204

Browse files
Martin Calsynfabiobaltieri
authored andcommitted
drivers: fuel_gauge: max17048: Fix overflow when calculating voltage
Annotate the calculation with type casts to force promotion to uint32_t and then cast back down to uint16_t for the return. This solves the issue with invalid voltage (mV) values being returned due to overflow during the conversion from the register value on the max17048 chip. Signed-off-by: Martin Calsyn <[email protected]>
1 parent 49d4ad9 commit 12c0204

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/fuel_gauge/max17048/max17048.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ int max17048_voltage(const struct device *i2c_dev, uint16_t *response)
9090
* milli volts instead of volts.
9191
*/
9292

93-
*response = *response * 78125 / 1000000;
93+
*response = (uint16_t)((uint32_t)*response * 78125L / 1000000L);
9494
return 0;
9595
}
9696

0 commit comments

Comments
 (0)