From: Harvey Harrison <harvey.harrison@gmail.com>
To: Rodolfo Giometti <giometti@linux.it>
Cc: Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] bq27x00_battery: use unaligned access helper
Date: Wed, 03 Sep 2008 20:39:28 -0700 [thread overview]
Message-ID: <1220499569.2137.21.camel@brick> (raw)
Remove hand-rolled get_unaligned_be16, this points to a possible
bug as bq27x00_read does another endian byteswap which sparse
notices:
drivers/power/bq27x00_battery.c:81:14: warning: cast to restricted __be16
Which should probably be checked.
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
New in next-20080902
Also all of these functions could (should) change to passing around a u16
rather than an int as the read function only ever reads 1 or two bytes.
drivers/power/bq27x00_battery.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index 62d4948..a5a49e1 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -23,6 +23,7 @@
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/idr.h>
+#include <asm/unaligned.h>
#include <linux/i2c.h>
@@ -33,7 +34,6 @@
#define BQ27x00_REG_RSOC 0x0B /* Relative State-of-Charge */
#define BQ27x00_REG_AI 0x14
#define BQ27x00_REG_FLAGS 0x0A
-#define HIGH_BYTE(A) ((A) << 8)
/* If the system has several batteries we need a different name for each
* of them...
@@ -239,7 +239,7 @@ static int bq27200_read(u8 reg, int *rt_value, int b_single,
err = i2c_transfer(client->adapter, msg, 1);
if (err >= 0) {
if (!b_single)
- *rt_value = data[1] | HIGH_BYTE(data[0]);
+ *rt_value = get_unaligned_be16(data);
else
*rt_value = data[0];
--
1.6.0.1.514.g59380c
reply other threads:[~2008-09-04 3:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1220499569.2137.21.camel@brick \
--to=harvey.harrison@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=giometti@linux.it \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox