From: Jonathan Cameron <jic23@kernel.org>
To: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Cc: "Kanak Shilledar" <kanak.shilledar@axis.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Henrik Grimler" <henrik.grimler@axis.com>,
"Jean-Baptiste Maneyrol" <jean-baptiste.maneyrol@tdk.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel@axis.com
Subject: Re: [PATCH 2/3] iio: accel: Add support for ICM42370P
Date: Sun, 16 Aug 2026 02:58:58 +0100 [thread overview]
Message-ID: <20260816025858.451dbbcb@jic23-huawei> (raw)
In-Reply-To: <andT6r0ZIR1DuZWg@debian-BULLSEYE-live-builder-AMD64>
> > +/**
> > + * struct inv_icm42370_data - driver state variables
> > + * @lock: lock for serializing multiple register access.
> > + * @name: chip name.
> > + * @map: regmap pointer.
> > + * @vdd_supply: VDD voltage regulator for the chip.
> > + * @vddio_supply: I/O voltage regulator for the chip.
> > + * @indio_accel: accelerometer IIO device.
> > + * @sensor_state: per-sensor state tracking (e.g. power, ODR).
> > + * @buffer: buffer for reading data registers, aligned for DMA.
> > + * @accel_calibbias: accelerometer calibration bias for X, Y, and Z axes.
> > + * @fifo: FIFO state and configuration.
> > + * @timestamp: interrupt timestamp.
> > + * @chip: chip identifier.
> > + * @conf: chip sensors configurations.
> > + */
> > +struct inv_icm42370_data {
> There is another 'state' struct declared below which leaves us with two types of
> state structs for icm42370? Would it make sense to have them merged?
>
> > + struct mutex lock;
> > + const char *name;
> > + struct regmap *map;
> > + struct regulator *vdd_supply;
> > + struct regulator *vddio_supply;
> I'm not seeing the regulators being used after probe. For these power supplies,
> devm_regulator_get_enable() is usually enough to get them running. If that
> applies to icm42370, then there will be no need for vdd fields in the state struct.
>
> > + struct iio_dev *indio_accel;
> > + struct inv_icm42370_sensor_state *sensor_state;
> > + u8 buffer[2] __aligned(IIO_DMA_MINALIGN);
> The __aligned() pragma forces cache line alignment on the field it annotates.
> IIO device drivers often have annotations like that to make data buffers use
> separate cache lines and thus avoid data mishandling when doing DMA.
> Though, if the alignment is forced closer to the beginning of the struct, we
> may end up with holes in memory. This is not a subject I specialize in, though,
> you may find this LWN article better than my poor explanation.
> https://lwn.net/Articles/335942/
>
> Besides avoiding holes in data structures, running pahole may also help you
> better understand the alignment issue.
Marcelo, you indeed highlighted a problem but not quite the reason it is
a problem. __aligned(IIO_DMA_MINALIGN) forces the alignment of the beginning
of the buffer to be on a cacheline. It doesn't do anything about the next
element. The aim here is to ensure that any data accesses by DMA doesn't
share a cacheline with data that may be accessed concurrently by the CPU.
It seems very likely some of the stuff that follows might be accessed
at that time and hence potentially corrupted by stale values coming back
from the DMA engine which thinks it has exclusive control of the cacheline.
Hence put them at the end of the structure not in the middle ensures there
is nothing in that space. Structures are padded to a multiple of the
highest aligned element.
I just took a quick glance at existing comments to see where things
stood before looking at v2 and this jumped out at me
Jonathan
>
> > + s16 accel_calibbias[3];
> > + struct inv_icm42370_fifo fifo;
> > + s64 timestamp;
> > + enum inv_icm42370_chip chip;
> > + struct inv_icm42370_conf conf;
> > +};
next prev parent reply other threads:[~2026-08-16 1:59 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 12:46 [PATCH 0/3] Add driver for Invensense ICM42370P accelerometer Kanak Shilledar
2026-08-06 12:46 ` [PATCH 1/3] dt-bindings: Add InvenSense ICM-42370-p accelerometer Kanak Shilledar
2026-08-06 12:53 ` sashiko-bot
2026-08-07 10:16 ` Joshua Crofts
2026-08-07 13:15 ` Kanak Shilledar
2026-08-12 2:59 ` Rob Herring
2026-08-06 12:46 ` [PATCH 2/3] iio: accel: Add support for ICM42370P Kanak Shilledar
2026-08-06 13:02 ` sashiko-bot
2026-08-07 6:51 ` Uwe Kleine-König
2026-08-07 13:11 ` Kanak Shilledar
2026-08-07 10:09 ` Joshua Crofts
2026-08-07 13:41 ` Kanak Shilledar
2026-08-07 14:13 ` Joshua Crofts
2026-08-13 12:37 ` Kanak Shilledar
2026-08-08 16:06 ` Marcelo Schmitt
2026-08-16 1:58 ` Jonathan Cameron [this message]
2026-08-06 12:46 ` [PATCH 3/3] iio: accel: icm42370: Add FIFO buffer functionality Kanak Shilledar
2026-08-06 13:03 ` sashiko-bot
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=20260816025858.451dbbcb@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=henrik.grimler@axis.com \
--cc=jean-baptiste.maneyrol@tdk.com \
--cc=kanak.shilledar@axis.com \
--cc=kernel@axis.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/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