Re: [PATCH] iio: adc: ti-ads7138: explicitly include <linux/slab.h>

From: Jonathan Cameron

Date: Fri Apr 24 2026 - 13:14:31 EST


On Fri, 24 Apr 2026 14:33:45 +0300
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:

> On Fri, Apr 24, 2026 at 11:36:00AM +0100, Jonathan Cameron wrote:
> > On Fri, 24 Apr 2026 12:07:24 +0300
> > Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:
> > > On Fri, Apr 24, 2026 at 12:18:10PM +0400, Giorgi Tchankvetadze wrote:
>
> ...
>
> > > WRT to the kmalloc() use, wouldn't it be simply better to use
> > > i2c_master_send_dmasafe() and kill that kmalloc() dance in the driver?
> >
> > That sounds backwards. IIRC i2c_master_send_dmasafe() needs a heap allocation
> > to ensure a DMA safe buffer. See i2c_get_dma_safe_msg_buf() and
> > the check on I2C_M_DMA_SAFE.
>
> Ah, I thought it's opposite, but looking at the usage it seems like it's host
> controller driver responsibility to use DMA or not for the transfer.
>
> Why do we need to have kmalloc() here at all? I don't understand that.
Absolutely. Locally it looks like length might be large and therefore
the array not suitable to be on the stack, but that's not the case.
length == 2 so the array only has 4 elements and can go on the stack.

>
> > This function is just overly flexible.
>