Skip to content

Commit 992c78f

Browse files
smithboneAndi Kleen
authored andcommitted
olpc_battery: Fix endian neutral breakage for s16 values
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 <richard@laptop.org> Signed-off-by: Daniel Drake <dsd@laptop.org> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Andi Kleen <ak@linux.intel.com>
1 parent f38e82f commit 992c78f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

drivers/power/olpc_battery.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
271271
if (ret)
272272
return ret;
273273

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

281-
val->intval = (int)be16_to_cpu(ec_word) * 15625L / 120;
281+
val->intval = (s16)be16_to_cpu(ec_word) * 15625L / 120;
282282
break;
283283
case POWER_SUPPLY_PROP_CAPACITY:
284284
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,
299299
if (ret)
300300
return ret;
301301

302-
val->intval = (int)be16_to_cpu(ec_word) * 100 / 256;
302+
val->intval = (s16)be16_to_cpu(ec_word) * 100 / 256;
303303
break;
304304
case POWER_SUPPLY_PROP_TEMP_AMBIENT:
305305
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,
313313
if (ret)
314314
return ret;
315315

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

0 commit comments

Comments
 (0)