[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aBSWmeRaPg5U8f7v@smile.fi.intel.com>
Date: Fri, 2 May 2025 12:55:37 +0300
From: Andy Shevchenko <andy@...nel.org>
To: David Lechner <dlechner@...libre.com>
Cc: Michael Hennerich <Michael.Hennerich@...log.com>,
Jonathan Cameron <jic23@...nel.org>,
Nuno Sá <nuno.sa@...log.com>,
Angelo Dureghello <adureghello@...libre.com>,
Jonathan Cameron <Jonathan.Cameron@...wei.com>,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] iio: adc: ad7606_spi: add offload scan mask check
On Wed, Apr 30, 2025 at 04:41:58PM -0500, David Lechner wrote:
> Validate the scan mask when SPI offloading is being used.
>
> Since this family of ADCs is simultaneous sampling, there isn't a way
> to selectively disable channels when reading sample data. (Technically,
> AD7616 has a sequencer so could have some control, but that is for
> another day).
>
> For "regular" IIO triggered buffer reads, this isn't a problem and the
> IIO core will demux the data and ignore data from disabled channels.
> However, since SPI offloading is done completely in hardware, we don't
> have a way to do the same. So before this patch, if less than all
> channels were enabled, the data would be misplaced in the buffer.
>
> By adding a check in update_scan_mode, we can fail to enable the buffer
> instead of having bad data returned to userspace.
...
> +static int ad7606_spi_update_scan_mode(struct iio_dev *indio_dev,
> + const unsigned long *scan_mask)
> +{
> + struct ad7606_state *st = iio_priv(indio_dev);
> +
> + if (st->offload_en) {
> + DECLARE_BITMAP(bitmap, AD760X_MAX_CHANNELS);
> +
> + bitmap_fill(bitmap, AD760X_MAX_CHANNELS);
> +
> + /*
> + * SPI offload requires that all channels are enabled since
> + * there isn't a way to selectively disable channels that get
> + * read (this is simultaneous sampling ADC) and the DMA buffer
> + * has no way of demuxing the data to filter out unwanted
> + * channels.
> + */
> + if (!bitmap_equal(bitmap, scan_mask,
> + st->chip_info->num_adc_channels))
> + return -EINVAL;
No need to have the local variable, just make sure that bitmap_weigth(FOO) == FOO.
if (... && bitmap_weight(FOO) != FOO)
return -EINVAL;
> + }
> +
> + return 0;
> +}
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists