From: Chunyan Zhang <zhang.lyra@gmail.com>
To: Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
Orson Zhai <orsonzhai@gmail.com>,
Baolin Wang <baolin.wang7@gmail.com>,
Chunyan Zhang <chunyan.zhang@unisoc.com>,
Chunyan Zhang <zhang.lyra@gmail.com>,
Chen Yongzhi <yongzhi.chen@unisoc.com>
Subject: [PATCH v2 2/2] power: supply: sc27xx: prevent adc * 1000 from overflow
Date: Fri, 24 Jul 2020 20:21:48 +0800 [thread overview]
Message-ID: <20200724122148.26541-3-zhang.lyra@gmail.com> (raw)
In-Reply-To: <20200724122148.26541-1-zhang.lyra@gmail.com>
From: Chunyan Zhang <chunyan.zhang@unisoc.com>
The input parameter is int type, cause adc * 1000 could overflow.
Change to use s64 to avoid this issue.
Signed-off-by: Chen Yongzhi <yongzhi.chen@unisoc.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
---
drivers/power/supply/sc27xx_fuel_gauge.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c
index be42e814ea34..9c627618c224 100644
--- a/drivers/power/supply/sc27xx_fuel_gauge.c
+++ b/drivers/power/supply/sc27xx_fuel_gauge.c
@@ -5,6 +5,7 @@
#include <linux/iio/consumer.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
+#include <linux/math64.h>
#include <linux/module.h>
#include <linux/nvmem-consumer.h>
#include <linux/of.h>
@@ -133,14 +134,14 @@ 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);
+ 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)
--
2.20.1
next prev parent reply other threads:[~2020-07-24 12:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-24 12:21 [PATCH v2 0/2] fix an overflow error on sc27xx power supply Chunyan Zhang
2020-07-24 12:21 ` [PATCH v2 1/2] math64: New DIV_S64_ROUND_CLOSEST helper Chunyan Zhang
2020-07-24 12:21 ` Chunyan Zhang [this message]
2020-07-27 23:14 ` [PATCH v2 0/2] fix an overflow error on sc27xx power supply Sebastian Reichel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200724122148.26541-3-zhang.lyra@gmail.com \
--to=zhang.lyra@gmail.com \
--cc=baolin.wang7@gmail.com \
--cc=chunyan.zhang@unisoc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=orsonzhai@gmail.com \
--cc=sre@kernel.org \
--cc=yongzhi.chen@unisoc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome