Re: [PATCH v2 1/2] iio: accel: kionix-kx022a: use scan struct for one-shot and trigger reads

Jonathan Cameron <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Message-ID <20260820030438.736b67e1@jic23-huawei>
On Wed, 19 Aug 2026 10:17:33 +0300
Andy Shevchenko <[email protected]> wrote:

> On Tue, Aug 18, 2026 at 10:51:21PM +0100, Gabriel Rondon wrote:
> > The driver kept two separate staging areas that hold the same thing:
> > buffer[8], a DMA-aligned area used by the one-shot read in
> > kx022a_get_axis() and by the triggered handler, and the scan struct,
> > used by the FIFO flush path. Both are three __le16 channels plus room
> > for the timestamp.
> > 
> > Drop buffer and route the one-shot read and the triggered handler
> > through scan.channels, so the driver has a single staging area. Move the
> > IIO_DMA_MINALIGN alignment onto scan, since it now backs the regmap bulk
> > reads that buffer used to.
> > 
> > No functional change. get_axis() only runs via read_raw() under
> > iio_device_claim_direct(), so it cannot run while the triggered buffer is
> > active, and the triggered handler only runs while it is; the two never
> > touch scan concurrently, exactly as they previously shared buffer.  
> 
> ...
> 
> > static int kx022a_get_axis(struct kx022a_data *data,  
> 
> >  {  
> 
> I would rather do this
> 
> 	__le16 *buf = &data->scan.channels[0];
> 
> >  	int ret;
> >  
> > -	ret = regmap_bulk_read(data->regmap, chan->address, &data->buffer[0],
> > -			       sizeof(__le16));
> > +	ret = regmap_bulk_read(data->regmap, chan->address,
> > +			       &data->scan.channels[0], sizeof(__le16));  
> 
> 	ret = regmap_bulk_read(data->regmap, chan->address, buf, sizeof(*buf));
> 
> >  	if (ret)
> >  		return ret;
> >  
> > -	*val = (s16)le16_to_cpu(data->buffer[0]);
> > +	*val = (s16)le16_to_cpu(data->scan.channels[0]);  
> 
> 	*val = (s16)le16_to_cpup(buf);
True - that is nicer. Tweaked.  Diff just to check I didn't get it wrong:

diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index 86f17431aa23..8f2810c8ffeb 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -610,14 +610,15 @@ static int kx022a_get_axis(struct kx022a_data *data,
                           struct iio_chan_spec const *chan,
                           int *val)
 {
+       __le16 *buf = &data->scan.channels[0];
        int ret;
 
        ret = regmap_bulk_read(data->regmap, chan->address,
-                              &data->scan.channels[0], sizeof(__le16));
+                              buf, sizeof(*buf));
        if (ret)
                return ret;
 
-       *val = (s16)le16_to_cpu(data->scan.channels[0]);
+       *val = (s16)le16_to_cpup(buf);
 
        return IIO_VAL_INT;
 }



>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.