Re: [PATCH 2/2] firmware: arm_scmi: Refactor protocol allocation

From: Cristian Marussi

Date: Fri Nov 27 2026 - 08:56:14 EST


On Tue, Nov 24, 2026 at 02:50:15PM -0800, Jonathan Cameron wrote:
> On Tue, 24 Nov 2026 18:51:11 +0000
> Cristian Marussi <cristian.marussi@xxxxxxx> wrote:
>
> > Simplify protocol initialization and finalization using cleanup handlers.
> > Relocate the protocol put operations out of the setup and cleanup code so
> > as to be executed strictly after the protocol devres groups have been
> > fully released.
> >
> > Signed-off-by: Cristian Marussi <cristian.marussi@xxxxxxx>
>
> Lol. I should have read on! Nice that you have found the time to look at this.
>
> > ---
> > drivers/firmware/arm_scmi/driver.c | 53 +++++++++++++-----------------
> > 1 file changed, 22 insertions(+), 31 deletions(-)
> >
> > diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> > index 2c4424aa0d37..199f0a189432 100644
> > --- a/drivers/firmware/arm_scmi/driver.c
> > +++ b/drivers/firmware/arm_scmi/driver.c
> > @@ -2256,24 +2256,21 @@ static void scmi_protocol_version_initialize(struct device *dev,
> > *
> > * Context: Assumes to be called with @protocols_mtx already acquired.
> > * Return: A reference to a freshly allocated and initialized protocol instance
> > - * or ERR_PTR on failure. On failure the @proto reference is at first
> > - * put using @scmi_protocol_put() before releasing all the devres group.
> > + * or ERR_PTR on failure.
> > */
> > static struct scmi_protocol_instance *
> > scmi_alloc_init_protocol_instance(struct scmi_info *info,
> > const struct scmi_protocol *proto)
> > {
> > + const struct scmi_handle *handle = &info->handle;
> > + struct scmi_protocol_instance *pi;
> > int ret = -ENOMEM;
> > void *gid;
> > - struct scmi_protocol_instance *pi;
> > - const struct scmi_handle *handle = &info->handle;
> >
> > /* Protocol specific devres group */
> > gid = devres_open_group(handle->dev, NULL, GFP_KERNEL);
> > - if (!gid) {
> > - scmi_protocol_put(proto);
> > - goto out;
> > - }
> > + if (!gid)
> > + return ERR_PTR(ret);
> >
> > pi = devm_kzalloc_obj(handle->dev, *pi);
> > if (!pi)
> > @@ -2328,10 +2325,7 @@ scmi_alloc_init_protocol_instance(struct scmi_info *info,
> > 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);
> > devres_release_group(handle->dev, gid);
> > -out:
> > return ERR_PTR(ret);
> > }
> Better though the devres group approach works best in my view when it's a wrapper
> around a helper.
>
> gid = dev_res_open_group(handle->dev, NULL, GFP_KERNEL);
> pi = __scmi_alloc_init_protocol_instance();
> if (IS_ERR(pi)) {
> devres_release_group(handle->dev, gid);
> return pi;
> }
>
> devres_close_group(handlde->dev, gid);
> return pi;
>
> Though here you'd have more or less a wrapper surrounding a wrapper, so fine to
> just push this up into scmi_alloc_init_protocol_instance()
>
> Anyhow even if you leave like you have it this is a great improvement.
> Lifetimes in these calls are now a little less complex to reason about.

Yes this was definitely some ugly ancient code of mine that needed
definitely to be cleaned-up.

Thanks,
Cristian