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

Takashi Iwai <[email protected]> Thu, 06 Aug 2026 09:38:12 +0200
Newsgroups org.kernel.vger.linux-sound
Message-ID <[email protected]>
On Thu, 06 Aug 2026 01:16:10 +0200,
Mark Brown wrote:
> 
> On Wed, Aug 05, 2026 at 03:52:24PM +0200, Takashi Iwai wrote:
> > Simplify the code to manage the firmware loading with __free(firmware)
> > auto-cleanup.
> 
> >  	for (i = 0; i < WM2000_NUM_SUPPLIES; i++)
> > @@ -876,6 +875,7 @@ static int wm2000_i2c_probe(struct i2c_client *i2c)
> >  			filename = pdata->download_file;
> >  	}
> >  
> > +	const struct firmware *fw __free(firmware) = NULL;
> >  	ret = request_firmware(&fw, filename, &i2c->dev);
> >  	if (ret != 0) {
> >  		dev_err(&i2c->dev, "Failed to acquire ANC data: %d\n", ret);
> 
> Same goto issue here.

Right, and the workaround is to keep the declaration at the beginning
of the function.


thanks,

Takashi

-- 8< --
From: Takashi Iwai <[email protected]>
Subject: [PATCH v2 23/31] ASoC: wm2000: Use auto-cleanup for firmware loading

Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.

Only the code refactoring, no functional changes.

Signed-off-by: Takashi Iwai <[email protected]>
---
 sound/soc/codecs/wm2000.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c
index 897b0acac5f3..41c8cfb346c6 100644
--- a/sound/soc/codecs/wm2000.c
+++ b/sound/soc/codecs/wm2000.c
@@ -796,7 +796,7 @@ static int wm2000_i2c_probe(struct i2c_client *i2c)
 	struct wm2000_priv *wm2000;
 	struct wm2000_platform_data *pdata;
 	const char *filename;
-	const struct firmware *fw = NULL;
+	const struct firmware *fw __free(firmware) = NULL;
 	int ret, i;
 	unsigned int reg;
 	u16 id;
@@ -814,7 +814,7 @@ static int wm2000_i2c_probe(struct i2c_client *i2c)
 		ret = PTR_ERR(wm2000->regmap);
 		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
 			ret);
-		goto out;
+		return ret;
 	}
 
 	for (i = 0; i < WM2000_NUM_SUPPLIES; i++)
@@ -908,9 +908,6 @@ static int wm2000_i2c_probe(struct i2c_client *i2c)
 
 err_supplies:
 	regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies);
-
-out:
-	release_firmware(fw);
 	return ret;
 }
 
-- 
2.55.0