On Sat, Mar 28, 2026 at 9:17 PM Rosen Penev <[email protected]> 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

Reply via email to