Thread (6 messages) 6 messages, 2 authors, 5d ago

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

From: Rosen Penev <hidden>
Date: 2026-06-30 01:42:47
Also in: linux-arm-kernel, linux-hardening, lkml

On Wed, May 6, 2026 at 4:09 AM Nishanth Menon [off-list ref] wrote:
For some reason, replying drops the CC list. manually added them in.
Found the issue:

https://lore.kernel.org/lkml/20260630014129.1548147-1-rosenp@gmail.com/T/#u (local)
On 20:12-20260503, Rosen Penev wrote:
quoted
Use a flexible array member to combine allocations.

Add __counted_by for extra runtime analysis.

Fixup k3-udma as well since ti_sci_resource is used there as well and
needs fixing up to use kzalloc_flex.

Signed-off-by: Rosen Penev <redacted>
---
 v2: add k3-udma fixes.
 drivers/dma/ti/k3-udma.c               | 180 +++++++++++++------------
 drivers/firmware/ti_sci.c              |   7 +-
 include/linux/soc/ti/ti_sci_protocol.h |   2 +-
 3 files changed, 98 insertions(+), 91 deletions(-)
Since majority of the changes are via k3-udma.c, if this could go via
dma tree, it would be nice. Else, please give an ack and I can carry on
my tree.

For the following:
Reviewed-by: Nishanth Menon <nm@ti.com>
quoted
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
--
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
https://ti.com/opensource
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help