Skip to contentSkip to conversation

olpc_battery: Fix endian neutral breakage for s16 values

PATCH In review Daniel Drake 3 participants 3 messages Sep 25, 2010 – Sep 28, 2010

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 olpc_battery: Fix endian neutral breakage for s16 values

From: Richard A. Smith <[email protected]>

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

---
 drivers/power/olpc_battery.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

v2 drops the unneeded int casts, which are implicit.

drivers/power/olpc_battery.c +4 -4
index aafc1c5..5bc1dcf 100644
@@ -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);
@@ -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);
@@ -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);
Signature · 1 line
1.7.2.2
#1 lore raw
Quoted 6 lines · Daniel Drake

From: Richard A. Smith<[email protected]>

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

Seems the comment has a error. Should be 'returns an unsigned' rather than signed. Other than that it looks good.

Signature · 2 lines
Richard A. Smith  <[email protected]>
One Laptop per Child
#2 lore raw
Quoted 10 lines · Richard A. Smith
Quoted 6 lines · Daniel Drake

From: Richard A. Smith<[email protected]>

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

Seems the comment has a error. Should be 'returns an unsigned' rather than signed. Other than that it looks good.

Fixed and applied w/ Cc: <[email protected]>, thanks!

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2