summaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2017-04-14 20:32:47 +0200
committerSebastian Reichel <sre@kernel.org>2017-05-01 12:37:16 +0200
commitc67c06939ee4a24fcad1235dd9632153533fdd4d (patch)
treeaa2196d3f620f12de7b0c6388e629c161cc0eed7 /drivers/power
parent7f232af35620fe68746cb3da582062de965b286c (diff)
downloadlinux-stable-c67c06939ee4a24fcad1235dd9632153533fdd4d.tar.gz
linux-stable-c67c06939ee4a24fcad1235dd9632153533fdd4d.tar.bz2
linux-stable-c67c06939ee4a24fcad1235dd9632153533fdd4d.zip
power: supply: max17042_battery: Use sign_extend32 instead of DIY code
Use sign_extend32 to sign-extend variables where necessary instead of DIY code. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/supply/max17042_battery.c24
1 files changed, 3 insertions, 21 deletions
diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index da7a75f82489..790dfa9d0a2e 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -106,13 +106,7 @@ static int max17042_get_temperature(struct max17042_chip *chip, int *temp)
if (ret < 0)
return ret;
- *temp = data;
- /* The value is signed. */
- if (*temp & 0x8000) {
- *temp = (0x7fff & ~*temp) + 1;
- *temp *= -1;
- }
-
+ *temp = sign_extend32(data, 15);
/* The value is converted into deci-centigrade scale */
/* Units of LSB = 1 / 256 degree Celsius */
*temp = *temp * 10 / 256;
@@ -302,13 +296,7 @@ static int max17042_get_property(struct power_supply *psy,
if (ret < 0)
return ret;
- val->intval = data;
- if (val->intval & 0x8000) {
- /* Negative */
- val->intval = ~val->intval & 0x7fff;
- val->intval++;
- val->intval *= -1;
- }
+ val->intval = sign_extend32(data, 15);
val->intval *= 1562500 / chip->pdata->r_sns;
} else {
return -EINVAL;
@@ -320,13 +308,7 @@ static int max17042_get_property(struct power_supply *psy,
if (ret < 0)
return ret;
- val->intval = data;
- if (val->intval & 0x8000) {
- /* Negative */
- val->intval = ~val->intval & 0x7fff;
- val->intval++;
- val->intval *= -1;
- }
+ val->intval = sign_extend32(data, 15);
val->intval *= 1562500 / chip->pdata->r_sns;
} else {
return -EINVAL;