[PATCH 04/10] iio: adc: mxs-lradc-adc: use struct with aligned_s64 timestamp

Jonathan Cameron jic23 at kernel.org
Mon Apr 21 04:13:41 PDT 2025


On Fri, 18 Apr 2025 14:58:23 -0500
David Lechner <dlechner at baylibre.com> wrote:

> Use a struct with aligned s64_timestamp instead of a padded array for
> the buffer used for iio_push_to_buffers_with_ts(). This makes it easier
> to see the correctness of the size and alignment of the buffer.
> 
> Signed-off-by: David Lechner <dlechner at baylibre.com>
> ---
>  drivers/iio/adc/mxs-lradc-adc.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/adc/mxs-lradc-adc.c b/drivers/iio/adc/mxs-lradc-adc.c
> index 92baf3f5f5601b863c694eb03b6d8f287e4fe6ab..73e42f0ebcaeaaa437ba5c64ecdd7759a1191e6c 100644
> --- a/drivers/iio/adc/mxs-lradc-adc.c
> +++ b/drivers/iio/adc/mxs-lradc-adc.c
> @@ -116,7 +116,10 @@ struct mxs_lradc_adc {
>  
>  	void __iomem		*base;
>  	/* Maximum of 8 channels + 8 byte ts */

If we were keeping this (I think the buffer solution is better)
then we could drop that coment as to me this just became self describing code.
That's why I like these structures where we can use them with out confusion!

> -	u32			buffer[10] __aligned(8);
> +	struct {
> +		u32 data[8];
> +		aligned_u64 ts;
aligned_s64 

I've not idea why timestamps are signed, but they always have been!

> +	} buffer;
>  	struct iio_trigger	*trig;
>  	struct completion	completion;
>  	spinlock_t		lock;
> @@ -418,14 +421,14 @@ static irqreturn_t mxs_lradc_adc_trigger_handler(int irq, void *p)
>  	unsigned int i, j = 0;
>  
>  	for_each_set_bit(i, iio->active_scan_mask, LRADC_MAX_TOTAL_CHANS) {
> -		adc->buffer[j] = readl(adc->base + LRADC_CH(j));
> +		adc->buffer.data[j] = readl(adc->base + LRADC_CH(j));
>  		writel(chan_value, adc->base + LRADC_CH(j));
> -		adc->buffer[j] &= LRADC_CH_VALUE_MASK;
> -		adc->buffer[j] /= LRADC_DELAY_TIMER_LOOP;
> +		adc->buffer.data[j] &= LRADC_CH_VALUE_MASK;
> +		adc->buffer.data[j] /= LRADC_DELAY_TIMER_LOOP;
>  		j++;
>  	}
>  
> -	iio_push_to_buffers_with_ts(iio, adc->buffer, sizeof(adc->buffer),
> +	iio_push_to_buffers_with_ts(iio, &adc->buffer, sizeof(adc->buffer),
>  				    pf->timestamp);
>  
>  	iio_trigger_notify_done(iio->trig);
> 




More information about the linux-arm-kernel mailing list