Skip to content

Commit

Permalink
olpc_battery: Fix endian neutral breakage for s16 values
Browse files Browse the repository at this point in the history
commit 7cfbb29 upstream.

When the driver was updated to be endian neutral (8e9c771)
the signed part of the s16 values was lost.  This is because be16_to_cpu()
returns an unsigned value.  This patch casts the values back to a s16
number prior to the the implicit cast up to an int.

Signed-off-by: Richard A. Smith <[email protected]>
Signed-off-by: Daniel Drake <[email protected]>
Signed-off-by: Anton Vorontsov <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Andi Kleen <[email protected]>
  • Loading branch information
smithbone authored and Andi Kleen committed Dec 14, 2010
1 parent f38e82f commit 992c78f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/power/olpc_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;

val->intval = (int)be16_to_cpu(ec_word) * 9760L / 32;
val->intval = (s16)be16_to_cpu(ec_word) * 9760L / 32;
break;
case POWER_SUPPLY_PROP_CURRENT_AVG:
ret = olpc_ec_cmd(EC_BAT_CURRENT, NULL, 0, (void *)&ec_word, 2);
if (ret)
return ret;

val->intval = (int)be16_to_cpu(ec_word) * 15625L / 120;
val->intval = (s16)be16_to_cpu(ec_word) * 15625L / 120;
break;
case POWER_SUPPLY_PROP_CAPACITY:
ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &ec_byte, 1);
Expand All @@ -299,7 +299,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;

val->intval = (int)be16_to_cpu(ec_word) * 100 / 256;
val->intval = (s16)be16_to_cpu(ec_word) * 100 / 256;
break;
case POWER_SUPPLY_PROP_TEMP_AMBIENT:
ret = olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2);
Expand All @@ -313,7 +313,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;

val->intval = (int)be16_to_cpu(ec_word) * 6250 / 15;
val->intval = (s16)be16_to_cpu(ec_word) * 6250 / 15;
break;
case POWER_SUPPLY_PROP_SERIAL_NUMBER:
ret = olpc_ec_cmd(EC_BAT_SERIAL, NULL, 0, (void *)&ser_buf, 8);
Expand Down

0 comments on commit 992c78f

Please sign in to comment.