From: Cristian Marussi <cristian.marussi@arm.com>
To: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Cc: Cristian Marussi <cristian.marussi@arm.com>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org,
sudeep.holla@kernel.org, philip.radford@arm.com
Subject: Re: [PATCH 2/2] firmware: arm_scmi: Refactor protocol allocation
Date: Fri, 27 Nov 2026 13:55:56 +0000 [thread overview]
Message-ID: <awmL7CdzcH4vmw_i@pluto> (raw)
In-Reply-To: <20261124145015.0000358e@oss.qualcomm.com>
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@arm.com> 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@arm.com>
>
> 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
prev parent reply other threads:[~2026-11-27 13:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 18:51 [PATCH 0/2] SCMI protocols fixes and refactor Cristian Marussi
2026-11-24 18:51 ` [PATCH 1/2] firmware: arm_scmi: Invoke proper protocol cleanup on failure Cristian Marussi
2026-11-24 22:43 ` Jonathan Cameron
2026-11-24 18:51 ` [PATCH 2/2] firmware: arm_scmi: Refactor protocol allocation Cristian Marussi
2026-11-24 22:50 ` Jonathan Cameron
2026-11-27 13:55 ` Cristian Marussi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awmL7CdzcH4vmw_i@pluto \
--to=cristian.marussi@arm.com \
--cc=arm-scmi@vger.kernel.org \
--cc=jonathan.cameron@oss.qualcomm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=philip.radford@arm.com \
--cc=sudeep.holla@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®