]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
iio: accel: mma9551_core: use size in words for word buffers
authorIrina Tirdea <irina.tirdea@intel.com>
Mon, 13 Apr 2015 15:41:01 +0000 (18:41 +0300)
committerJonathan Cameron <jic23@kernel.org>
Sun, 14 Jun 2015 14:59:28 +0000 (15:59 +0100)
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>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/accel/mma9551_core.c
drivers/iio/accel/mma9553.c

index 2fd2a995686b273dae815f2bdb344c6a10284ea0..583660b74f42b543003f00e4012204a45d9fec0c 100644 (file)
@@ -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);
 
index 8bfc61824fb2378ab8554777bc1d0842c2bdb7a0..06c870789383c78c6bee22652a62772f4e87f51d 100644 (file)
@@ -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");