Re: [PATCH 1/2] firmware: arm_scmi: Invoke proper protocol cleanup on failure

From: Jonathan Cameron

Date: Tue Nov 24 2026 - 17:44:07 EST


On Tue, 24 Nov 2026 18:51:10 +0000
Cristian Marussi <cristian.marussi@xxxxxxx> wrote:

> After a failure in the protocol initialization phase, invoke if provided
> the protocol deinitialization routines.
>
> Fixes: 48dc16e2e52c ("firmware: arm_scmi: Extend protocol registration interfaces")
> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
> Closes: https://sashiko.dev/#/bug/linux-12cc0795-af8e-4d0c-8f6a-780a6728de7a
> Signed-off-by: Cristian Marussi <cristian.marussi@xxxxxxx>

This function is 'fun' for it's mixing of devres, reference counting
and manual cleanup. Plus why is it responsible for the
scmi_protocol_put(proto) when the reference is grabbed in the caller?
There is no reason I can see we can't hold that reference past the calls
that follow which release a devres group but don't hold anything specific
the protocol module.

Anyhow, far as I can tell the fix is right but if anyone has the time I'd
take a look at whether this can be simplified.
So with that slightly doubtful set of comments in mind.

Reviewed-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxxxxxxxx>

> ---
> drivers/firmware/arm_scmi/driver.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index 05092301db29..2c4424aa0d37 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -2303,7 +2303,7 @@ scmi_alloc_init_protocol_instance(struct scmi_info *info,
> ret = idr_alloc(&info->protocols, pi, proto->id, proto->id + 1,
> GFP_KERNEL);
> if (ret != proto->id)
> - goto clean;
> + goto deinit;
>
> /*
> * Warn but ignore events registration errors since we do not want
> @@ -2324,6 +2324,9 @@ scmi_alloc_init_protocol_instance(struct scmi_info *info,
>
> return pi;
>
> +deinit:
> + if (pi->proto->instance_deinit)
> + pi->proto->instance_deinit(&pi->ph);
> clean:
> /* Take care to put the protocol module's owner before releasing all */
> scmi_protocol_put(proto);