From: Irina Tirdea <irina.tirdea@intel.com>
To: Jonathan Cameron <jic23@kernel.org>,
linux-iio@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>
Cc: linux-kernel@vger.kernel.org, Vlad Dogaru <vlad.dogaru@intel.com>,
Irina Tirdea <irina.tirdea@intel.com>
Subject: [PATCH v2 14/17] iio: accel: mma9551_core: use size in words for word buffers
Date: Mon, 13 Apr 2015 18:41:01 +0300 [thread overview]
Message-ID: <1428939664-12503-15-git-send-email-irina.tirdea@intel.com> (raw)
In-Reply-To: <1428939664-12503-1-git-send-email-irina.tirdea@intel.com>
Change the prototype for the mma9551_read/write_*_words functions
to receive the length of the buffer in words (instead of bytes) since
we are using a word buffer. This will prevent users from sending an
odd number of bytes for a word array.
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
---
drivers/iio/accel/mma9551_core.c | 27 ++++++++++++---------------
drivers/iio/accel/mma9553.c | 9 ++++++---
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/drivers/iio/accel/mma9551_core.c b/drivers/iio/accel/mma9551_core.c
index 2fd2a99..583660b 100644
--- a/drivers/iio/accel/mma9551_core.c
+++ b/drivers/iio/accel/mma9551_core.c
@@ -373,7 +373,7 @@ EXPORT_SYMBOL(mma9551_read_status_word);
* @client: I2C client
* @app_id: Application ID
* @reg: Application register
- * @len: Length of array to read in bytes
+ * @len: Length of array to read (in words)
* @buf: Array of words to read
*
* Read multiple configuration registers (word-sized registers).
@@ -388,20 +388,19 @@ int mma9551_read_config_words(struct i2c_client *client, u8 app_id,
u16 reg, u8 len, u16 *buf)
{
int ret, i;
- int len_words = len / sizeof(u16);
__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];
- if (len_words > ARRAY_SIZE(be_buf)) {
+ if (len > ARRAY_SIZE(be_buf)) {
dev_err(&client->dev, "Invalid buffer size %d\n", len);
return -EINVAL;
}
ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG,
- reg, NULL, 0, (u8 *) be_buf, len);
+ reg, NULL, 0, (u8 *)be_buf, len * sizeof(u16));
if (ret < 0)
return ret;
- for (i = 0; i < len_words; i++)
+ for (i = 0; i < len; i++)
buf[i] = be16_to_cpu(be_buf[i]);
return 0;
@@ -413,7 +412,7 @@ EXPORT_SYMBOL(mma9551_read_config_words);
* @client: I2C client
* @app_id: Application ID
* @reg: Application register
- * @len: Length of array to read in bytes
+ * @len: Length of array to read (in words)
* @buf: Array of words to read
*
* Read multiple status registers (word-sized registers).
@@ -428,20 +427,19 @@ int mma9551_read_status_words(struct i2c_client *client, u8 app_id,
u16 reg, u8 len, u16 *buf)
{
int ret, i;
- int len_words = len / sizeof(u16);
__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];
- if (len_words > ARRAY_SIZE(be_buf)) {
+ if (len > ARRAY_SIZE(be_buf)) {
dev_err(&client->dev, "Invalid buffer size %d\n", len);
return -EINVAL;
}
ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS,
- reg, NULL, 0, (u8 *) be_buf, len);
+ reg, NULL, 0, (u8 *)be_buf, len * sizeof(u16));
if (ret < 0)
return ret;
- for (i = 0; i < len_words; i++)
+ for (i = 0; i < len; i++)
buf[i] = be16_to_cpu(be_buf[i]);
return 0;
@@ -453,7 +451,7 @@ EXPORT_SYMBOL(mma9551_read_status_words);
* @client: I2C client
* @app_id: Application ID
* @reg: Application register
- * @len: Length of array to write in bytes
+ * @len: Length of array to write (in words)
* @buf: Array of words to write
*
* Write multiple configuration registers (word-sized registers).
@@ -468,19 +466,18 @@ int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
u16 reg, u8 len, u16 *buf)
{
int i;
- int len_words = len / sizeof(u16);
__be16 be_buf[(MMA9551_MAX_MAILBOX_DATA_REGS - 1) / 2];
- if (len_words > ARRAY_SIZE(be_buf)) {
+ if (len > ARRAY_SIZE(be_buf)) {
dev_err(&client->dev, "Invalid buffer size %d\n", len);
return -EINVAL;
}
- for (i = 0; i < len_words; i++)
+ for (i = 0; i < len; i++)
be_buf[i] = cpu_to_be16(buf[i]);
return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG,
- reg, (u8 *) be_buf, len, NULL, 0);
+ reg, (u8 *)be_buf, len * sizeof(u16), NULL, 0);
}
EXPORT_SYMBOL(mma9551_write_config_words);
diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c
index 8bfc618..06c8707 100644
--- a/drivers/iio/accel/mma9553.c
+++ b/drivers/iio/accel/mma9553.c
@@ -322,7 +322,8 @@ static int mma9553_read_activity_stepcnt(struct mma9553_data *data,
int ret;
ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER,
- MMA9553_REG_STATUS, sizeof(u32), buf);
+ MMA9553_REG_STATUS, ARRAY_SIZE(buf),
+ buf);
if (ret < 0) {
dev_err(&data->client->dev,
"error reading status and stepcnt\n");
@@ -397,7 +398,8 @@ static int mma9553_init(struct mma9553_data *data)
ret =
mma9551_read_config_words(data->client, MMA9551_APPID_PEDOMETER,
MMA9553_REG_CONF_SLEEPMIN,
- sizeof(data->conf), (u16 *) &data->conf);
+ sizeof(data->conf) / sizeof(u16),
+ (u16 *)&data->conf);
if (ret < 0) {
dev_err(&data->client->dev,
"failed to read configuration registers\n");
@@ -430,7 +432,8 @@ static int mma9553_init(struct mma9553_data *data)
ret =
mma9551_write_config_words(data->client, MMA9551_APPID_PEDOMETER,
MMA9553_REG_CONF_SLEEPMIN,
- sizeof(data->conf), (u16 *) &data->conf);
+ sizeof(data->conf) / sizeof(u16),
+ (u16 *)&data->conf);
if (ret < 0) {
dev_err(&data->client->dev,
"failed to write configuration registers\n");
--
1.9.1
next prev parent reply other threads:[~2015-04-13 15:41 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-13 15:40 [PATCH v2 00/17] Fixes for the mma9553 driver Irina Tirdea
2015-04-13 15:40 ` [PATCH v2 01/17] iio: accel: mma9553: fix endianness issue when reading status Irina Tirdea
2015-04-26 18:40 ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 02/17] iio: accel: mma9553: check input value for activity period Irina Tirdea
2015-04-26 18:43 ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 03/17] iio: accel: mma9551_core: prevent buffer overrun Irina Tirdea
2015-04-26 18:41 ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 04/17] iio: accel: mma9553: add enable channel for activity Irina Tirdea
2015-04-26 18:42 ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 05/17] iio: accel: mma9551_core: wrong doc fixes Irina Tirdea
2015-04-26 18:45 ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 06/17] iio: accel: mma9551_core: typo fix in RSC APP ID Irina Tirdea
2015-04-26 18:46 ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 07/17] iio: accel: mma9553: check for error in reading initial activity and stepcnt Irina Tirdea
2015-04-26 18:47 ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 08/17] iio: accel: mma9553: return 0 as indication of success Irina Tirdea
2015-04-13 15:40 ` [PATCH v2 09/17] iio: accel: mma9553: comment and error message fixes Irina Tirdea
2015-04-26 18:48 ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 10/17] iio: accel: mma9553: use GENMASK Irina Tirdea
2015-04-26 18:49 ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 11/17] iio: accel: mma9553: prefix naming fixes Irina Tirdea
2015-04-26 18:49 ` Jonathan Cameron
2015-04-13 15:40 ` [PATCH v2 12/17] iio: accel: mma9553: fix gpio bitnum init value Irina Tirdea
2015-04-26 18:53 ` Jonathan Cameron
2015-04-13 15:41 ` [PATCH v2 13/17] iio: accel: mma9553: refactor mma9553_read_raw Irina Tirdea
2015-04-26 18:53 ` Jonathan Cameron
2015-04-13 15:41 ` Irina Tirdea [this message]
2015-04-26 19:04 ` [PATCH v2 14/17] iio: accel: mma9551_core: use size in words for word buffers Jonathan Cameron
2015-04-29 12:20 ` Tirdea, Irina
2015-06-14 15:00 ` Jonathan Cameron
2015-06-23 14:17 ` Tirdea, Irina
2015-04-13 15:41 ` [PATCH v2 15/17] iio: accel: mma9553: fix alignment issues Irina Tirdea
2015-06-14 15:01 ` Jonathan Cameron
2015-04-13 15:41 ` [PATCH v2 16/17] iio: accel: mma9553: document use of mutex Irina Tirdea
2015-06-14 15:02 ` Jonathan Cameron
2015-04-13 15:41 ` [PATCH v2 17/17] iio: accel: mma9553: use unsigned counters Irina Tirdea
2015-06-14 15:04 ` Jonathan Cameron
2015-06-23 14:17 ` Tirdea, Irina
2015-04-26 21:50 ` [PATCH v2 00/17] Fixes for the mma9553 driver Hartmut Knaack
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=1428939664-12503-15-git-send-email-irina.tirdea@intel.com \
--to=irina.tirdea@intel.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vlad.dogaru@intel.com \
/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