Re: [PATCH v2] iio: st_sensors: drop temporary kmalloc buffer and reuse buffer_data
From: Andy Shevchenko
Date: Wed Mar 11 2026 - 16:22:29 EST
On Wed, Mar 11, 2026 at 8:21 PM Sanjay Chitroda
<sanjayembeddedse@xxxxxxxxx> wrote:
>
> From: Sanjay Chitroda <sanjayembeddedse@xxxxxxxxx>
>
> Replace the per-call kmalloc() scratch buffer with the statically allocated
> buffer_data[] field present in struct st_sensor_data. The existing buffer
> is DMA-aligned and sufficiently sized for all channel widths, so using it
> avoids unnecessary dynamic memory allocation on each read.
>
> This simplifies the code, removes redundent code and allocation.
Spell check your commit messages.
> No functional change intended.
...
> int err;
> - u8 *outdata;
> struct st_sensor_data *sdata = iio_priv(indio_dev);
> unsigned int byte_for_channel;
>
> byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits +
> ch->scan_type.shift, 8);
> + u8 *outdata = (u8 *)sdata->buffer_data;
No. We don't mess up with C99 definitions. The only exceptions are
loop iterators and scoped variables which are none in this case.
--
With Best Regards,
Andy Shevchenko