From: Guenter Roeck <linux@roeck-us.net>
To: Nicolin Chen <nicoleotsuka@gmail.com>
Cc: jdelvare@suse.com, linux-hwmon@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwmon: (ina2xx) Fix current value calculation
Date: Wed, 14 Nov 2018 09:12:22 -0800 [thread overview]
Message-ID: <20181114171222.GA25157@roeck-us.net> (raw)
On Tue, Nov 13, 2018 at 07:48:54PM -0800, Nicolin Chen wrote:
> The current register (04h) has a sign bit at MSB. The comments
> for this calculation also mention that it's a signed register.
>
> However, the regval is unsigned type so result of calculation
> turns out to be an incorrect value when current is negative.
>
> This patch simply fixes this by adding a casting to s16.
>
> Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/ina2xx.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
> index c2252cf452f5..07ee19573b3f 100644
> --- a/drivers/hwmon/ina2xx.c
> +++ b/drivers/hwmon/ina2xx.c
> @@ -274,7 +274,7 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg,
> break;
> case INA2XX_CURRENT:
> /* signed register, result in mA */
> - val = regval * data->current_lsb_uA;
> + val = (s16)regval * data->current_lsb_uA;
> val = DIV_ROUND_CLOSEST(val, 1000);
> break;
> case INA2XX_CALIBRATION:
> --
> 2.17.1
>
next reply other threads:[~2018-11-14 17:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-14 17:12 Guenter Roeck [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-11-14 3:48 [PATCH] hwmon: (ina2xx) Fix current value calculation Nicolin Chen
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=20181114171222.GA25157@roeck-us.net \
--to=linux@roeck-us.net \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicoleotsuka@gmail.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