Skip to contentSkip to conversation

iio: accel: kxsd9: Fix alignment of local buffer.

PATCH In review [email protected] 3 participants 3 messages May 3, 2020 – May 4, 2020 IIO

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 iio: accel: kxsd9: Fix alignment of local buffer.

From: Jonathan Cameron <[email protected]>

iio_push_to_buffers_with_timestamp assumes 8 byte alignment which is not guaranteed by an array of 8 __be16.

---
 drivers/iio/accel/kxsd9.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/iio/accel/kxsd9.c +7 -5
index 0b876b2dc5bd..4c42d1200914 100644
@@ -209,14 +209,16 @@ static irqreturn_t kxsd9_trigger_handler(int irq, void *p)
 	const struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct kxsd9_state *st = iio_priv(indio_dev);
+	struct {
+		__be16 chan[4];
+		u64 ts;
+	} hw_values;
 	int ret;
-	/* 4 * 16bit values AND timestamp */
-	__be16 hw_values[8];
 
 	ret = regmap_bulk_read(st->map,
 			       KXSD9_REG_X,
-			       &hw_values,
-			       8);
+			       hw_values.chan,
+			       sizeof(hw_values.chan));
 	if (ret) {
 		dev_err(st->dev,
 			"error reading data\n");
@@ -224,7 +226,7 @@ static irqreturn_t kxsd9_trigger_handler(int irq, void *p)
 	}
 
 	iio_push_to_buffers_with_timestamp(indio_dev,
-					   hw_values,
+					   &hw_values,
 					   iio_get_time_ns(indio_dev));
 	iio_trigger_notify_done(indio_dev->trig);
 
Signature · 1 line
2.26.2
#1 lore raw
Quoted 16 lines · On Sun, 2020-05-03 at 18:22 +0100, [email protected] wrote:

From: Jonathan Cameron <[email protected]>

iio_push_to_buffers_with_timestamp assumes 8 byte alignment which is not guaranteed by an array of 8 __be16.

---
 drivers/iio/accel/kxsd9.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/iio/accel/kxsd9.c +0 -0
index 0b876b2dc5bd..4c42d1200914 100644

drivers/iio/accel/kxsd9.c static irqreturn_t kxsd9_trigger_handler(int · line 216

Quoted 8 lines
drivers/iio/accel/kxsd9.c +4 -0
@@ -209,14 +209,16 @@ static irqreturn_t kxsd9_trigger_handler(int
 irq, void *p)
 	const struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct kxsd9_state *st = iio_priv(indio_dev);
+	struct {
+		__be16 chan[4];
+		u64 ts;
+	} hw_values;

A nitpick from my side. Maybe a comment woudn't be that noisy. It might be not that obvious for some people why this construct is needed and it might prevent new driver's from doing the same mistake.

- Nuno Sá

#2 lore raw
Quoted 21 lines · On Sun, 3 May 2020 20:01:56 +0200 Nuno Sá <[email protected]> wrote:
Quoted 20 lines · On Sun, 2020-05-03 at 18:22 +0100, [email protected] wrote:

From: Jonathan Cameron <[email protected]>

iio_push_to_buffers_with_timestamp assumes 8 byte alignment which is not guaranteed by an array of 8 __be16.

---
 drivers/iio/accel/kxsd9.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/iio/accel/kxsd9.c +0 -0
index 0b876b2dc5bd..4c42d1200914 100644
@@ -209,14 +209,16 @@ static irqreturn_t kxsd9_trigger_handler(int
 irq, void *p)
 	const struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct kxsd9_state *st = iio_priv(indio_dev);
Quoted 8 lines

drivers/iio/accel/kxsd9.c static irqreturn_t kxsd9_trigger_handler(int irq, void *p) · line 215

Quoted 4 lines
drivers/iio/accel/kxsd9.c +4 -0
+	struct {
+		__be16 chan[4];
+		u64 ts;
+	} hw_values;  

A nitpick from my side. Maybe a comment woudn't be that noisy. It might be not that obvious for some people why this construct is needed and it might prevent new driver's from doing the same mistake.

Good point. I'll add something like

/* Ensure correct positioning and alignment of timestamp */

above the struct definition.

Quoted 4 lines

- Nuno Sá