Skip to content

Commit ac31585

Browse files
Chunyan Zhangsre
authored andcommitted
power: supply: sc27xx: prevent adc * 1000 from overflow
The input parameter is int type, cause adc * 1000 could overflow. Change to use s64 to avoid this issue. Signed-off-by: Chen Yongzhi <[email protected]> Signed-off-by: Chunyan Zhang <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent af60459 commit ac31585

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/power/supply/sc27xx_fuel_gauge.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/iio/consumer.h>
66
#include <linux/interrupt.h>
77
#include <linux/kernel.h>
8+
#include <linux/math64.h>
89
#include <linux/module.h>
910
#include <linux/nvmem-consumer.h>
1011
#include <linux/of.h>
@@ -133,14 +134,14 @@ static const char * const sc27xx_charger_supply_name[] = {
133134
"sc2723_charger",
134135
};
135136

136-
static int sc27xx_fgu_adc_to_current(struct sc27xx_fgu_data *data, int adc)
137+
static int sc27xx_fgu_adc_to_current(struct sc27xx_fgu_data *data, s64 adc)
137138
{
138-
return DIV_ROUND_CLOSEST(adc * 1000, data->cur_1000ma_adc);
139+
return DIV_S64_ROUND_CLOSEST(adc * 1000, data->cur_1000ma_adc);
139140
}
140141

141-
static int sc27xx_fgu_adc_to_voltage(struct sc27xx_fgu_data *data, int adc)
142+
static int sc27xx_fgu_adc_to_voltage(struct sc27xx_fgu_data *data, s64 adc)
142143
{
143-
return DIV_ROUND_CLOSEST(adc * 1000, data->vol_1000mv_adc);
144+
return DIV_S64_ROUND_CLOSEST(adc * 1000, data->vol_1000mv_adc);
144145
}
145146

146147
static int sc27xx_fgu_voltage_to_adc(struct sc27xx_fgu_data *data, int vol)

0 commit comments

Comments
 (0)