2020-07-17 05:36:54

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH] power: supply: sc27xx: prevent adc * 1000 from overflow

From: Chunyan Zhang <[email protected]>

The input parameter is int type, cause adc * 1000 could overflow.
Change to use s64 to avoid this issue.

Fixes: 195ca1703784 ("power: supply: Add Spreadtrum SC27XX fuel gauge unit driver")
Signed-off-by: Chen Yongzhi <[email protected]>
Signed-off-by: Chunyan Zhang <[email protected]>
---
drivers/power/supply/sc27xx_fuel_gauge.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c
index be42e814ea34..a9838a2a673d 100644
--- a/drivers/power/supply/sc27xx_fuel_gauge.c
+++ b/drivers/power/supply/sc27xx_fuel_gauge.c
@@ -133,12 +133,12 @@ static const char * const sc27xx_charger_supply_name[] = {
"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);
}

-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);
}
--
2.20.1


2020-07-17 15:55:12

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] power: supply: sc27xx: prevent adc * 1000 from overflow

Hi Chunyan,

I love your patch! Yet something to improve:

[auto build test ERROR on power-supply/for-next]
[also build test ERROR on linux/master linus/master v5.8-rc5 next-20200716]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Chunyan-Zhang/power-supply-sc27xx-prevent-adc-1000-from-overflow/20200717-133835
base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
config: m68k-allyesconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

m68k-linux-ld: drivers/power/supply/sc27xx_fuel_gauge.o: in function `sc27xx_fgu_hw_init':
sc27xx_fuel_gauge.c:(.text+0x13ec): undefined reference to `__divdi3'
m68k-linux-ld: drivers/power/supply/sc27xx_fuel_gauge.o: in function `sc27xx_fgu_get_vbat_vol':
sc27xx_fuel_gauge.c:(.text+0x1d8): undefined reference to `__divdi3'
>> m68k-linux-ld: sc27xx_fuel_gauge.c:(.text+0x1f4): undefined reference to `__divdi3'
m68k-linux-ld: drivers/power/supply/sc27xx_fuel_gauge.o: in function `sc27xx_fgu_get_current':
sc27xx_fuel_gauge.c:(.text+0x2b8): undefined reference to `__divdi3'
m68k-linux-ld: sc27xx_fuel_gauge.c:(.text+0x2d4): undefined reference to `__divdi3'
m68k-linux-ld: drivers/power/supply/sc27xx_fuel_gauge.o:sc27xx_fuel_gauge.c:(.text+0x84e): more undefined references to `__divdi3' follow

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (2.06 kB)
.config.gz (56.17 kB)
Download all attachments