Re: [PATCH v3 1/4] iio: adc: ad799x: make rx_buf static and DMA-safe
From: David Lechner
Date: Mon Mar 02 2026 - 11:36:06 EST
On 3/2/26 7:06 AM, Archit Anant wrote:
> Currently, rx_buf is dynamically allocated using kmalloc() every time
> ad799x_update_scan_mode() is called. This can lead to memory leaks if
> the scan mask is updated multiple times.
>
> Drop the dynamic allocation and replace it with a static, buffer at the
> end of the state structure using IIO_DECLARE_DMA_BUFFER_WITH_TS().
> This eliminates the allocation overhead, prevents leaks, and removes
> the need for manual kfree() on driver removal.
>
> Suggested-by: David Lechner <dlechner@xxxxxxxxxxxx>
> Signed-off-by: Archit Anant <architanant5@xxxxxxxxx>
> ---
...
> @@ -217,11 +218,11 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
> }
>
> b_sent = i2c_smbus_read_i2c_block_data(st->client,
> - cmd, st->transfer_size, st->rx_buf);
> + cmd, st->transfer_size, (u8 *)st->rx_buf);
> if (b_sent < 0)
> goto out;
>
> - iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
> + iio_push_to_buffers_with_timestamp(indio_dev, &st->rx_buf,
Don't need & here since rx_buf is still an array.
> iio_get_time_ns(indio_dev));
> out:
> iio_trigger_notify_done(indio_dev->trig);