Re: [PATCH v6 2/4] iio: adc: ad799x: use a static buffer for scan data

From: Andy Shevchenko

Date: Thu Mar 26 2026 - 15:18:20 EST


On Thu, Mar 26, 2026 at 11:35:27PM +0530, 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_BUFFER_WITH_TS().
> This eliminates the allocation overhead, prevents leaks, and removes
> the need for manual kfree() on driver removal.

...

> 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);

Indentation also can be fixed while at it

b_sent = i2c_smbus_read_i2c_block_data(st->client,
cmd, st->transfer_size,
(u8 *)st->rx_buf);

(no need to resend just because of this).

> if (b_sent < 0)
> goto out;

--
With Best Regards,
Andy Shevchenko