[PATCH v11 2/8] iio: accel: adxl345: simplify reading the FIFO

Lothar Rubusch posted 8 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH v11 2/8] iio: accel: adxl345: simplify reading the FIFO
Posted by Lothar Rubusch 3 months, 1 week ago
Bulk FIFO reading can be streamlined by eliminating redundant variables and
simplifying the process of reading x-, y-, and z-axis measurement sets.

This is a refactoring change with no expected impact on functionality.

Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com>
---
 drivers/iio/accel/adxl345_core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index 6c437d7a59ed..b7dfd0007aa0 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -885,15 +885,12 @@ static int adxl345_get_samples(struct adxl345_state *st)
  */
 static int adxl345_fifo_transfer(struct adxl345_state *st, int samples)
 {
-	size_t count;
 	int i, ret = 0;
 
-	/* count is the 3x the fifo_buf element size, hence 6B */
-	count = sizeof(st->fifo_buf[0]) * ADXL345_DIRS;
 	for (i = 0; i < samples; i++) {
-		/* read 3x 2 byte elements from base address into next fifo_buf position */
 		ret = regmap_bulk_read(st->regmap, ADXL345_REG_XYZ_BASE,
-				       st->fifo_buf + (i * count / 2), count);
+				       st->fifo_buf + (i * ADXL345_DIRS),
+				       sizeof(st->fifo_buf[0]) * ADXL345_DIRS);
 		if (ret)
 			return ret;
 
-- 
2.39.5
Re: [PATCH v11 2/8] iio: accel: adxl345: simplify reading the FIFO
Posted by Jonathan Cameron 3 months ago
On Wed,  2 Jul 2025 23:03:09 +0000
Lothar Rubusch <l.rubusch@gmail.com> wrote:

> Bulk FIFO reading can be streamlined by eliminating redundant variables and
> simplifying the process of reading x-, y-, and z-axis measurement sets.
> 
> This is a refactoring change with no expected impact on functionality.
> 
> Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com>
Applied.
> ---
>  drivers/iio/accel/adxl345_core.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
> index 6c437d7a59ed..b7dfd0007aa0 100644
> --- a/drivers/iio/accel/adxl345_core.c
> +++ b/drivers/iio/accel/adxl345_core.c
> @@ -885,15 +885,12 @@ static int adxl345_get_samples(struct adxl345_state *st)
>   */
>  static int adxl345_fifo_transfer(struct adxl345_state *st, int samples)
>  {
> -	size_t count;
>  	int i, ret = 0;
>  
> -	/* count is the 3x the fifo_buf element size, hence 6B */
> -	count = sizeof(st->fifo_buf[0]) * ADXL345_DIRS;
>  	for (i = 0; i < samples; i++) {
> -		/* read 3x 2 byte elements from base address into next fifo_buf position */
>  		ret = regmap_bulk_read(st->regmap, ADXL345_REG_XYZ_BASE,
> -				       st->fifo_buf + (i * count / 2), count);
> +				       st->fifo_buf + (i * ADXL345_DIRS),
> +				       sizeof(st->fifo_buf[0]) * ADXL345_DIRS);
>  		if (ret)
>  			return ret;
>