Re: [PATCH 31/31] ASoC: SOF: Use auto-cleanup for firmware loading

Takashi Iwai <[email protected]> Thu, 06 Aug 2026 14:06:36 +0200
Newsgroups org.kernel.vger.linux-sound
Message-ID <[email protected]>
On Thu, 06 Aug 2026 13:56:30 +0200,
Péter Ujfalusi wrote:
> 
> 
> 
> On 05/08/2026 16:52, Takashi Iwai wrote:
> > Simplify the code to manage the firmware loading with __free(firmware)
> > and __free(kfree) auto-cleanups for the firmware data and the temporary
> > string or array.
> > 
> > Only the code refactoring, no functional changes.
> > 
> > Cc: Liam Girdwood <[email protected]>
> > Cc: Peter Ujfalusi <[email protected]>
> > Cc: Bard Liao <[email protected]>
> > Cc: Daniel Baluta <[email protected]>
> > Cc: Pierre-Louis Bossart <[email protected]>
> > Cc: Vijendar Mukunda <[email protected]>
> > Signed-off-by: Takashi Iwai <[email protected]>
> > ---
> >  sound/soc/sof/fw-file-profile.c | 19 +++++++------------
> >  sound/soc/sof/topology.c        | 20 ++++++--------------
> >  2 files changed, 13 insertions(+), 26 deletions(-)
> > 
> > diff --git a/sound/soc/sof/fw-file-profile.c b/sound/soc/sof/fw-file-profile.c
> > index 76bde2e0be1d..fcd57f04ca36 100644
> > --- a/sound/soc/sof/fw-file-profile.c
> > +++ b/sound/soc/sof/fw-file-profile.c
> > @@ -16,20 +16,19 @@ static int sof_test_firmware_file(struct device *dev,
> >  				  enum sof_ipc_type *ipc_type_to_adjust)
> >  {
> >  	enum sof_ipc_type fw_ipc_type;
> > -	const struct firmware *fw;
> > -	const char *fw_filename;
> >  	const u32 *magic;
> >  	int ret;
> >  
> > -	fw_filename = kasprintf(GFP_KERNEL, "%s/%s", profile->fw_path,
> > -				profile->fw_name);
> > +	const char *fw_filename __free(kfree) =
> > +		kasprintf(GFP_KERNEL, "%s/%s", profile->fw_path,
> > +			  profile->fw_name);
> >  	if (!fw_filename)
> >  		return -ENOMEM;
> >  
> > +	const struct firmware *fw __free(firmware) = NULL;
> 
> can we keep this at the head of the function?

We can, but for the auto-cleaned stuff, it's rather recommended to put
the declaration at the position that actually starts using it.  Then
you can avoid the unnecessary handling of the auto-cleanup.

(I don't find whether it's mentioned, though; the documentation about
the auto-cleanup isn't well organized yet, unfortunately...)


thanks,

Takashi