[PATCH 07/11] firmware: arm_scmi: Harden clock parents discovery
Cristian Marussi
cristian.marussi at arm.com
Sat Feb 28 02:37:55 PST 2026
On Sat, Feb 28, 2026 at 10:39:59AM +0800, Peng Fan wrote:
> On Fri, Feb 27, 2026 at 03:32:21PM +0000, Cristian Marussi wrote:
> >Fix clock parents enumeration to account only for effectively discovered
> >parents during enumeration, avoiding to trust the total number of parents
> >declared upfront by the platform.
> >
> >Signed-off-by: Cristian Marussi <cristian.marussi at arm.com>
> >---
> > drivers/firmware/arm_scmi/clock.c | 18 ++++++++++--------
> > 1 file changed, 10 insertions(+), 8 deletions(-)
> >
> >diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/clock.c
> >index d0fb5affb5cf..15faa79abed4 100644
> >--- a/drivers/firmware/arm_scmi/clock.c
> >+++ b/drivers/firmware/arm_scmi/clock.c
> >@@ -270,15 +270,15 @@ static int iter_clk_possible_parents_update_state(struct scmi_iterator_state *st
> > * assume it's returned+remaining on first call.
> > */
> > if (!st->max_resources) {
> >- p->clkd->info.num_parents = st->num_returned + st->num_remaining;
> >- p->clkd->info.parents = devm_kcalloc(p->dev,
> >- p->clkd->info.num_parents,
> >+ int num_parents = st->num_returned + st->num_remaining;
> >+
> >+ p->clkd->info.parents = devm_kcalloc(p->dev, num_parents,
> > sizeof(*p->clkd->info.parents),
> > GFP_KERNEL);
> >- if (!p->clkd->info.parents) {
> >- p->clkd->info.num_parents = 0;
> >+ if (!p->clkd->info.parents)
> > return -ENOMEM;
> >- }
> >+
> >+ /* max_resources is used by the iterators to control bounds */
> > st->max_resources = st->num_returned + st->num_remaining;
> > }
> >
> >@@ -293,9 +293,11 @@ static int iter_clk_possible_parents_process_response(const struct scmi_protocol
> > const struct scmi_msg_resp_clock_possible_parents *r = response;
> > struct scmi_clk_ipriv *p = priv;
> >
> >- u32 *parent = &p->clkd->info.parents[st->desc_index + st->loop_idx];
> >+ p->clkd->info.parents[st->desc_index + st->loop_idx] =
> >+ le32_to_cpu(r->possible_parents[st->loop_idx]);
> >
> >- *parent = le32_to_cpu(r->possible_parents[st->loop_idx]);
> >+ /* Count only effectively discovered parents */
> >+ p->clkd->info.num_parents++;
>
> It maybe good to give a warning, if mismatch between
> number of effectively discovered parents and "st->num_returned + st->num_remaining"
>
Indeed there could be sign of something off fw-side...
> Anyway this patch LGTM:
>
> Reviewed-by: Peng Fan <peng.fan at nxp.com>
>
Thanks,
Cristian
More information about the linux-arm-kernel
mailing list