Commit ac31585f authored by Chunyan Zhang's avatar Chunyan Zhang Committed by Sebastian Reichel

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: default avatarChen Yongzhi <yongzhi.chen@unisoc.com>
Signed-off-by: default avatarChunyan Zhang <chunyan.zhang@unisoc.com>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent af60459a
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <linux/iio/consumer.h> #include <linux/iio/consumer.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/math64.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/nvmem-consumer.h> #include <linux/nvmem-consumer.h>
#include <linux/of.h> #include <linux/of.h>
...@@ -133,14 +134,14 @@ static const char * const sc27xx_charger_supply_name[] = { ...@@ -133,14 +134,14 @@ static const char * const sc27xx_charger_supply_name[] = {
"sc2723_charger", "sc2723_charger",
}; };
static int sc27xx_fgu_adc_to_current(struct sc27xx_fgu_data *data, int adc) static int sc27xx_fgu_adc_to_current(struct sc27xx_fgu_data *data, s64 adc)
{ {
return DIV_ROUND_CLOSEST(adc * 1000, data->cur_1000ma_adc); return DIV_S64_ROUND_CLOSEST(adc * 1000, data->cur_1000ma_adc);
} }
static int sc27xx_fgu_adc_to_voltage(struct sc27xx_fgu_data *data, int adc) static int sc27xx_fgu_adc_to_voltage(struct sc27xx_fgu_data *data, s64 adc)
{ {
return DIV_ROUND_CLOSEST(adc * 1000, data->vol_1000mv_adc); return DIV_S64_ROUND_CLOSEST(adc * 1000, data->vol_1000mv_adc);
} }
static int sc27xx_fgu_voltage_to_adc(struct sc27xx_fgu_data *data, int vol) static int sc27xx_fgu_voltage_to_adc(struct sc27xx_fgu_data *data, int vol)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment