Re: [PATCH] firmware: ti_sci: simplify resource allocation

From: Rosen Penev

Date: Thu Sep 03 2026 - 16:47:06 EST


On Thu, Sep 3, 2026 at 10:48 AM Nishanth Menon <nm@xxxxxx> wrote:
>
> On 15:11-20260430, Rosen Penev wrote:
> > Use a flexible array member to combine allocations.
> >
> > Add __counted_by for extra runtime analysis.
> >
> > Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
> > ---
> > drivers/firmware/ti_sci.c | 7 +------
> > include/linux/soc/ti/ti_sci_protocol.h | 2 +-
> > 2 files changed, 2 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
> > index e027a2bd8f26..04d99c1fafa1 100644
> > --- a/drivers/firmware/ti_sci.c
> > +++ b/drivers/firmware/ti_sci.c
> > @@ -3574,16 +3574,11 @@ devm_ti_sci_get_resource_sets(const struct ti_sci_handle *handle,
> > bool valid_set = false;
> > int i, ret, res_count;
> >
> > - res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL);
> > + res = devm_kzalloc(dev, struct_size(res, desc, sets), GFP_KERNEL);
> > if (!res)
> > return ERR_PTR(-ENOMEM);
> >
> > res->sets = sets;
> > - res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc),
> > - GFP_KERNEL);
> > - if (!res->desc)
> > - return ERR_PTR(-ENOMEM);
> > -
> > for (i = 0; i < res->sets; i++) {
> > ret = handle->ops.rm_core_ops.get_range(handle, dev_id,
> > sub_types[i],
> > diff --git a/include/linux/soc/ti/ti_sci_protocol.h b/include/linux/soc/ti/ti_sci_protocol.h
> > index fd104b666836..7632bb11c862 100644
> > --- a/include/linux/soc/ti/ti_sci_protocol.h
> > +++ b/include/linux/soc/ti/ti_sci_protocol.h
> > @@ -599,7 +599,7 @@ struct ti_sci_handle {
> > struct ti_sci_resource {
> > u16 sets;
> > raw_spinlock_t lock;
> > - struct ti_sci_resource_desc *desc;
> > + struct ti_sci_resource_desc desc[] __counted_by(sets);
> > };
> >
> > #if IS_ENABLED(CONFIG_TI_SCI_PROTOCOL)
> > --
> > 2.54.0
> >
>
> drivers/dma/ti/k3-udma.c: In function 'udma_setup_resources':
> drivers/dma/ti/k3-udma.c:4689:22: error: invalid use of flexible array member
> 4689 | irq_res.desc = kzalloc_objs(*irq_res.desc, irq_res.sets);
> | ^
> drivers/dma/ti/k3-udma.c:4690:13: warning: the comparison will always evaluate as 'true' for the address of 'desc' will never be NULL [-Waddress]
> 4690 | if (!irq_res.desc)
> | ^
> In file included from drivers/dma/ti/k3-udma.c:27:
> ./include/linux/soc/ti/ti_sci_protocol.h:602:37: note: 'desc' declared here
> 602 | struct ti_sci_resource_desc desc[] __counted_by(sets);
> | ^~~~
> drivers/dma/ti/k3-udma.c: In function 'bcdma_setup_resources':
> drivers/dma/ti/k3-udma.c:4881:22: error: invalid use of flexible array member
> 4881 | irq_res.desc = kzalloc_objs(*irq_res.desc, irq_res.sets);
> | ^
> drivers/dma/ti/k3-udma.c:4882:13: warning: the comparison will always evaluate as 'true' for the address of 'desc' will never be NULL [-Waddress]
> 4882 | if (!irq_res.desc)
> | ^
> ./include/linux/soc/ti/ti_sci_protocol.h:602:37: note: 'desc' declared here
> 602 | struct ti_sci_resource_desc desc[] __counted_by(sets);
> | ^~~~
> drivers/dma/ti/k3-udma.c: In function 'pktdma_setup_resources':
> drivers/dma/ti/k3-udma.c:5083:22: error: invalid use of flexible array member
> 5083 | irq_res.desc = kzalloc_objs(*irq_res.desc, irq_res.sets);
> | ^
> drivers/dma/ti/k3-udma.c:5084:13: warning: the comparison will always evaluate as 'true' for the address of 'desc' will never be NULL [-Waddress]
> 5084 | if (!irq_res.desc)
> | ^
> ./include/linux/soc/ti/ti_sci_protocol.h:602:37: note: 'desc' declared here
> 602 | struct ti_sci_resource_desc desc[] __counted_by(sets);
> | ^~~~
> drivers/dma/ti/k3-udma.c: At top level:
> drivers/dma/ti/k3-udma.c:53:9: warning: macro "UDMA_RFLOW_DSTTAG_FLOW_ID" is not used [-Wunused-macros]
> 53 | #define UDMA_RFLOW_DSTTAG_FLOW_ID 2
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/dma/ti/k3-udma.c:52:9: warning: macro "UDMA_RFLOW_DSTTAG_CFG_TAG" is not used [-Wunused-macros]
> 52 | #define UDMA_RFLOW_DSTTAG_CFG_TAG 1
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/dma/ti/k3-udma.c:48:9: warning: macro "UDMA_RFLOW_SRCTAG_FLOW_ID" is not used [-Wunused-macros]
> 48 | #define UDMA_RFLOW_SRCTAG_FLOW_ID 2
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/dma/ti/k3-udma.c:51:9: warning: macro "UDMA_RFLOW_DSTTAG_NONE" is not used [-Wunused-macros]
> 51 | #define UDMA_RFLOW_DSTTAG_NONE 0
> | ^~~~~~~~~~~~~~~~~~~~~~
> drivers/dma/ti/k3-udma.c:47:9: warning: macro "UDMA_RFLOW_SRCTAG_CFG_TAG" is not used [-Wunused-macros]
> 47 | #define UDMA_RFLOW_SRCTAG_CFG_TAG 1
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> make[5]: *** [scripts/Makefile.build:290: drivers/dma/ti/k3-udma.o] Error 1
> make[4]: *** [scripts/Makefile.build:551: drivers/dma/ti] Error 2
> make[3]: *** [scripts/Makefile.build:551: drivers/dma] Error 2
> make[3]: *** Waiting for unfinished jobs....
> make[2]: *** [scripts/Makefile.build:551: drivers] Error 2
> make[1]: *** [/workdir/Makefile:2232: .] Error 2
> make: *** [Makefile:248: __sub-make] Error 2
>
>
> If I am not mistaken, k3-udma.c and k3-ringacc.c will be impacted. can
> you check and update the patch?
Just the former.
>
>
> Additionally, please CC LAKML.
linux-arm-kernel@xxxxxxxxxxxxxxxxxxx is already in CC.
>
> --
> Regards,
> Nishanth Menon
> Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3 1A34 DDB5 849D 1736 249D
> https://ti.com/opensource