* [PATCH v2] olpc_battery: Fix endian neutral breakage for s16 values
@ 2010-09-25 18:19 Daniel Drake
2010-09-27 14:51 ` Richard A. Smith
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Drake @ 2010-09-25 18:19 UTC (permalink / raw)
To: cbou, dwmw2; +Cc: dilinger, linux-kernel, harvey.harrison, richard
From: Richard A. Smith <richard@laptop.org>
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.
Signed-off-by: Richard A. Smith <richard@laptop.org>
Signed-off-by: Daniel Drake <dsd@laptop.org>
---
drivers/power/olpc_battery.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
v2 drops the unneeded int casts, which are implicit.
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index aafc1c5..5bc1dcf 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -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);
--
1.7.2.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] olpc_battery: Fix endian neutral breakage for s16 values
2010-09-25 18:19 [PATCH v2] olpc_battery: Fix endian neutral breakage for s16 values Daniel Drake
@ 2010-09-27 14:51 ` Richard A. Smith
2010-09-28 11:16 ` Anton Vorontsov
0 siblings, 1 reply; 3+ messages in thread
From: Richard A. Smith @ 2010-09-27 14:51 UTC (permalink / raw)
To: Daniel Drake; +Cc: cbou, dwmw2, dilinger, linux-kernel, harvey.harrison
On 09/25/2010 02:19 PM, Daniel Drake wrote:
> From: Richard A. Smith<richard@laptop.org>
>
> 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.
--
Richard A. Smith <richard@laptop.org>
One Laptop per Child
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] olpc_battery: Fix endian neutral breakage for s16 values
2010-09-27 14:51 ` Richard A. Smith
@ 2010-09-28 11:16 ` Anton Vorontsov
0 siblings, 0 replies; 3+ messages in thread
From: Anton Vorontsov @ 2010-09-28 11:16 UTC (permalink / raw)
To: Richard A. Smith
Cc: Daniel Drake, dwmw2, dilinger, linux-kernel, harvey.harrison
On Mon, Sep 27, 2010 at 10:51:35AM -0400, Richard A. Smith wrote:
> On 09/25/2010 02:19 PM, Daniel Drake wrote:
> >From: Richard A. Smith<richard@laptop.org>
> >
> >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: <stable@kernel.org>, thanks!
--
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-09-28 11:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-25 18:19 [PATCH v2] olpc_battery: Fix endian neutral breakage for s16 values Daniel Drake
2010-09-27 14:51 ` Richard A. Smith
2010-09-28 11:16 ` Anton Vorontsov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox