Re: [PATCHv2] dmaengine: hsu: use kzalloc_flex()
From: Andy Shevchenko
Date: Mon Mar 30 2026 - 04:57:39 EST
On Sat, Mar 28, 2026 at 9:17 PM Rosen Penev <rosenp@xxxxxxxxx> wrote:
>
> Simplifies allocations by using a flexible array member in this struct.
>
> Remove hsu_dma_alloc_desc(). It now offers no readability advantages in
> this single usage.
>
> Add __counted_by to get extra runtime analysis.
> Apply the exact same treatment to struct hsu_dma and devm_kzalloc.
We refer to the functions as func(): devm_kzalloc().
...
> - hsu = devm_kzalloc(chip->dev, sizeof(*hsu), GFP_KERNEL);
> + /* Calculate nr_channels from the IO space length */
> + nr_channels = (chip->length - chip->offset) / HSU_DMA_CHAN_LENGTH;
> + hsu = devm_kzalloc(chip->dev, struct_size(hsu, chan, nr_channels), GFP_KERNEL);
> if (!hsu)
> return -ENOMEM;
>
> - chip->hsu = hsu;
> -
> - /* Calculate nr_channels from the IO space length */
> - hsu->nr_channels = (chip->length - chip->offset) / HSU_DMA_CHAN_LENGTH;
> + hsu->nr_channels = nr_channels;
>
> - hsu->chan = devm_kcalloc(chip->dev, hsu->nr_channels,
> - sizeof(*hsu->chan), GFP_KERNEL);
> - if (!hsu->chan)
> - return -ENOMEM;
> + chip->hsu = hsu;
Don't know these _flex() APIs enough, but can we leave the chip->hsu =
hsu; in the same place as it's now?
--
With Best Regards,
Andy Shevchenko