public inbox for linux-doc@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lothar Rubusch <l.rubusch@gmail.com>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com,
	dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	corbet@lwn.net, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	eraretuya@gmail.com
Subject: Re: [PATCH v9 05/11] iio: accel: adxl345: simplify reading the FIFO
Date: Sat, 21 Jun 2025 17:58:24 +0100	[thread overview]
Message-ID: <20250621175824.57bb9d9c@jic23-huawei> (raw)
In-Reply-To: <CAFXKEHaGk5NZ4dT9xLkAfirn974P9miwjs=5N+PTqJ2x00QOiA@mail.gmail.com>

On Mon, 16 Jun 2025 00:14:47 +0200
Lothar Rubusch <l.rubusch@gmail.com> wrote:

> Hi Jonathan,
> 
> On Sat, Jun 14, 2025 at 3:47 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > On Tue, 10 Jun 2025 21:59:27 +0000
> > Lothar Rubusch <l.rubusch@gmail.com> wrote:
> >  
> > > Bulk reading from the FIFO can be simplified. Remove unnecessary
> > > variables and simplify reading sets of x-, y- and z-axis measurements.
> > >
> > > This is a refactoring change and should not impact functionality.
> > >
> > > Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com>
> > > ---
> > >  drivers/iio/accel/adxl345_core.c | 6 ++----
> > >  1 file changed, 2 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
> > > index 18c625d323ba..dcfbfe4cac0f 100644
> > > --- a/drivers/iio/accel/adxl345_core.c
> > > +++ b/drivers/iio/accel/adxl345_core.c
> > > @@ -884,15 +884,13 @@ 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),
> > > +                                    2 * ADXL345_DIRS);  
> >                                        sizeof(st->fifo_buf[0]) * ADXL345_DIRS);
> >
> > As it's not locally obvious where that 2 comes from.  
> 
> Hm, I left the comment some lines above: "read 3x 2 byte elements from
> base address into next fifo_buf position" - so, the 2 comes from the 2
> bytes. 3x because of the 3-axis sensor, so 3 axis times 2 bytes. How
> can I improve it? The patch is just a simplification, removing that
> unnecessary count variable.

 sizeof(st->fifo_buf[0]) * ADXL345_DIRS);

improves it by making it clear where the 2 comes from.
Getting rid of count is good, but that remaining 2 * 
should be replaced by using sizeof() the buffer element.

The comment would then be unnecessary as we are sizing it directly from
the fifo storage.  Fine to leave it if you like though.

Jonathan


> 
> >  
> > >               if (ret)
> > >                       return ret;
> > >  
> >  


  reply	other threads:[~2025-06-21 16:58 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-10 21:59 [PATCH v9 00/11] iio: accel: adxl345: add interrupt based sensor events Lothar Rubusch
2025-06-10 21:59 ` [PATCH v9 01/11] iio: accel: adxl345: apply scale factor to tap threshold Lothar Rubusch
2025-06-14 13:42   ` Jonathan Cameron
2025-06-15 22:20     ` Lothar Rubusch
2025-06-21 16:55       ` Jonathan Cameron
2025-06-21 18:14         ` Lothar Rubusch
2025-06-10 21:59 ` [PATCH v9 02/11] iio: accel: adxl345: make data struct variable irq function local Lothar Rubusch
2025-06-14 13:43   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 03/11] iio: accel: adxl345: simplify measure enable Lothar Rubusch
2025-06-14 13:45   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 04/11] iio: accel: adxl345: simplify interrupt mapping Lothar Rubusch
2025-06-11 15:20   ` Andy Shevchenko
2025-06-10 21:59 ` [PATCH v9 05/11] iio: accel: adxl345: simplify reading the FIFO Lothar Rubusch
2025-06-14 13:47   ` Jonathan Cameron
2025-06-15 22:14     ` Lothar Rubusch
2025-06-21 16:58       ` Jonathan Cameron [this message]
2025-06-10 21:59 ` [PATCH v9 06/11] iio: accel: adxl345: replace magic numbers by unit expressions Lothar Rubusch
2025-06-14 13:49   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 07/11] iio: accel: adxl345: add activity event feature Lothar Rubusch
2025-06-12 11:51   ` Andy Shevchenko
2025-06-21 18:06     ` Lothar Rubusch
2025-06-21 19:55       ` Andy Shevchenko
2025-06-10 21:59 ` [PATCH v9 08/11] iio: accel: adxl345: add inactivity feature Lothar Rubusch
2025-06-12 12:15   ` Andy Shevchenko
2025-06-14 13:55     ` Jonathan Cameron
2025-06-14 19:02       ` Andy Shevchenko
2025-06-21 18:53     ` Lothar Rubusch
2025-06-21 19:24       ` Andy Shevchenko
2025-06-21 19:28         ` Andy Shevchenko
2025-06-14 14:00   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 09/11] iio: accel: adxl345: add coupling detection for activity/inactivity Lothar Rubusch
2025-06-14 14:04   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 10/11] iio: accel: adxl345: extend inactivity time for less than 1s Lothar Rubusch
2025-06-14 14:10   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 11/11] docs: iio: add documentation for adxl345 driver Lothar Rubusch
2025-06-14 14:17   ` Jonathan Cameron

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=20250621175824.57bb9d9c@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dlechner@baylibre.com \
    --cc=eraretuya@gmail.com \
    --cc=l.rubusch@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.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