* [PATCH 01/31] ASoC: aw87390: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 02/31] ASoC: aw88081: " Takashi Iwai
` (29 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/aw87390.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/sound/soc/codecs/aw87390.c b/sound/soc/codecs/aw87390.c
index 8150670fde2d..5555c45dffcc 100644
--- a/sound/soc/codecs/aw87390.c
+++ b/sound/soc/codecs/aw87390.c
@@ -248,7 +248,7 @@ static const struct snd_kcontrol_new aw87390_controls[] = {
static int aw87390_request_firmware_file(struct aw87390 *aw87390)
{
- const struct firmware *cont = NULL;
+ const struct firmware *cont __free(firmware) = NULL;
int ret;
aw87390->aw_pa->fw_status = AW87390_DEV_FW_FAILED;
@@ -263,14 +263,11 @@ static int aw87390_request_firmware_file(struct aw87390 *aw87390)
aw87390->aw_cfg = devm_kzalloc(aw87390->aw_pa->dev,
struct_size(aw87390->aw_cfg, data, cont->size), GFP_KERNEL);
- if (!aw87390->aw_cfg) {
- release_firmware(cont);
+ if (!aw87390->aw_cfg)
return -ENOMEM;
- }
aw87390->aw_cfg->len = cont->size;
memcpy(aw87390->aw_cfg->data, cont->data, cont->size);
- release_firmware(cont);
ret = aw88395_dev_load_acf_check(aw87390->aw_pa, aw87390->aw_cfg);
if (ret) {
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 02/31] ASoC: aw88081: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
2026-08-05 13:52 ` [PATCH 01/31] ASoC: aw87390: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 03/31] ASoC: aw88166: " Takashi Iwai
` (28 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/aw88081.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/sound/soc/codecs/aw88081.c b/sound/soc/codecs/aw88081.c
index a3cc027de606..3247ba5c71b8 100644
--- a/sound/soc/codecs/aw88081.c
+++ b/sound/soc/codecs/aw88081.c
@@ -1133,7 +1133,7 @@ static int aw88081_dev_init(struct aw88081 *aw88081, struct aw_container *aw_cfg
static int aw88081_request_firmware_file(struct aw88081 *aw88081)
{
- const struct firmware *cont = NULL;
+ const struct firmware *cont __free(firmware) = NULL;
struct aw_container *aw_cfg;
int ret;
@@ -1147,17 +1147,14 @@ static int aw88081_request_firmware_file(struct aw88081 *aw88081)
AW88081_ACF_FILE, cont ? cont->size : 0);
aw_cfg = devm_kzalloc(aw88081->aw_pa->dev, struct_size(aw_cfg, data, cont->size), GFP_KERNEL);
- if (!aw_cfg) {
- release_firmware(cont);
+ if (!aw_cfg)
return -ENOMEM;
- }
+
aw_cfg->len = (int)cont->size;
memcpy(aw_cfg->data, cont->data, cont->size);
aw88081->aw_cfg = aw_cfg;
- release_firmware(cont);
-
ret = aw88395_dev_load_acf_check(aw88081->aw_pa, aw88081->aw_cfg);
if (ret)
return ret;
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 03/31] ASoC: aw88166: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
2026-08-05 13:52 ` [PATCH 01/31] ASoC: aw87390: " Takashi Iwai
2026-08-05 13:52 ` [PATCH 02/31] ASoC: aw88081: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 04/31] ASoC: aw88261: " Takashi Iwai
` (27 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/aw88166.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/sound/soc/codecs/aw88166.c b/sound/soc/codecs/aw88166.c
index b72f87f677dd..d2a138211c59 100644
--- a/sound/soc/codecs/aw88166.c
+++ b/sound/soc/codecs/aw88166.c
@@ -1570,7 +1570,7 @@ static int aw88166_dev_init(struct aw88166 *aw88166, struct aw_container *aw_cfg
static int aw88166_request_firmware_file(struct aw88166 *aw88166)
{
- const struct firmware *cont = NULL;
+ const struct firmware *cont __free(firmware) = NULL;
const char *fw_name;
int ret;
@@ -1590,13 +1590,11 @@ static int aw88166_request_firmware_file(struct aw88166 *aw88166)
aw88166->aw_cfg = devm_kzalloc(aw88166->aw_pa->dev,
struct_size(aw88166->aw_cfg, data, cont->size), GFP_KERNEL);
- if (!aw88166->aw_cfg) {
- release_firmware(cont);
+ if (!aw88166->aw_cfg)
return -ENOMEM;
- }
+
aw88166->aw_cfg->len = (int)cont->size;
memcpy(aw88166->aw_cfg->data, cont->data, cont->size);
- release_firmware(cont);
ret = aw88395_dev_load_acf_check(aw88166->aw_pa, aw88166->aw_cfg);
if (ret) {
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 04/31] ASoC: aw88261: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (2 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 03/31] ASoC: aw88166: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 05/31] ASoC: aw88395: " Takashi Iwai
` (26 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/aw88261.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/sound/soc/codecs/aw88261.c b/sound/soc/codecs/aw88261.c
index acbd7de2e40e..b8d06534bc8f 100644
--- a/sound/soc/codecs/aw88261.c
+++ b/sound/soc/codecs/aw88261.c
@@ -1149,7 +1149,7 @@ static int aw88261_dev_init(struct aw88261 *aw88261, struct aw_container *aw_cfg
static int aw88261_request_firmware_file(struct aw88261 *aw88261)
{
- const struct firmware *cont = NULL;
+ const struct firmware *cont __free(firmware) = NULL;
struct aw_container *aw_cfg;
const char *fw_name;
int ret;
@@ -1169,13 +1169,11 @@ static int aw88261_request_firmware_file(struct aw88261 *aw88261)
fw_name, cont ? cont->size : 0);
aw_cfg = devm_kzalloc(aw88261->aw_pa->dev, struct_size(aw_cfg, data, cont->size), GFP_KERNEL);
- if (!aw_cfg) {
- release_firmware(cont);
+ if (!aw_cfg)
return -ENOMEM;
- }
+
aw_cfg->len = (int)cont->size;
memcpy(aw_cfg->data, cont->data, cont->size);
- release_firmware(cont);
aw88261->aw_cfg = aw_cfg;
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 05/31] ASoC: aw88395: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (3 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 04/31] ASoC: aw88261: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 06/31] ASoC: aw88399: " Takashi Iwai
` (25 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/aw88395/aw88395.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/sound/soc/codecs/aw88395/aw88395.c b/sound/soc/codecs/aw88395/aw88395.c
index e9ff2c79ac15..2f4108624d13 100644
--- a/sound/soc/codecs/aw88395/aw88395.c
+++ b/sound/soc/codecs/aw88395/aw88395.c
@@ -457,7 +457,7 @@ static void aw88395_hw_reset(struct aw88395 *aw88395)
static int aw88395_request_firmware_file(struct aw88395 *aw88395)
{
- const struct firmware *cont = NULL;
+ const struct firmware *cont __free(firmware) = NULL;
struct aw_container *aw_cfg;
int ret;
@@ -473,13 +473,11 @@ static int aw88395_request_firmware_file(struct aw88395 *aw88395)
AW88395_ACF_FILE, cont ? cont->size : 0);
aw_cfg = devm_kzalloc(aw88395->aw_pa->dev, struct_size(aw_cfg, data, cont->size), GFP_KERNEL);
- if (!aw_cfg) {
- release_firmware(cont);
+ if (!aw_cfg)
return -ENOMEM;
- }
+
aw_cfg->len = (int)cont->size;
memcpy(aw_cfg->data, cont->data, cont->size);
- release_firmware(cont);
aw88395->aw_cfg = aw_cfg;
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 06/31] ASoC: aw88399: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (4 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 05/31] ASoC: aw88395: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 07/31] ASoC: fs-amp-lib: " Takashi Iwai
` (24 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/aw88399-lib.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/sound/soc/codecs/aw88399-lib.c b/sound/soc/codecs/aw88399-lib.c
index 5c7982891def..809c2faa0c0c 100644
--- a/sound/soc/codecs/aw88399-lib.c
+++ b/sound/soc/codecs/aw88399-lib.c
@@ -1282,7 +1282,7 @@ static int aw88399_dev_init(struct aw88399 *aw88399, struct aw_container *aw_cfg
int aw88399_request_firmware_file(struct aw88399 *aw88399)
{
- const struct firmware *cont = NULL;
+ const struct firmware *cont __free(firmware) = NULL;
int ret;
aw88399->aw_pa->fw_status = AW88399_DEV_FW_FAILED;
@@ -1298,13 +1298,11 @@ int aw88399_request_firmware_file(struct aw88399 *aw88399)
aw88399->aw_cfg = devm_kzalloc(aw88399->aw_pa->dev,
struct_size(aw88399->aw_cfg, data, cont->size), GFP_KERNEL);
- if (!aw88399->aw_cfg) {
- release_firmware(cont);
+ if (!aw88399->aw_cfg)
return -ENOMEM;
- }
+
aw88399->aw_cfg->len = (int)cont->size;
memcpy(aw88399->aw_cfg->data, cont->data, cont->size);
- release_firmware(cont);
ret = aw88395_dev_load_acf_check(aw88399->aw_pa, aw88399->aw_cfg);
if (ret) {
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 07/31] ASoC: fs-amp-lib: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (5 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 06/31] ASoC: aw88399: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 08/31] ASoC: hdac_hda: " Takashi Iwai
` (23 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Nick Li
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Nick Li <nick.li@foursemi.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/fs-amp-lib.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/soc/codecs/fs-amp-lib.c b/sound/soc/codecs/fs-amp-lib.c
index c8f56617e370..a562c72fc524 100644
--- a/sound/soc/codecs/fs-amp-lib.c
+++ b/sound/soc/codecs/fs-amp-lib.c
@@ -221,7 +221,7 @@ static void fs_print_firmware_info(struct fs_amp_lib *amp_lib)
int fs_amp_load_firmware(struct fs_amp_lib *amp_lib, const char *name)
{
- const struct firmware *cont;
+ const struct firmware *cont __free(firmware) = NULL;
struct fs_fwm_header *hdr;
int ret;
@@ -237,7 +237,6 @@ int fs_amp_load_firmware(struct fs_amp_lib *amp_lib, const char *name)
dev_info(amp_lib->dev, "Loading %s - size: %zu\n", name, cont->size);
hdr = devm_kmemdup(amp_lib->dev, cont->data, cont->size, GFP_KERNEL);
- release_firmware(cont);
if (!hdr)
return -ENOMEM;
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 08/31] ASoC: hdac_hda: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (6 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 07/31] ASoC: fs-amp-lib: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 09/31] ASoC: max98390: " Takashi Iwai
` (22 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/hdac_hda.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/soc/codecs/hdac_hda.c b/sound/soc/codecs/hdac_hda.c
index 1ab5f8a26e03..1c06fdbf0e71 100644
--- a/sound/soc/codecs/hdac_hda.c
+++ b/sound/soc/codecs/hdac_hda.c
@@ -437,7 +437,7 @@ static int hdac_hda_codec_probe(struct snd_soc_component *component)
#ifdef CONFIG_SND_HDA_PATCH_LOADER
if (loadable_patch[hda_pvt->dev_index] && *loadable_patch[hda_pvt->dev_index]) {
- const struct firmware *fw;
+ const struct firmware *fw __free(firmware) = NULL;
dev_info(&hdev->dev, "Applying patch firmware '%s'\n",
loadable_patch[hda_pvt->dev_index]);
@@ -451,7 +451,6 @@ static int hdac_hda_codec_probe(struct snd_soc_component *component)
dev_err(&hdev->dev, "%s: failed to load hda patch %d\n", __func__, ret);
goto error_no_pm;
}
- release_firmware(fw);
}
}
#endif
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 09/31] ASoC: max98390: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (7 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 08/31] ASoC: hdac_hda: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 10/31] ASoC: ntpfw: " Takashi Iwai
` (21 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/max98390.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/sound/soc/codecs/max98390.c b/sound/soc/codecs/max98390.c
index 66309e87fdbd..2295fc057c71 100644
--- a/sound/soc/codecs/max98390.c
+++ b/sound/soc/codecs/max98390.c
@@ -788,7 +788,6 @@ static int max98390_dsm_init(struct snd_soc_component *component)
const char *vendor, *product;
struct max98390_priv *max98390 =
snd_soc_component_get_drvdata(component);
- const struct firmware *fw;
char *dsm_param;
vendor = dmi_get_system_info(DMI_SYS_VENDOR);
@@ -805,6 +804,8 @@ static int max98390_dsm_init(struct snd_soc_component *component)
snprintf(filename, sizeof(filename), "%s",
max98390->dsm_param_name);
}
+
+ const struct firmware *fw __free(firmware) = NULL;
ret = request_firmware(&fw, filename, component->dev);
if (ret) {
ret = request_firmware(&fw, "dsm_param.bin", component->dev);
@@ -812,7 +813,7 @@ static int max98390_dsm_init(struct snd_soc_component *component)
ret = request_firmware(&fw, "dsmparam.bin",
component->dev);
if (ret)
- goto err;
+ return ret;
}
}
@@ -822,8 +823,7 @@ static int max98390_dsm_init(struct snd_soc_component *component)
if (fw->size < MAX98390_DSM_PARAM_MIN_SIZE) {
dev_err(component->dev,
"param fw is invalid.\n");
- ret = -EINVAL;
- goto err_alloc;
+ return -EINVAL;
}
dsm_param = (char *)fw->data;
param_start_addr = (dsm_param[0] & 0xff) | (dsm_param[1] & 0xff) << 8;
@@ -833,8 +833,7 @@ static int max98390_dsm_init(struct snd_soc_component *component)
fw->size < param_size + MAX98390_DSM_PAYLOAD_OFFSET) {
dev_err(component->dev,
"param fw is invalid.\n");
- ret = -EINVAL;
- goto err_alloc;
+ return -EINVAL;
}
regmap_write(max98390->regmap, MAX98390_R203A_AMP_EN, 0x80);
dsm_param += MAX98390_DSM_PAYLOAD_OFFSET;
@@ -842,10 +841,7 @@ static int max98390_dsm_init(struct snd_soc_component *component)
dsm_param, param_size);
regmap_write(max98390->regmap, MAX98390_R23E1_DSP_GLOBAL_EN, 0x01);
-err_alloc:
- release_firmware(fw);
-err:
- return ret;
+ return 0;
}
static void max98390_init_regs(struct snd_soc_component *component)
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 10/31] ASoC: ntpfw: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (8 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 09/31] ASoC: max98390: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 11/31] ASoC: pcm6240: " Takashi Iwai
` (20 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/ntpfw.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/sound/soc/codecs/ntpfw.c b/sound/soc/codecs/ntpfw.c
index 5ced2e966ab7..b6443e24ae8e 100644
--- a/sound/soc/codecs/ntpfw.c
+++ b/sound/soc/codecs/ntpfw.c
@@ -89,7 +89,7 @@ int ntpfw_load(struct i2c_client *i2c, const char *name, u32 magic)
{
struct device *dev = &i2c->dev;
const struct ntpfw_chunk *chunk;
- const struct firmware *fw;
+ const struct firmware *fw __free(firmware) = NULL;
const u8 *data;
size_t leftover;
int ret;
@@ -101,10 +101,8 @@ int ntpfw_load(struct i2c_client *i2c, const char *name, u32 magic)
return ret;
}
- if (!ntpfw_verify(dev, fw->data, fw->size, magic)) {
- ret = -EINVAL;
- goto done;
- }
+ if (!ntpfw_verify(dev, fw->data, fw->size, magic))
+ return -EINVAL;
data = fw->data + sizeof(struct ntpfw_header);
leftover = fw->size - sizeof(struct ntpfw_header);
@@ -112,23 +110,18 @@ int ntpfw_load(struct i2c_client *i2c, const char *name, u32 magic)
while (leftover) {
chunk = (struct ntpfw_chunk *)data;
- if (!ntpfw_verify_chunk(dev, chunk, leftover)) {
- ret = -EINVAL;
- goto done;
- }
+ if (!ntpfw_verify_chunk(dev, chunk, leftover))
+ return -EINVAL;
ret = ntpfw_send_chunk(i2c, chunk);
if (ret)
- goto done;
+ return ret;
data += be16_to_cpu(chunk->length) + sizeof(*chunk);
leftover -= be16_to_cpu(chunk->length) + sizeof(*chunk);
}
-done:
- release_firmware(fw);
-
- return ret;
+ return 0;
}
EXPORT_SYMBOL_GPL(ntpfw_load);
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 11/31] ASoC: pcm6240: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (9 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 10/31] ASoC: ntpfw: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 16:47 ` Herve Codina
2026-08-05 13:52 ` [PATCH 12/31] ASoC: peb2466: " Takashi Iwai
` (19 subsequent siblings)
30 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Herve Codina
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Since the firmware release is cleaned up automatically, we can convert
the mutex call with guard() gracefully, too.
Only the code refactoring, no functional changes.
Cc: Herve Codina <herve.codina@bootlin.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/pcm6240.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/sound/soc/codecs/pcm6240.c b/sound/soc/codecs/pcm6240.c
index a2b66eae6ac4..db85ae2f8aed 100644
--- a/sound/soc/codecs/pcm6240.c
+++ b/sound/soc/codecs/pcm6240.c
@@ -1577,10 +1577,10 @@ static int pcmdevice_comp_probe(struct snd_soc_component *comp)
{
struct pcmdevice_priv *pcm_dev = snd_soc_component_get_drvdata(comp);
struct i2c_adapter *adap = pcm_dev->client->adapter;
- const struct firmware *fw_entry = NULL;
+ const struct firmware *fw_entry __free(firmware) = NULL;
int ret, i, j;
- mutex_lock(&pcm_dev->codec_lock);
+ guard(mutex)(&pcm_dev->codec_lock);
pcm_dev->component = comp;
@@ -1588,7 +1588,7 @@ static int pcmdevice_comp_probe(struct snd_soc_component *comp)
for (j = 0; j < 2; j++) {
ret = pcmdev_gain_ctrl_add(pcm_dev, i, j);
if (ret < 0)
- goto out;
+ return ret;
}
}
@@ -1621,21 +1621,17 @@ static int pcmdevice_comp_probe(struct snd_soc_component *comp)
if (ret) {
dev_err(pcm_dev->dev, "%s: request %s err = %d\n", __func__,
pcm_dev->bin_name, ret);
- goto out;
+ return ret;
}
ret = pcmdev_regbin_ready(fw_entry, pcm_dev);
if (ret) {
dev_err(pcm_dev->dev, "%s: %s parse err = %d\n", __func__,
pcm_dev->bin_name, ret);
- goto out;
+ return ret;
}
- ret = pcmdev_profile_ctrl_add(pcm_dev);
-out:
- release_firmware(fw_entry);
- mutex_unlock(&pcm_dev->codec_lock);
- return ret;
+ return pcmdev_profile_ctrl_add(pcm_dev);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* Re: [PATCH 11/31] ASoC: pcm6240: Use auto-cleanup for firmware loading
2026-08-05 13:52 ` [PATCH 11/31] ASoC: pcm6240: " Takashi Iwai
@ 2026-08-05 16:47 ` Herve Codina
2026-08-06 6:16 ` Takashi Iwai
0 siblings, 1 reply; 49+ messages in thread
From: Herve Codina @ 2026-08-05 16:47 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Mark Brown, linux-sound
Hi Takashi,
On Wed, 5 Aug 2026 15:52:12 +0200
Takashi Iwai <tiwai@suse.de> wrote:
> Simplify the code to manage the firmware loading with __free(firmware)
> auto-cleanup.
>
> Since the firmware release is cleaned up automatically, we can convert
> the mutex call with guard() gracefully, too.
>
> Only the code refactoring, no functional changes.
>
> Cc: Herve Codina <herve.codina@bootlin.com>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
> sound/soc/codecs/pcm6240.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
Hum, I am in Cc but I think it is the wrong commit.
I would expect to be in Cc of modification related to the peb2466 codec.
Anyway, for this one, modification looks good to me.
Reviewed-by: Herve Codina <herve.codina@bootlin.com>
Also I will retrieve the peb2466 patch (patch 12/31) directly from lore
and reply.
Best regards,
Hervé
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH 11/31] ASoC: pcm6240: Use auto-cleanup for firmware loading
2026-08-05 16:47 ` Herve Codina
@ 2026-08-06 6:16 ` Takashi Iwai
0 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-06 6:16 UTC (permalink / raw)
To: Herve Codina; +Cc: Takashi Iwai, Mark Brown, linux-sound
On Wed, 05 Aug 2026 18:47:05 +0200,
Herve Codina wrote:
>
> Hi Takashi,
>
> On Wed, 5 Aug 2026 15:52:12 +0200
> Takashi Iwai <tiwai@suse.de> wrote:
>
> > Simplify the code to manage the firmware loading with __free(firmware)
> > auto-cleanup.
> >
> > Since the firmware release is cleaned up automatically, we can convert
> > the mutex call with guard() gracefully, too.
> >
> > Only the code refactoring, no functional changes.
> >
> > Cc: Herve Codina <herve.codina@bootlin.com>
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> > sound/soc/codecs/pcm6240.c | 16 ++++++----------
> > 1 file changed, 6 insertions(+), 10 deletions(-)
> >
>
> Hum, I am in Cc but I think it is the wrong commit.
>
> I would expect to be in Cc of modification related to the peb2466 codec.
>
> Anyway, for this one, modification looks good to me.
>
> Reviewed-by: Herve Codina <herve.codina@bootlin.com>
>
> Also I will retrieve the peb2466 patch (patch 12/31) directly from lore
> and reply.
My bad, it was a mistake due to the manual edit.
(Do we have any automatic mechanism to add corresponding Cc's?)
thanks,
Takashi
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH 12/31] ASoC: peb2466: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (10 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 11/31] ASoC: pcm6240: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 16:50 ` Herve Codina
2026-08-05 13:52 ` [PATCH 13/31] ASoC: rt1320-sdw: " Takashi Iwai
` (18 subsequent siblings)
30 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/peb2466.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/sound/soc/codecs/peb2466.c b/sound/soc/codecs/peb2466.c
index 5a1ed02abb84..f1ded68c2d75 100644
--- a/sound/soc/codecs/peb2466.c
+++ b/sound/soc/codecs/peb2466.c
@@ -1538,17 +1538,14 @@ static int peb2466_fw_parse(struct snd_soc_component *component,
static int peb2466_load_coeffs(struct snd_soc_component *component, const char *fw_name)
{
- const struct firmware *fw;
+ const struct firmware *fw __free(firmware) = NULL;
int ret;
ret = request_firmware(&fw, fw_name, component->dev);
if (ret)
return ret;
- ret = peb2466_fw_parse(component, fw->data, fw->size);
- release_firmware(fw);
-
- return ret;
+ return peb2466_fw_parse(component, fw->data, fw->size);
}
static int peb2466_component_probe(struct snd_soc_component *component)
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* Re: [PATCH 12/31] ASoC: peb2466: Use auto-cleanup for firmware loading
2026-08-05 13:52 ` [PATCH 12/31] ASoC: peb2466: " Takashi Iwai
@ 2026-08-05 16:50 ` Herve Codina
0 siblings, 0 replies; 49+ messages in thread
From: Herve Codina @ 2026-08-05 16:50 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Mark Brown, linux-sound
Hi Takashi,
On Wed, 5 Aug 2026 15:52:13 +0200
Takashi Iwai <tiwai@suse.de> wrote:
> 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 <tiwai@suse.de>
> ---
> sound/soc/codecs/peb2466.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
LGTM.
Reviewed-by: Herve Codina <herve.codina@bootlin.com>
Best regards,
Hervé
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH 13/31] ASoC: rt1320-sdw: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (11 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 12/31] ASoC: peb2466: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 22:56 ` Mark Brown
2026-08-05 13:52 ` [PATCH 14/31] ASoC: rt5575: " Takashi Iwai
` (17 subsequent siblings)
30 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Oder Chiou
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/rt1320-sdw.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c
index 3a5eebcfefdd..0af4bfc875e5 100644
--- a/sound/soc/codecs/rt1320-sdw.c
+++ b/sound/soc/codecs/rt1320-sdw.c
@@ -1786,7 +1786,6 @@ static int rt1320_r0_cali_put(struct snd_kcontrol *kcontrol,
static void rt1320_load_mcu_patch(struct rt1320_sdw_priv *rt1320)
{
struct sdw_slave *slave = rt1320->sdw_slave;
- const struct firmware *patch;
const char *filename;
unsigned int addr, val, min_addr, max_addr;
const unsigned char *ptr;
@@ -1815,6 +1814,7 @@ static void rt1320_load_mcu_patch(struct rt1320_sdw_priv *rt1320)
}
/* load the patch code here */
+ const struct firmware *patch __free(firmware) = NULL;
ret = request_firmware(&patch, filename, &slave->dev);
if (ret) {
dev_err(&slave->dev, "%s: Failed to load %s firmware", __func__, filename);
@@ -1840,17 +1840,15 @@ static void rt1320_load_mcu_patch(struct rt1320_sdw_priv *rt1320)
if (addr > max_addr || addr < min_addr) {
dev_err(&slave->dev, "%s: the address 0x%x is wrong", __func__, addr);
- goto _exit_;
+ return;
}
if (val > 0xff) {
dev_err(&slave->dev, "%s: the value 0x%x is wrong", __func__, val);
- goto _exit_;
+ return;
}
regmap_write(rt1320->regmap, addr, val);
}
}
-_exit_:
- release_firmware(patch);
}
}
@@ -1924,7 +1922,6 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320)
struct device *dev = &rt1320->sdw_slave->dev;
static const char func_tag[] = "FUNC";
static const char xu_tag[] = "XU";
- const struct firmware *rae_fw = NULL;
unsigned int fw_offset;
unsigned char *fw_data;
unsigned char *param_data;
@@ -1960,6 +1957,7 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320)
RT1320_SDCA_CTL_REQ_POWER_STATE, 0), 0x00);
rt1320_pde_transition_delay(rt1320, FUNC_NUM_AMP, RT1320_SDCA_ENT_PDE23, 0x00);
+ const struct firmware *rae_fw __free(firmware) = NULL;
request_firmware(&rae_fw, rae_filename, dev);
if (rae_fw) {
@@ -1977,7 +1975,6 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320)
}
if (!retry && !(value & 0x40)) {
dev_err(dev, "%s: RAE is not ready to load\n", __func__);
- release_firmware(rae_fw);
return -ETIMEDOUT;
}
break;
@@ -1998,7 +1995,6 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320)
}
if (!retry && !(value & 0x40)) {
dev_err(dev, "%s: RAE is not ready to load\n", __func__);
- release_firmware(rae_fw);
return -ETIMEDOUT;
}
break;
@@ -2057,7 +2053,6 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320)
}
regcache_cache_bypass(rt1320->regmap, false);
- release_firmware(rae_fw);
} else {
dev_err(dev, "%s: Failed to load %s firmware\n", __func__, rae_filename);
@@ -2124,7 +2119,6 @@ struct rt1320_dspfwheader {
struct rt1320_dspfwheader *fwheader;
struct rt1320_imageinfo *ptr_img;
struct sdw_bpt_section sec[10];
- const struct firmware *fw = NULL;
unsigned char *fw_data;
bool dev_fw_match = false;
static const char hdr_sig[] = "AFX";
@@ -2170,6 +2164,7 @@ struct rt1320_dspfwheader {
goto _exit_;
}
+ const struct firmware *fw __free(firmware) = NULL;
request_firmware(&fw, filename, dev);
if (fw) {
fwheader = (struct rt1320_dspfwheader *)fw->data;
@@ -2178,7 +2173,6 @@ struct rt1320_dspfwheader {
if (fwheader->sync != 0x0a1c5679) {
dev_err(dev, "%s: FW sync error\n", __func__);
- release_firmware(fw);
goto _exit_;
}
@@ -2256,7 +2250,6 @@ struct rt1320_dspfwheader {
}
regcache_cache_bypass(rt1320->regmap, false);
- release_firmware(fw);
if (!dev_fw_match) {
dev_err(dev, "%s: FW file doesn't match to device\n", __func__);
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* Re: [PATCH 13/31] ASoC: rt1320-sdw: Use auto-cleanup for firmware loading
2026-08-05 13:52 ` [PATCH 13/31] ASoC: rt1320-sdw: " Takashi Iwai
@ 2026-08-05 22:56 ` Mark Brown
2026-08-06 7:37 ` Takashi Iwai
0 siblings, 1 reply; 49+ messages in thread
From: Mark Brown @ 2026-08-05 22:56 UTC (permalink / raw)
To: Takashi Iwai; +Cc: linux-sound, Oder Chiou
[-- Attachment #1: Type: text/plain, Size: 643 bytes --]
On Wed, Aug 05, 2026 at 03:52:14PM +0200, Takashi Iwai wrote:
> Simplify the code to manage the firmware loading with __free(firmware)
> auto-cleanup.
>
> Only the code refactoring, no functional changes.
> @@ -2170,6 +2164,7 @@ struct rt1320_dspfwheader {
> goto _exit_;
> }
>
> + const struct firmware *fw __free(firmware) = NULL;
> request_firmware(&fw, filename, dev);
> if (fw) {
> fwheader = (struct rt1320_dspfwheader *)fw->data;
There's a goto further up that jumps over this which clang warns about,
this will break the build. Landmines like that are why cleanup.h warns
about mixing it with goto.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 49+ messages in thread* Re: [PATCH 13/31] ASoC: rt1320-sdw: Use auto-cleanup for firmware loading
2026-08-05 22:56 ` Mark Brown
@ 2026-08-06 7:37 ` Takashi Iwai
2026-08-06 11:52 ` Mark Brown
0 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-06 7:37 UTC (permalink / raw)
To: Mark Brown; +Cc: Takashi Iwai, linux-sound, Oder Chiou
On Thu, 06 Aug 2026 00:56:23 +0200,
Mark Brown wrote:
>
> On Wed, Aug 05, 2026 at 03:52:14PM +0200, Takashi Iwai wrote:
> > Simplify the code to manage the firmware loading with __free(firmware)
> > auto-cleanup.
> >
> > Only the code refactoring, no functional changes.
>
> > @@ -2170,6 +2164,7 @@ struct rt1320_dspfwheader {
> > goto _exit_;
> > }
> >
> > + const struct firmware *fw __free(firmware) = NULL;
> > request_firmware(&fw, filename, dev);
> > if (fw) {
> > fwheader = (struct rt1320_dspfwheader *)fw->data;
>
> There's a goto further up that jumps over this which clang warns about,
> this will break the build. Landmines like that are why cleanup.h warns
> about mixing it with goto.
That's an issue because I moved the declaration of the variable fw;
if it's left at the beginning of the function as it was, it should
work fine, like the patch below. The same applied to the error for
wm2000.
If this is OK, I'll submit v2 series with the fixes for rt1320-sdw and
wm2000.
thanks,
Takashi
-- 8< --
From: Takashi Iwai <tiwai@suse.de>
Subject: [PATCH v2 13/31] ASoC: rt1320-sdw: 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.
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
v1->v2: keep the firmware declaration at the beginning of the function
to co-live with gotos
sound/soc/codecs/rt1320-sdw.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c
index 3a5eebcfefdd..8d2d6697a502 100644
--- a/sound/soc/codecs/rt1320-sdw.c
+++ b/sound/soc/codecs/rt1320-sdw.c
@@ -1786,7 +1786,7 @@ static int rt1320_r0_cali_put(struct snd_kcontrol *kcontrol,
static void rt1320_load_mcu_patch(struct rt1320_sdw_priv *rt1320)
{
struct sdw_slave *slave = rt1320->sdw_slave;
- const struct firmware *patch;
+ const struct firmware *patch __free(firmware) = NULL;
const char *filename;
unsigned int addr, val, min_addr, max_addr;
const unsigned char *ptr;
@@ -1840,17 +1840,15 @@ static void rt1320_load_mcu_patch(struct rt1320_sdw_priv *rt1320)
if (addr > max_addr || addr < min_addr) {
dev_err(&slave->dev, "%s: the address 0x%x is wrong", __func__, addr);
- goto _exit_;
+ return;
}
if (val > 0xff) {
dev_err(&slave->dev, "%s: the value 0x%x is wrong", __func__, val);
- goto _exit_;
+ return;
}
regmap_write(rt1320->regmap, addr, val);
}
}
-_exit_:
- release_firmware(patch);
}
}
@@ -1924,7 +1922,7 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320)
struct device *dev = &rt1320->sdw_slave->dev;
static const char func_tag[] = "FUNC";
static const char xu_tag[] = "XU";
- const struct firmware *rae_fw = NULL;
+ const struct firmware *rae_fw __free(firmware) = NULL;
unsigned int fw_offset;
unsigned char *fw_data;
unsigned char *param_data;
@@ -1977,7 +1975,6 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320)
}
if (!retry && !(value & 0x40)) {
dev_err(dev, "%s: RAE is not ready to load\n", __func__);
- release_firmware(rae_fw);
return -ETIMEDOUT;
}
break;
@@ -1998,7 +1995,6 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320)
}
if (!retry && !(value & 0x40)) {
dev_err(dev, "%s: RAE is not ready to load\n", __func__);
- release_firmware(rae_fw);
return -ETIMEDOUT;
}
break;
@@ -2057,7 +2053,6 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320)
}
regcache_cache_bypass(rt1320->regmap, false);
- release_firmware(rae_fw);
} else {
dev_err(dev, "%s: Failed to load %s firmware\n", __func__, rae_filename);
@@ -2124,7 +2119,7 @@ struct rt1320_dspfwheader {
struct rt1320_dspfwheader *fwheader;
struct rt1320_imageinfo *ptr_img;
struct sdw_bpt_section sec[10];
- const struct firmware *fw = NULL;
+ const struct firmware *fw __free(firmware) = NULL;
unsigned char *fw_data;
bool dev_fw_match = false;
static const char hdr_sig[] = "AFX";
@@ -2178,7 +2173,6 @@ struct rt1320_dspfwheader {
if (fwheader->sync != 0x0a1c5679) {
dev_err(dev, "%s: FW sync error\n", __func__);
- release_firmware(fw);
goto _exit_;
}
@@ -2256,7 +2250,6 @@ struct rt1320_dspfwheader {
}
regcache_cache_bypass(rt1320->regmap, false);
- release_firmware(fw);
if (!dev_fw_match) {
dev_err(dev, "%s: FW file doesn't match to device\n", __func__);
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* Re: [PATCH 13/31] ASoC: rt1320-sdw: Use auto-cleanup for firmware loading
2026-08-06 7:37 ` Takashi Iwai
@ 2026-08-06 11:52 ` Mark Brown
2026-08-06 13:48 ` Takashi Iwai
0 siblings, 1 reply; 49+ messages in thread
From: Mark Brown @ 2026-08-06 11:52 UTC (permalink / raw)
To: Takashi Iwai; +Cc: linux-sound, Oder Chiou
[-- Attachment #1: Type: text/plain, Size: 646 bytes --]
On Thu, Aug 06, 2026 at 09:37:14AM +0200, Takashi Iwai wrote:
> Mark Brown wrote:
> > There's a goto further up that jumps over this which clang warns about,
> > this will break the build. Landmines like that are why cleanup.h warns
> > about mixing it with goto.
> That's an issue because I moved the declaration of the variable fw;
> if it's left at the beginning of the function as it was, it should
> work fine, like the patch below. The same applied to the error for
> wm2000.
Yes, it's fine when the declaration is at the beginning IIRC (though not
ideal stylistically) - the warning is generated when a goto jumps over a
declaration.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH 13/31] ASoC: rt1320-sdw: Use auto-cleanup for firmware loading
2026-08-06 11:52 ` Mark Brown
@ 2026-08-06 13:48 ` Takashi Iwai
0 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-06 13:48 UTC (permalink / raw)
To: Mark Brown; +Cc: Takashi Iwai, linux-sound, Oder Chiou
On Thu, 06 Aug 2026 13:52:48 +0200,
Mark Brown wrote:
>
> On Thu, Aug 06, 2026 at 09:37:14AM +0200, Takashi Iwai wrote:
> > Mark Brown wrote:
>
> > > There's a goto further up that jumps over this which clang warns about,
> > > this will break the build. Landmines like that are why cleanup.h warns
> > > about mixing it with goto.
>
> > That's an issue because I moved the declaration of the variable fw;
> > if it's left at the beginning of the function as it was, it should
> > work fine, like the patch below. The same applied to the error for
> > wm2000.
>
> Yes, it's fine when the declaration is at the beginning IIRC (though not
> ideal stylistically) - the warning is generated when a goto jumps over a
> declaration.
OK, I'm going to submit v2 series.
thanks,
Takashi
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH 14/31] ASoC: rt5575: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (12 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 13/31] ASoC: rt1320-sdw: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 15/31] ASoC: rt5677: " Takashi Iwai
` (16 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Oder Chiou
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/rt5575-spi.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/soc/codecs/rt5575-spi.c b/sound/soc/codecs/rt5575-spi.c
index d5b3a57c8866..750f1f7169e6 100644
--- a/sound/soc/codecs/rt5575-spi.c
+++ b/sound/soc/codecs/rt5575-spi.c
@@ -93,7 +93,6 @@ static void rt5575_spi_burst_write(struct spi_device *spi, u32 addr, const u8 *t
int rt5575_spi_fw_load(struct spi_device *spi)
{
struct device *dev = &spi->dev;
- const struct firmware *firmware;
int i, ret;
static const char * const fw_path[] = {
"realtek/rt5575/rt5575_fw1.bin",
@@ -104,6 +103,7 @@ int rt5575_spi_fw_load(struct spi_device *spi)
static const u32 fw_addr[] = { 0x5f400000, 0x5f600000, 0x5f7fe000, 0x5f7ff000 };
for (i = 0; i < ARRAY_SIZE(fw_addr); i++) {
+ const struct firmware *firmware __free(firmware) = NULL;
ret = request_firmware(&firmware, fw_path[i], dev);
if (ret) {
dev_err(dev, "Request firmware failure: %d\n", ret);
@@ -111,7 +111,6 @@ int rt5575_spi_fw_load(struct spi_device *spi)
}
rt5575_spi_burst_write(spi, fw_addr[i], firmware->data, firmware->size);
- release_firmware(firmware);
}
return 0;
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 15/31] ASoC: rt5677: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (13 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 14/31] ASoC: rt5575: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 16/31] ASoC: rt722-sdca: " Takashi Iwai
` (15 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Oder Chiou
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/rt5677.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c
index 3e4d1dbce740..4757017cc83d 100644
--- a/sound/soc/codecs/rt5677.c
+++ b/sound/soc/codecs/rt5677.c
@@ -849,11 +849,11 @@ static int rt5677_parse_and_load_dsp(struct rt5677_priv *rt5677, const u8 *buf,
static int rt5677_load_dsp_from_file(struct rt5677_priv *rt5677)
{
- const struct firmware *fwp;
struct device *dev = rt5677->component->dev;
- int ret = 0;
+ int ret;
/* Load dsp firmware from rt5677_elf_vad file */
+ const struct firmware *fwp __free(firmware) = NULL;
ret = request_firmware(&fwp, "rt5677_elf_vad", dev);
if (ret) {
dev_err(dev, "Request rt5677_elf_vad failed %d\n", ret);
@@ -861,9 +861,7 @@ static int rt5677_load_dsp_from_file(struct rt5677_priv *rt5677)
}
dev_info(dev, "Requested rt5677_elf_vad (%zu)\n", fwp->size);
- ret = rt5677_parse_and_load_dsp(rt5677, fwp->data, fwp->size);
- release_firmware(fwp);
- return ret;
+ return rt5677_parse_and_load_dsp(rt5677, fwp->data, fwp->size);
}
static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on)
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 16/31] ASoC: rt722-sdca: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (14 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 15/31] ASoC: rt5677: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 17/31] ASoC: sigmadsp: se " Takashi Iwai
` (14 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Oder Chiou
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup, as well as the firmware file name being released with
__free(kfree).
Only the code refactoring, no functional changes.
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/rt722-sdca.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/sound/soc/codecs/rt722-sdca.c b/sound/soc/codecs/rt722-sdca.c
index 27bb0eb1ece7..4cbe9e909585 100644
--- a/sound/soc/codecs/rt722-sdca.c
+++ b/sound/soc/codecs/rt722-sdca.c
@@ -352,8 +352,6 @@ static int rt722_cae_load(struct rt722_sdca_priv *rt722)
static const char func_tag[] = "FUNC";
static const char xu_tag[] = "XU";
const char *dmi_vendor, *dmi_product, *dmi_sku;
- char *cae_filename;
- const struct firmware *cae_fw = NULL;
unsigned int cae_st_spk, cae_st_hp, cae_st_mic;
unsigned int func, value;
unsigned int combined_val;
@@ -385,7 +383,8 @@ static int rt722_cae_load(struct rt722_sdca_priv *rt722)
space = strchr(dmi_sku, ' ');
s_len = space ? space - dmi_sku : strlen(dmi_sku);
- cae_filename = kasprintf(GFP_KERNEL,
+ char *cae_filename __free(kfree) =
+ kasprintf(GFP_KERNEL,
"realtek/rt722/rt722_RAE_%.*s_%.*s_%.*s.dat",
v_len, dmi_vendor,
p_len, dmi_product,
@@ -399,8 +398,8 @@ static int rt722_cae_load(struct rt722_sdca_priv *rt722)
regmap_write(rt722->regmap, RT722_MIC_CAE_PARAM39, 0x5f);
usleep_range(50000, 60000);
+ const struct firmware *cae_fw __free(firmware) = NULL;
request_firmware(&cae_fw, cae_filename, dev);
- kfree(cae_filename);
if (!cae_fw) {
dev_err(dev, "%s: Failed to load CAE firmware\n", __func__);
return -ENOENT;
@@ -555,7 +554,6 @@ static int rt722_cae_load(struct rt722_sdca_priv *rt722)
regcache_cache_bypass(rt722->regmap, false);
rt722->cae_update_done = 1;
dev_dbg(dev, "%s: CAE FW update done.\n", __func__);
- release_firmware(cae_fw);
return 0;
verify_abort:
@@ -565,7 +563,6 @@ static int rt722_cae_load(struct rt722_sdca_priv *rt722)
out_release:
rt722_sdca_index_update_bits(rt722, RT722_VENDOR_REG,
RT722_MISC_CTRL1, 0x8000, 0x0000);
- release_firmware(cae_fw);
dev_err(dev, "%s: CAE FW update aborted (ret=%d).\n", __func__, ret);
return ret;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 17/31] ASoC: sigmadsp: se auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (15 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 16/31] ASoC: rt722-sdca: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 16:08 ` Nuno Sá
2026-08-05 13:52 ` [PATCH 18/31] ASoC: sma1307: Use " Takashi Iwai
` (13 subsequent siblings)
30 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Lars-Peter Clausen, Nuno Sá
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/sigmadsp.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/sound/soc/codecs/sigmadsp.c b/sound/soc/codecs/sigmadsp.c
index b7dbeb237447..4ecbbac93258 100644
--- a/sound/soc/codecs/sigmadsp.c
+++ b/sound/soc/codecs/sigmadsp.c
@@ -484,7 +484,7 @@ static void devm_sigmadsp_release(struct device *dev, void *res)
static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
{
const struct sigma_firmware_header *ssfw_head;
- const struct firmware *fw;
+ const struct firmware *fw __free(firmware) = NULL;
int ret;
u32 crc;
@@ -492,7 +492,7 @@ static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
ret = request_firmware(&fw, name, sigmadsp->dev);
if (ret) {
pr_debug("%s: request_firmware() failed with %i\n", __func__, ret);
- goto done;
+ return ret;
}
/* then verify the header */
@@ -506,13 +506,13 @@ static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
*/
if (fw->size < sizeof(*ssfw_head) || fw->size >= 0x4000000) {
dev_err(sigmadsp->dev, "Failed to load firmware: Invalid size\n");
- goto done;
+ return -EINVAL;
}
ssfw_head = (void *)fw->data;
if (memcmp(ssfw_head->magic, SIGMA_MAGIC, ARRAY_SIZE(ssfw_head->magic))) {
dev_err(sigmadsp->dev, "Failed to load firmware: Invalid magic\n");
- goto done;
+ return -EINVAL;
}
crc = crc32(0, fw->data + sizeof(*ssfw_head),
@@ -521,7 +521,7 @@ static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
if (crc != le32_to_cpu(ssfw_head->crc)) {
dev_err(sigmadsp->dev, "Failed to load firmware: Wrong crc checksum: expected %x got %x\n",
le32_to_cpu(ssfw_head->crc), crc);
- goto done;
+ return -EINVAL;
}
switch (ssfw_head->version) {
@@ -542,9 +542,6 @@ static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
if (ret)
sigmadsp_firmware_release(sigmadsp);
-done:
- release_firmware(fw);
-
return ret;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* Re: [PATCH 17/31] ASoC: sigmadsp: se auto-cleanup for firmware loading
2026-08-05 13:52 ` [PATCH 17/31] ASoC: sigmadsp: se " Takashi Iwai
@ 2026-08-05 16:08 ` Nuno Sá
0 siblings, 0 replies; 49+ messages in thread
From: Nuno Sá @ 2026-08-05 16:08 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Mark Brown, linux-sound, Lars-Peter Clausen, Nuno Sá
On Wed, Aug 05, 2026 at 03:52:18PM +0200, Takashi Iwai wrote:
> Simplify the code to manage the firmware loading with __free(firmware)
> auto-cleanup.
>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Cc: Nuno Sá <nuno.sa@analog.com>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
Acked-by: Nuno Sá <nuno.sa@analog.com>
> sound/soc/codecs/sigmadsp.c | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/sound/soc/codecs/sigmadsp.c b/sound/soc/codecs/sigmadsp.c
> index b7dbeb237447..4ecbbac93258 100644
> --- a/sound/soc/codecs/sigmadsp.c
> +++ b/sound/soc/codecs/sigmadsp.c
> @@ -484,7 +484,7 @@ static void devm_sigmadsp_release(struct device *dev, void *res)
> static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
> {
> const struct sigma_firmware_header *ssfw_head;
> - const struct firmware *fw;
> + const struct firmware *fw __free(firmware) = NULL;
> int ret;
> u32 crc;
>
> @@ -492,7 +492,7 @@ static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
> ret = request_firmware(&fw, name, sigmadsp->dev);
> if (ret) {
> pr_debug("%s: request_firmware() failed with %i\n", __func__, ret);
> - goto done;
> + return ret;
> }
>
> /* then verify the header */
> @@ -506,13 +506,13 @@ static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
> */
> if (fw->size < sizeof(*ssfw_head) || fw->size >= 0x4000000) {
> dev_err(sigmadsp->dev, "Failed to load firmware: Invalid size\n");
> - goto done;
> + return -EINVAL;
> }
>
> ssfw_head = (void *)fw->data;
> if (memcmp(ssfw_head->magic, SIGMA_MAGIC, ARRAY_SIZE(ssfw_head->magic))) {
> dev_err(sigmadsp->dev, "Failed to load firmware: Invalid magic\n");
> - goto done;
> + return -EINVAL;
> }
>
> crc = crc32(0, fw->data + sizeof(*ssfw_head),
> @@ -521,7 +521,7 @@ static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
> if (crc != le32_to_cpu(ssfw_head->crc)) {
> dev_err(sigmadsp->dev, "Failed to load firmware: Wrong crc checksum: expected %x got %x\n",
> le32_to_cpu(ssfw_head->crc), crc);
> - goto done;
> + return -EINVAL;
> }
>
> switch (ssfw_head->version) {
> @@ -542,9 +542,6 @@ static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
> if (ret)
> sigmadsp_firmware_release(sigmadsp);
>
> -done:
> - release_firmware(fw);
> -
> return ret;
> }
>
> --
> 2.55.0
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH 18/31] ASoC: sma1307: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (16 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 17/31] ASoC: sigmadsp: se " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 19/31] ASoC: tas2781: " Takashi Iwai
` (12 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Kiseok Jo
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Kiseok Jo <kiseok.jo@irondevice.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/sma1307.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/sound/soc/codecs/sma1307.c b/sound/soc/codecs/sma1307.c
index c52fe95b30c6..adb369a29b9d 100644
--- a/sound/soc/codecs/sma1307.c
+++ b/sound/soc/codecs/sma1307.c
@@ -1690,7 +1690,7 @@ static void sma1307_check_fault_worker(struct work_struct *work)
static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *file)
{
- const struct firmware *fw;
+ const struct firmware *fw __free(firmware) = NULL;
int size, offset, num_mode;
int ret;
@@ -1703,22 +1703,18 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
return;
} else if ((fw->size) < SMA1307_SETTING_HEADER_SIZE) {
dev_err(sma1307->dev, "%s: Invalid file\n", __func__);
- release_firmware(fw);
sma1307->set.status = false;
return;
}
int *data __free(kfree) = kzalloc(fw->size, GFP_KERNEL);
if (!data) {
- release_firmware(fw);
sma1307->set.status = false;
return;
}
size = fw->size >> 2;
memcpy(data, fw->data, fw->size);
- release_firmware(fw);
-
/* HEADER */
sma1307->set.header_size = SMA1307_SETTING_HEADER_SIZE;
sma1307->set.checksum = data[sma1307->set.header_size - 2];
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 19/31] ASoC: tas2781: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (17 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 18/31] ASoC: sma1307: Use " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 20/31] ASoC: tas5805m: " Takashi Iwai
` (11 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Shenghao Ding, Kevin Lu, Baojun Xu, Sen Wang
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Shenghao Ding <shenghao-ding@ti.com>
Cc: Kevin Lu <kevin-lu@ti.com>
Cc: Baojun Xu <baojun.xu@ti.com>
Cc: Sen Wang <sen@ti.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/tas2781-fmwlib.c | 45 +++++++++++--------------------
1 file changed, 15 insertions(+), 30 deletions(-)
diff --git a/sound/soc/codecs/tas2781-fmwlib.c b/sound/soc/codecs/tas2781-fmwlib.c
index dcbeb9618195..b1e75fc868b6 100644
--- a/sound/soc/codecs/tas2781-fmwlib.c
+++ b/sound/soc/codecs/tas2781-fmwlib.c
@@ -2243,7 +2243,7 @@ int tas2781_load_calibration(void *context, char *file_name,
{
struct tasdevice_priv *tas_priv = (struct tasdevice_priv *)context;
struct tasdevice *tasdev = &(tas_priv->tasdevice[i]);
- const struct firmware *fw_entry = NULL;
+ const struct firmware *fw_entry __free(firmware) = NULL;
struct tasdevice_fw *tas_fmw;
struct firmware fmw;
int offset = 0;
@@ -2253,60 +2253,50 @@ int tas2781_load_calibration(void *context, char *file_name,
if (ret) {
dev_err(tas_priv->dev, "%s: Request firmware %s failed\n",
__func__, file_name);
- goto out;
+ return ret;
}
if (!fw_entry->size) {
dev_err(tas_priv->dev, "%s: file read error: size = %lu\n",
__func__, (unsigned long)fw_entry->size);
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
fmw.size = fw_entry->size;
fmw.data = fw_entry->data;
tas_fmw = tasdev->cali_data_fmw = kzalloc_obj(struct tasdevice_fw);
- if (!tasdev->cali_data_fmw) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!tasdev->cali_data_fmw)
+ return -ENOMEM;
+
tas_fmw->dev = tas_priv->dev;
offset = fw_parse_header(tas_priv, tas_fmw, &fmw, offset);
if (offset == -EINVAL) {
dev_err(tas_priv->dev, "fw_parse_header EXIT!\n");
- ret = offset;
- goto out;
+ return -EINVAL;
}
offset = fw_parse_variable_hdr_cal(tas_priv, tas_fmw, &fmw, offset);
if (offset == -EINVAL) {
dev_err(tas_priv->dev,
"%s: fw_parse_variable_header_cal EXIT!\n", __func__);
- ret = offset;
- goto out;
+ return -EINVAL;
}
offset = fw_parse_program_data(tas_priv, tas_fmw, &fmw, offset);
if (offset < 0) {
dev_err(tas_priv->dev, "fw_parse_program_data EXIT!\n");
- ret = offset;
- goto out;
+ return offset;
}
offset = fw_parse_configuration_data(tas_priv, tas_fmw, &fmw, offset);
if (offset < 0) {
dev_err(tas_priv->dev, "fw_parse_configuration_data EXIT!\n");
- ret = offset;
- goto out;
+ return offset;
}
offset = fw_parse_calibration_data(tas_priv, tas_fmw, &fmw, offset);
if (offset < 0) {
dev_err(tas_priv->dev, "fw_parse_calibration_data EXIT!\n");
- ret = offset;
- goto out;
+ return offset;
}
-out:
- release_firmware(fw_entry);
-
- return ret;
+ return 0;
}
EXPORT_SYMBOL_NS_GPL(tas2781_load_calibration, "SND_SOC_TAS2781_FMWLIB");
@@ -2399,7 +2389,7 @@ static int tasdevice_dspfw_ready(const struct firmware *fmw,
int tasdevice_dsp_parser(void *context)
{
struct tasdevice_priv *tas_priv = (struct tasdevice_priv *)context;
- const struct firmware *fw_entry;
+ const struct firmware *fw_entry __free(firmware) = NULL;
int ret;
ret = request_firmware(&fw_entry, tas_priv->coef_binaryname,
@@ -2407,15 +2397,10 @@ int tasdevice_dsp_parser(void *context)
if (ret) {
dev_err(tas_priv->dev, "%s: load %s error\n", __func__,
tas_priv->coef_binaryname);
- goto out;
+ return ret;
}
- ret = tasdevice_dspfw_ready(fw_entry, tas_priv);
- release_firmware(fw_entry);
- fw_entry = NULL;
-
-out:
- return ret;
+ return tasdevice_dspfw_ready(fw_entry, tas_priv);
}
EXPORT_SYMBOL_NS_GPL(tasdevice_dsp_parser, "SND_SOC_TAS2781_FMWLIB");
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 20/31] ASoC: tas5805m: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (18 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 19/31] ASoC: tas2781: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 21/31] ASoC: tlv320aic31xx: " Takashi Iwai
` (10 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/tas5805m.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/sound/soc/codecs/tas5805m.c b/sound/soc/codecs/tas5805m.c
index f76e04b403b5..d32796a6fa75 100644
--- a/sound/soc/codecs/tas5805m.c
+++ b/sound/soc/codecs/tas5805m.c
@@ -457,7 +457,6 @@ static int tas5805m_i2c_probe(struct i2c_client *i2c)
struct tas5805m_priv *tas5805m;
char filename[128];
const char *config_name;
- const struct firmware *fw;
int ret;
regmap = devm_regmap_init_i2c(i2c, &tas5805m_regmap);
@@ -502,24 +501,20 @@ static int tas5805m_i2c_probe(struct i2c_client *i2c)
snprintf(filename, sizeof(filename), "tas5805m_dsp_%s.bin",
config_name);
+ const struct firmware *fw __free(firmware) = NULL;
ret = request_firmware(&fw, filename, dev);
if (ret)
return ret;
if ((fw->size < 2) || (fw->size & 1)) {
dev_err(dev, "firmware is invalid\n");
- release_firmware(fw);
return -EINVAL;
}
tas5805m->dsp_cfg_len = fw->size;
tas5805m->dsp_cfg_data = devm_kmemdup(dev, fw->data, fw->size, GFP_KERNEL);
- if (!tas5805m->dsp_cfg_data) {
- release_firmware(fw);
+ if (!tas5805m->dsp_cfg_data)
return -ENOMEM;
- }
-
- release_firmware(fw);
/* Do the first part of the power-on here, while we can expect
* the I2S interface to be quiet. We must raise PDN# and then
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 21/31] ASoC: tlv320aic31xx: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (19 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 20/31] ASoC: tas5805m: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 22/31] ASoC: wm0010: " Takashi Iwai
` (9 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Shenghao Ding, Kevin Lu, Baojun Xu, Sen Wang
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Shenghao Ding <shenghao-ding@ti.com>
Cc: Kevin Lu <kevin-lu@ti.com>
Cc: Baojun Xu <baojun.xu@ti.com>
Cc: Sen Wang <sen@ti.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/codecs/tlv320aic31xx.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/sound/soc/codecs/tlv320aic31xx.c b/sound/soc/codecs/tlv320aic31xx.c
index 1d2e0ea6d4fe..43bcbc5449e1 100644
--- a/sound/soc/codecs/tlv320aic31xx.c
+++ b/sound/soc/codecs/tlv320aic31xx.c
@@ -1720,18 +1720,14 @@ static int tlv320dac3100_fw_load(struct aic31xx_priv *aic31xx,
static int tlv320dac3100_load_coeffs(struct aic31xx_priv *aic31xx,
const char *fw_name)
{
- const struct firmware *fw;
+ const struct firmware *fw __free(firmware) = NULL;
int ret;
ret = request_firmware(&fw, fw_name, aic31xx->dev);
if (ret)
return ret;
- ret = tlv320dac3100_fw_load(aic31xx, fw->data, fw->size);
-
- release_firmware(fw);
-
- return ret;
+ return tlv320dac3100_fw_load(aic31xx, fw->data, fw->size);
}
static int aic31xx_i2c_probe(struct i2c_client *i2c)
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 22/31] ASoC: wm0010: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (20 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 21/31] ASoC: tlv320aic31xx: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 23/31] ASoC: wm2000: " Takashi Iwai
` (8 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/wm0010.c | 58 ++++++++++++++-------------------------
1 file changed, 21 insertions(+), 37 deletions(-)
diff --git a/sound/soc/codecs/wm0010.c b/sound/soc/codecs/wm0010.c
index 58c0c601ee6c..c44abffe9b56 100644
--- a/sound/soc/codecs/wm0010.c
+++ b/sound/soc/codecs/wm0010.c
@@ -333,7 +333,6 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_component *comp
struct wm0010_boot_xfer *xfer;
int ret;
DECLARE_COMPLETION_ONSTACK(done);
- const struct firmware *fw;
const struct dfw_binrec *rec;
const struct dfw_inforec *inforec;
u64 *img;
@@ -342,6 +341,7 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_component *comp
INIT_LIST_HEAD(&xfer_list);
+ const struct firmware *fw __free(firmware) = NULL;
ret = request_firmware(&fw, name, component->dev);
if (ret != 0) {
dev_err(component->dev, "Failed to request application(%s): %d\n",
@@ -360,16 +360,14 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_component *comp
/* First record should be INFO */
if (rec->command != DFW_CMD_INFO) {
dev_err(component->dev, "First record not INFO\r\n");
- ret = -EINVAL;
- goto abort;
+ return -EINVAL;
}
if (inforec->info_version != INFO_VERSION) {
dev_err(component->dev,
"Unsupported version (%02d) of INFO record\r\n",
inforec->info_version);
- ret = -EINVAL;
- goto abort;
+ return -EINVAL;
}
dev_dbg(component->dev, "Version v%02d INFO record found\r\n",
@@ -378,8 +376,7 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_component *comp
/* Check it's a DSP file */
if (dsp != DEVICE_ID_WM0010) {
dev_err(component->dev, "Not a WM0010 firmware file.\r\n");
- ret = -EINVAL;
- goto abort;
+ return -EINVAL;
}
/* Skip the info record as we don't need to send it */
@@ -404,14 +401,14 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_component *comp
out = kzalloc(len, GFP_KERNEL | GFP_DMA);
if (!out) {
ret = -ENOMEM;
- goto abort1;
+ goto abort;
}
xfer->t.rx_buf = out;
img = kzalloc(len, GFP_KERNEL | GFP_DMA);
if (!img) {
ret = -ENOMEM;
- goto abort1;
+ goto abort;
}
xfer->t.tx_buf = img;
@@ -449,13 +446,13 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_component *comp
ret = spi_async(spi, &xfer->m);
if (ret != 0) {
dev_err(component->dev, "Write failed: %d\n", ret);
- goto abort1;
+ goto abort;
}
if (wm0010->boot_failed) {
dev_dbg(component->dev, "Boot fail!\n");
ret = -EINVAL;
- goto abort1;
+ goto abort;
}
}
@@ -463,7 +460,7 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_component *comp
ret = 0;
-abort1:
+abort:
while (!list_empty(&xfer_list)) {
xfer = list_first_entry(&xfer_list, struct wm0010_boot_xfer,
list);
@@ -473,8 +470,6 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_component *comp
kfree(xfer);
}
-abort:
- release_firmware(fw);
return ret;
}
@@ -482,14 +477,12 @@ static int wm0010_stage2_load(struct snd_soc_component *component)
{
struct spi_device *spi = to_spi_device(component->dev);
struct wm0010_priv *wm0010 = snd_soc_component_get_drvdata(component);
- const struct firmware *fw;
struct spi_message m;
struct spi_transfer t;
- u32 *img;
- u8 *out;
int i;
int ret = 0;
+ const struct firmware *fw __free(firmware) = NULL;
ret = request_firmware(&fw, "wm0010_stage2.bin", component->dev);
if (ret != 0) {
dev_err(component->dev, "Failed to request stage2 loader: %d\n",
@@ -500,17 +493,15 @@ static int wm0010_stage2_load(struct snd_soc_component *component)
dev_dbg(component->dev, "Downloading %zu byte stage 2 loader\n", fw->size);
/* Copy to local buffer first as vmalloc causes problems for dma */
- img = kmemdup(&fw->data[0], fw->size, GFP_KERNEL | GFP_DMA);
- if (!img) {
- ret = -ENOMEM;
- goto abort2;
- }
+ u32 *img __free(kfree) =
+ kmemdup(&fw->data[0], fw->size, GFP_KERNEL | GFP_DMA);
+ if (!img)
+ return -ENOMEM;
- out = kzalloc(fw->size, GFP_KERNEL | GFP_DMA);
- if (!out) {
- ret = -ENOMEM;
- goto abort1;
- }
+ u8 *out __free(kfree) =
+ kzalloc(fw->size, GFP_KERNEL | GFP_DMA);
+ if (!out)
+ return -ENOMEM;
spi_message_init(&m);
memset(&t, 0, sizeof(t));
@@ -527,7 +518,7 @@ static int wm0010_stage2_load(struct snd_soc_component *component)
ret = spi_sync(spi, &m);
if (ret != 0) {
dev_err(component->dev, "Initial download failed: %d\n", ret);
- goto abort;
+ return ret;
}
/* Look for errors from the boot ROM */
@@ -536,18 +527,11 @@ static int wm0010_stage2_load(struct snd_soc_component *component)
dev_err(component->dev, "Boot ROM error: %x in %d\n",
out[i], i);
wm0010_mark_boot_failure(wm0010);
- ret = -EBUSY;
- goto abort;
+ return -EBUSY;
}
}
-abort:
- kfree(out);
-abort1:
- kfree(img);
-abort2:
- release_firmware(fw);
- return ret;
+ return 0;
}
static int wm0010_boot(struct snd_soc_component *component)
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 23/31] ASoC: wm2000: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (21 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 22/31] ASoC: wm0010: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 23:16 ` Mark Brown
2026-08-05 13:52 ` [PATCH 24/31] ASoC: zl38060: " Takashi Iwai
` (7 subsequent siblings)
30 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
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..36ca86a7306b 100644
--- a/sound/soc/codecs/wm2000.c
+++ b/sound/soc/codecs/wm2000.c
@@ -796,7 +796,6 @@ 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;
int ret, i;
unsigned int reg;
u16 id;
@@ -814,7 +813,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++)
@@ -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);
@@ -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
^ permalink raw reply related [flat|nested] 49+ messages in thread* Re: [PATCH 23/31] ASoC: wm2000: Use auto-cleanup for firmware loading
2026-08-05 13:52 ` [PATCH 23/31] ASoC: wm2000: " Takashi Iwai
@ 2026-08-05 23:16 ` Mark Brown
2026-08-06 7:38 ` Takashi Iwai
0 siblings, 1 reply; 49+ messages in thread
From: Mark Brown @ 2026-08-05 23:16 UTC (permalink / raw)
To: Takashi Iwai; +Cc: linux-sound
[-- Attachment #1: Type: text/plain, Size: 554 bytes --]
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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 49+ messages in thread* Re: [PATCH 23/31] ASoC: wm2000: Use auto-cleanup for firmware loading
2026-08-05 23:16 ` Mark Brown
@ 2026-08-06 7:38 ` Takashi Iwai
0 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-06 7:38 UTC (permalink / raw)
To: Mark Brown; +Cc: Takashi Iwai, linux-sound
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 <tiwai@suse.de>
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 <tiwai@suse.de>
---
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
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH 24/31] ASoC: zl38060: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (22 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 23/31] ASoC: wm2000: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 25/31] ASoC: fsl: " Takashi Iwai
` (6 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/codecs/zl38060.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/sound/soc/codecs/zl38060.c b/sound/soc/codecs/zl38060.c
index 7de4014e626d..894b8eb42e39 100644
--- a/sound/soc/codecs/zl38060.c
+++ b/sound/soc/codecs/zl38060.c
@@ -162,7 +162,7 @@ static int zl38_fw_send_xaddr(struct regmap *regmap, const void *data)
static int zl38_load_firmware(struct device *dev, struct regmap *regmap)
{
const struct ihex_binrec *rec;
- const struct firmware *fw;
+ const struct firmware *fw __free(firmware) = NULL;
u32 addr;
u16 len;
int err;
@@ -180,7 +180,7 @@ static int zl38_load_firmware(struct device *dev, struct regmap *regmap)
return err;
err = zl38_fw_enter_boot_mode(regmap);
if (err)
- goto out;
+ return err;
rec = (const struct ihex_binrec *)fw->data;
while (rec) {
addr = be32_to_cpu(rec->addr);
@@ -195,15 +195,12 @@ static int zl38_load_firmware(struct device *dev, struct regmap *regmap)
err = -EINVAL;
}
if (err)
- goto out;
+ return err;
/* next ! */
rec = ihex_next_binrec(rec);
}
- err = zl38_fw_go(regmap);
-out:
- release_firmware(fw);
- return err;
+ return zl38_fw_go(regmap);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 25/31] ASoC: fsl: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (23 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 24/31] ASoC: zl38060: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 26/31] ASoC: Intel: avs: " Takashi Iwai
` (5 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown
Cc: linux-sound, Shengjiu Wang, Xiubo Li, Fabio Estevam, Nicolin Chen
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Shengjiu Wang <shengjiu.wang@gmail.com>
Cc: Xiubo Li <Xiubo.Lee@gmail.com>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Nicolin Chen <nicoleotsuka@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/fsl/fsl_xcvr.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/sound/soc/fsl/fsl_xcvr.c b/sound/soc/fsl/fsl_xcvr.c
index 41d100500534..982827204351 100644
--- a/sound/soc/fsl/fsl_xcvr.c
+++ b/sound/soc/fsl/fsl_xcvr.c
@@ -921,10 +921,10 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
static int fsl_xcvr_load_firmware(struct fsl_xcvr *xcvr)
{
struct device *dev = &xcvr->pdev->dev;
- const struct firmware *fw;
int ret = 0, rem, off, out, page = 0, size = FSL_XCVR_REG_OFFSET;
u32 mask, val;
+ const struct firmware *fw __free(firmware) = NULL;
ret = request_firmware(&fw, xcvr->soc_data->fw_name, dev);
if (ret) {
dev_err(dev, "failed to request firmware.\n");
@@ -936,7 +936,6 @@ static int fsl_xcvr_load_firmware(struct fsl_xcvr *xcvr)
/* RAM is 20KiB = 16KiB code + 4KiB data => max 10 pages 2KiB each */
if (rem > 16384) {
dev_err(dev, "FW size %d is bigger than 16KiB.\n", rem);
- release_firmware(fw);
return -ENOMEM;
}
@@ -947,7 +946,7 @@ static int fsl_xcvr_load_firmware(struct fsl_xcvr *xcvr)
if (ret < 0) {
dev_err(dev, "FW: failed to set page %d, err=%d\n",
page, ret);
- goto err_firmware;
+ return ret;
}
off = page * size;
@@ -968,11 +967,6 @@ static int fsl_xcvr_load_firmware(struct fsl_xcvr *xcvr)
}
}
-err_firmware:
- release_firmware(fw);
- if (ret < 0)
- return ret;
-
/* configure watermarks */
mask = FSL_XCVR_EXT_CTRL_RX_FWM_MASK | FSL_XCVR_EXT_CTRL_TX_FWM_MASK;
val = FSL_XCVR_EXT_CTRL_RX_FWM(FSL_XCVR_FIFO_WMK_RX);
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 26/31] ASoC: Intel: avs: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (24 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 25/31] ASoC: fsl: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 14:48 ` Cezary Rojewski
2026-08-05 13:52 ` [PATCH 27/31] ASoC: Intel: catpt: " Takashi Iwai
` (4 subsequent siblings)
30 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Cezary Rojewski
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Cezary Rojewski <cezary.rojewski@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/intel/avs/topology.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/soc/intel/avs/topology.c b/sound/soc/intel/avs/topology.c
index 9033f683393c..673ac31f2fea 100644
--- a/sound/soc/intel/avs/topology.c
+++ b/sound/soc/intel/avs/topology.c
@@ -2222,7 +2222,7 @@ struct avs_tplg *avs_tplg_new(struct snd_soc_component *comp)
int avs_load_topology(struct snd_soc_component *comp, const char *filename)
{
- const struct firmware *fw;
+ const struct firmware *fw __free(firmware) = NULL;
int ret;
ret = request_firmware(&fw, filename, comp->dev);
@@ -2235,7 +2235,6 @@ int avs_load_topology(struct snd_soc_component *comp, const char *filename)
if (ret < 0)
dev_err(comp->dev, "load topology \"%s\" failed: %d\n", filename, ret);
- release_firmware(fw);
return ret;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 27/31] ASoC: Intel: catpt: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (25 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 26/31] ASoC: Intel: avs: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 14:48 ` Cezary Rojewski
2026-08-05 13:52 ` [PATCH 28/31] ASoC: qcom: " Takashi Iwai
` (3 subsequent siblings)
30 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Cezary Rojewski
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Cezary Rojewski <cezary.rojewski@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/intel/catpt/loader.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/sound/soc/intel/catpt/loader.c b/sound/soc/intel/catpt/loader.c
index e7ba9e1e60ae..724cbe337db4 100644
--- a/sound/soc/intel/catpt/loader.c
+++ b/sound/soc/intel/catpt/loader.c
@@ -568,27 +568,24 @@ static int catpt_request_load_firmware(struct catpt_dev *cdev, struct dma_chan *
const char *name, bool restore)
{
struct catpt_fw_hdr *fw;
- struct firmware *img;
dma_addr_t paddr;
void *vaddr;
int ret;
- ret = request_firmware((const struct firmware **)&img, name, cdev->dev);
+ const struct firmware *img __free(firmware) = NULL;
+ ret = request_firmware(&img, name, cdev->dev);
if (ret)
return ret;
fw = (struct catpt_fw_hdr *)img->data;
if (strncmp(fw->signature, FW_SIGNATURE, FW_SIGNATURE_SIZE)) {
dev_err(cdev->dev, "firmware signature mismatch\n");
- ret = -EINVAL;
- goto release_fw;
+ return -EINVAL;
}
vaddr = dma_alloc_coherent(cdev->dev, img->size, &paddr, GFP_KERNEL);
- if (!vaddr) {
- ret = -ENOMEM;
- goto release_fw;
- }
+ if (!vaddr)
+ return -ENOMEM;
memcpy(vaddr, img->data, img->size);
fw = (struct catpt_fw_hdr *)vaddr;
@@ -598,8 +595,6 @@ static int catpt_request_load_firmware(struct catpt_dev *cdev, struct dma_chan *
ret = catpt_load_firmware(cdev, chan, paddr, fw);
dma_free_coherent(cdev->dev, img->size, vaddr, paddr);
-release_fw:
- release_firmware(img);
return ret;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 28/31] ASoC: qcom: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (26 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 27/31] ASoC: Intel: catpt: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 29/31] ASoC: renesas: " Takashi Iwai
` (2 subsequent siblings)
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound, Srinivas Kandagatla
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Srinivas Kandagatla <srini@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/qcom/qdsp6/topology.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
index 1f69fba6de26..42f7bb8e88fe 100644
--- a/sound/soc/qcom/qdsp6/topology.c
+++ b/sound/soc/qcom/qdsp6/topology.c
@@ -1313,7 +1313,6 @@ int audioreach_tplg_init(struct snd_soc_component *component)
{
struct snd_soc_card *card = component->card;
struct device *dev = component->dev;
- const struct firmware *fw;
int ret;
/* Inline with Qualcomm UCM configs and linux-firmware path */
@@ -1323,6 +1322,7 @@ int audioreach_tplg_init(struct snd_soc_component *component)
if (!tplg_fw_name)
return -ENOMEM;
+ const struct firmware *fw __free(firmware) = NULL;
ret = request_firmware(&fw, tplg_fw_name, dev);
if (ret < 0) {
dev_err(dev, "tplg firmware loading %s failed %d\n", tplg_fw_name, ret);
@@ -1335,8 +1335,6 @@ int audioreach_tplg_init(struct snd_soc_component *component)
dev_err(dev, "tplg component load failed: %d\n", ret);
}
- release_firmware(fw);
-
return ret;
}
EXPORT_SYMBOL_GPL(audioreach_tplg_init);
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 29/31] ASoC: renesas: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (27 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 28/31] ASoC: qcom: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 13:52 ` [PATCH 30/31] ASoC: SDCA: " Takashi Iwai
2026-08-05 13:52 ` [PATCH 31/31] ASoC: SOF: " Takashi Iwai
30 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-sound
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 <tiwai@suse.de>
---
sound/soc/renesas/siu_dai.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/sound/soc/renesas/siu_dai.c b/sound/soc/renesas/siu_dai.c
index 039b1264d90d..85dee9025710 100644
--- a/sound/soc/renesas/siu_dai.c
+++ b/sound/soc/renesas/siu_dai.c
@@ -715,7 +715,6 @@ static struct snd_soc_dai_driver siu_i2s_dai = {
static int siu_probe(struct platform_device *pdev)
{
- const struct firmware *fw_entry;
struct resource *res, *region;
struct siu_info *info;
int ret;
@@ -726,6 +725,7 @@ static int siu_probe(struct platform_device *pdev)
siu_i2s_data = info;
info->dev = &pdev->dev;
+ const struct firmware *fw_entry __free(firmware) = NULL;
ret = request_firmware(&fw_entry, "siu_spb.bin", &pdev->dev);
if (ret)
return ret;
@@ -736,8 +736,6 @@ static int siu_probe(struct platform_device *pdev)
*/
memcpy(&info->fw, fw_entry->data, fw_entry->size);
- release_firmware(fw_entry);
-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* [PATCH 30/31] ASoC: SDCA: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (28 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 29/31] ASoC: renesas: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-05 14:34 ` Charles Keepax
2026-08-05 13:52 ` [PATCH 31/31] ASoC: SOF: " Takashi Iwai
30 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown
Cc: linux-sound, Charles Keepax, Maciej Strozek, Bard Liao,
Pierre-Louis Bossart
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.
Only the code refactoring, no functional changes.
Cc: Charles Keepax <ckeepax@opensource.cirrus.com>
Cc: Maciej Strozek <mstrozek@opensource.cirrus.com>
Cc: Bard Liao <yung-chuan.liao@linux.intel.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/sdca/sdca_fdl.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/sound/soc/sdca/sdca_fdl.c b/sound/soc/sdca/sdca_fdl.c
index dbe572336f8c..150e36ed24bc 100644
--- a/sound/soc/sdca/sdca_fdl.c
+++ b/sound/soc/sdca/sdca_fdl.c
@@ -195,7 +195,6 @@ static int fdl_load_file(struct sdca_interrupt *interrupt,
{
struct device *dev = interrupt->dev;
struct sdca_fdl_data *fdl_data = &interrupt->function->fdl_data;
- const struct firmware *firmware = NULL;
struct acpi_sw_file *swf = NULL, *tmp;
struct sdca_fdl_file *fdl_file;
char *disk_filename;
@@ -230,6 +229,7 @@ static int fdl_load_file(struct sdca_interrupt *interrupt,
dev_dbg(dev, "FDL disk filename: %s\n", disk_filename);
+ const struct firmware *firmware __free(firmware) = NULL;
ret = firmware_request_nowarn(&firmware, disk_filename, dev);
kfree(disk_filename);
if (ret) {
@@ -258,8 +258,7 @@ static int fdl_load_file(struct sdca_interrupt *interrupt,
if (!swf) {
dev_err(dev, "failed to locate SWF\n");
- ret = -ENOENT;
- goto error;
+ return -ENOENT;
}
dev_info(dev, "loading SWF: %x-%x-%x\n",
@@ -271,9 +270,6 @@ static int fdl_load_file(struct sdca_interrupt *interrupt,
SDCA_CTL_XU_FDL_MESSAGEOFFSET, fdl_file->fdl_offset,
SDCA_CTL_XU_FDL_MESSAGELENGTH, swf->data,
swf->file_length - offsetof(struct acpi_sw_file, data));
-
-error:
- release_firmware(firmware);
return ret;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* Re: [PATCH 30/31] ASoC: SDCA: Use auto-cleanup for firmware loading
2026-08-05 13:52 ` [PATCH 30/31] ASoC: SDCA: " Takashi Iwai
@ 2026-08-05 14:34 ` Charles Keepax
0 siblings, 0 replies; 49+ messages in thread
From: Charles Keepax @ 2026-08-05 14:34 UTC (permalink / raw)
To: Takashi Iwai
Cc: Mark Brown, linux-sound, Maciej Strozek, Bard Liao,
Pierre-Louis Bossart
On Wed, Aug 05, 2026 at 03:52:31PM +0200, Takashi Iwai wrote:
> Simplify the code to manage the firmware loading with __free(firmware)
> auto-cleanup.
>
> Only the code refactoring, no functional changes.
>
> Cc: Charles Keepax <ckeepax@opensource.cirrus.com>
> Cc: Maciej Strozek <mstrozek@opensource.cirrus.com>
> Cc: Bard Liao <yung-chuan.liao@linux.intel.com>
> Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Tested-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Thanks,
Charles
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH 31/31] ASoC: SOF: Use auto-cleanup for firmware loading
2026-08-05 13:52 [PATCH 00/31] ASoC: Use auto-cleanup for firmware loading Takashi Iwai
` (29 preceding siblings ...)
2026-08-05 13:52 ` [PATCH 30/31] ASoC: SDCA: " Takashi Iwai
@ 2026-08-05 13:52 ` Takashi Iwai
2026-08-06 11:56 ` Péter Ujfalusi
30 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-05 13:52 UTC (permalink / raw)
To: Mark Brown
Cc: linux-sound, Liam Girdwood, Peter Ujfalusi, Bard Liao,
Daniel Baluta, Pierre-Louis Bossart, Vijendar Mukunda
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 <lgirdwood@gmail.com>
Cc: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Cc: Bard Liao <yung-chuan.liao@linux.intel.com>
Cc: Daniel Baluta <daniel.baluta@nxp.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
Cc: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
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;
ret = firmware_request_nowarn(&fw, fw_filename, dev);
if (ret < 0) {
dev_dbg(dev, "Failed to open firmware file: %s\n", fw_filename);
- kfree(fw_filename);
return ret;
}
@@ -44,8 +43,7 @@ static int sof_test_firmware_file(struct device *dev,
break;
default:
dev_err(dev, "Invalid firmware magic: %#x\n", *magic);
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
if (ipc_type_to_adjust) {
@@ -54,13 +52,10 @@ static int sof_test_firmware_file(struct device *dev,
dev_err(dev,
"ipc type mismatch between %s and expected: %d vs %d\n",
fw_filename, fw_ipc_type, profile->ipc_type);
- ret = -EINVAL;
+ return -EINVAL;
}
-out:
- release_firmware(fw);
- kfree(fw_filename);
- return ret;
+ return 0;
}
static int sof_test_topology_file(struct device *dev,
diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
index 6fd69ba11c41..820513bb2577 100644
--- a/sound/soc/sof/topology.c
+++ b/sound/soc/sof/topology.c
@@ -2506,13 +2506,12 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
struct snd_sof_pdata *sof_pdata = sdev->pdata;
const char *tplg_filename_prefix = sof_pdata->tplg_filename_prefix;
- const struct firmware *fw;
- const char **tplg_files;
int tplg_cnt = 0;
int ret;
int i;
- tplg_files = kcalloc(scomp->card->num_links, sizeof(char *), GFP_KERNEL);
+ const char **tplg_files __free(kfree) =
+ kcalloc(scomp->card->num_links, sizeof(char *), GFP_KERNEL);
if (!tplg_files)
return -ENOMEM;
@@ -2538,10 +2537,8 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
tplg_filename_prefix,
&tplg_files,
no_fallback);
- if (tplg_cnt < 0) {
- kfree(tplg_files);
+ if (tplg_cnt < 0)
return tplg_cnt;
- }
}
/*
@@ -2552,8 +2549,6 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
if (strstr(file, "dummy")) {
dev_err(scomp->dev,
"Function topology is required, please upgrade sof-firmware\n");
-
- kfree(tplg_files);
return -EINVAL;
}
tplg_files[0] = file;
@@ -2568,6 +2563,7 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
if (tplg_files[0] != file)
dev_info(scomp->dev, "loading topology %d: %s\n", i, tplg_files[i]);
+ const struct firmware *fw __free(firmware) = NULL;
ret = request_firmware(&fw, tplg_files[i], scomp->dev);
if (ret < 0) {
/*
@@ -2586,8 +2582,6 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
else
ret = snd_soc_tplg_component_load(scomp, &sof_tplg_ops, fw);
- release_firmware(fw);
-
if (ret < 0) {
dev_err(scomp->dev, "tplg %s component load failed %d\n",
tplg_files[i], ret);
@@ -2606,6 +2600,8 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
goto out;
}
dev_info(scomp->dev, "loading feature topology %d: %s\n", i, feature_topology);
+
+ const struct firmware *fw __free(firmware) = NULL;
ret = request_firmware(&fw, feature_topology, scomp->dev);
if (ret < 0) {
/*
@@ -2630,8 +2626,6 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
else
ret = snd_soc_tplg_component_load(scomp, &sof_tplg_ops, fw);
- release_firmware(fw);
-
if (ret < 0) {
dev_err(scomp->dev, "feature tplg %s component load failed %d\n",
feature_topologies[i], ret);
@@ -2650,8 +2644,6 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
if (ret >= 0 && sdev->led_present)
ret = snd_ctl_led_request();
- kfree(tplg_files);
-
return ret;
}
EXPORT_SYMBOL(snd_sof_load_topology);
--
2.55.0
^ permalink raw reply related [flat|nested] 49+ messages in thread* Re: [PATCH 31/31] ASoC: SOF: Use auto-cleanup for firmware loading
2026-08-05 13:52 ` [PATCH 31/31] ASoC: SOF: " Takashi Iwai
@ 2026-08-06 11:56 ` Péter Ujfalusi
2026-08-06 12:06 ` Takashi Iwai
0 siblings, 1 reply; 49+ messages in thread
From: Péter Ujfalusi @ 2026-08-06 11:56 UTC (permalink / raw)
To: Takashi Iwai, Mark Brown
Cc: linux-sound, Liam Girdwood, Bard Liao, Daniel Baluta,
Pierre-Louis Bossart, Vijendar Mukunda
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 <lgirdwood@gmail.com>
> Cc: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
> Cc: Bard Liao <yung-chuan.liao@linux.intel.com>
> Cc: Daniel Baluta <daniel.baluta@nxp.com>
> Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
> Cc: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
> 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?
> ret = firmware_request_nowarn(&fw, fw_filename, dev);
> if (ret < 0) {
> dev_dbg(dev, "Failed to open firmware file: %s\n", fw_filename);
> - kfree(fw_filename);
> return ret;
> }
>
> @@ -44,8 +43,7 @@ static int sof_test_firmware_file(struct device *dev,
> break;
> default:
> dev_err(dev, "Invalid firmware magic: %#x\n", *magic);
> - ret = -EINVAL;
> - goto out;
> + return -EINVAL;
> }
>
> if (ipc_type_to_adjust) {
> @@ -54,13 +52,10 @@ static int sof_test_firmware_file(struct device *dev,
> dev_err(dev,
> "ipc type mismatch between %s and expected: %d vs %d\n",
> fw_filename, fw_ipc_type, profile->ipc_type);
> - ret = -EINVAL;
> + return -EINVAL;
> }
> -out:
> - release_firmware(fw);
> - kfree(fw_filename);
>
> - return ret;
> + return 0;
> }
>
> static int sof_test_topology_file(struct device *dev,
> diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
> index 6fd69ba11c41..820513bb2577 100644
> --- a/sound/soc/sof/topology.c
> +++ b/sound/soc/sof/topology.c
> @@ -2506,13 +2506,12 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
> struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
> struct snd_sof_pdata *sof_pdata = sdev->pdata;
> const char *tplg_filename_prefix = sof_pdata->tplg_filename_prefix;
> - const struct firmware *fw;
> - const char **tplg_files;
> int tplg_cnt = 0;
> int ret;
> int i;
>
> - tplg_files = kcalloc(scomp->card->num_links, sizeof(char *), GFP_KERNEL);
> + const char **tplg_files __free(kfree) =
> + kcalloc(scomp->card->num_links, sizeof(char *), GFP_KERNEL);
> if (!tplg_files)
> return -ENOMEM;
>
> @@ -2538,10 +2537,8 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
> tplg_filename_prefix,
> &tplg_files,
> no_fallback);
> - if (tplg_cnt < 0) {
> - kfree(tplg_files);
> + if (tplg_cnt < 0)
> return tplg_cnt;
> - }
> }
>
> /*
> @@ -2552,8 +2549,6 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
> if (strstr(file, "dummy")) {
> dev_err(scomp->dev,
> "Function topology is required, please upgrade sof-firmware\n");
> -
> - kfree(tplg_files);
> return -EINVAL;
> }
> tplg_files[0] = file;
> @@ -2568,6 +2563,7 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
> if (tplg_files[0] != file)
> dev_info(scomp->dev, "loading topology %d: %s\n", i, tplg_files[i]);
>
> + const struct firmware *fw __free(firmware) = NULL;
can we move this at the start of the for {} loop?
for (i = 0; i < tplg_cnt; i++) {
const struct firmware *fw __free(firmware) = NULL;
...
> ret = request_firmware(&fw, tplg_files[i], scomp->dev);
> if (ret < 0) {
> /*
> @@ -2586,8 +2582,6 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
> else
> ret = snd_soc_tplg_component_load(scomp, &sof_tplg_ops, fw);
>
> - release_firmware(fw);
> -
> if (ret < 0) {
> dev_err(scomp->dev, "tplg %s component load failed %d\n",
> tplg_files[i], ret);
> @@ -2606,6 +2600,8 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
> goto out;
> }
> dev_info(scomp->dev, "loading feature topology %d: %s\n", i, feature_topology);
> +
> + const struct firmware *fw __free(firmware) = NULL;
can we move this at the start of the for {} loop?
for (i = 0; i < feature_tplg_cnt; i++) {
const struct firmware *fw __free(firmware) = NULL;
...
But I'm not sure if we buy clarity with the tplg loading.
> ret = request_firmware(&fw, feature_topology, scomp->dev);
> if (ret < 0) {
> /*
> @@ -2630,8 +2626,6 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
> else
> ret = snd_soc_tplg_component_load(scomp, &sof_tplg_ops, fw);
>
> - release_firmware(fw);
> -
> if (ret < 0) {
> dev_err(scomp->dev, "feature tplg %s component load failed %d\n",
> feature_topologies[i], ret);
> @@ -2650,8 +2644,6 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
> if (ret >= 0 && sdev->led_present)
> ret = snd_ctl_led_request();
>
> - kfree(tplg_files);
> -
> return ret;
> }
> EXPORT_SYMBOL(snd_sof_load_topology);
with that,
Acked-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Tested-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
--
Péter
^ permalink raw reply [flat|nested] 49+ messages in thread* Re: [PATCH 31/31] ASoC: SOF: Use auto-cleanup for firmware loading
2026-08-06 11:56 ` Péter Ujfalusi
@ 2026-08-06 12:06 ` Takashi Iwai
2026-08-06 13:04 ` Péter Ujfalusi
0 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2026-08-06 12:06 UTC (permalink / raw)
To: Péter Ujfalusi
Cc: Takashi Iwai, Mark Brown, linux-sound, Liam Girdwood, Bard Liao,
Daniel Baluta, Pierre-Louis Bossart, Vijendar Mukunda
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 <lgirdwood@gmail.com>
> > Cc: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
> > Cc: Bard Liao <yung-chuan.liao@linux.intel.com>
> > Cc: Daniel Baluta <daniel.baluta@nxp.com>
> > Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
> > Cc: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> > 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
^ permalink raw reply [flat|nested] 49+ messages in thread* Re: [PATCH 31/31] ASoC: SOF: Use auto-cleanup for firmware loading
2026-08-06 12:06 ` Takashi Iwai
@ 2026-08-06 13:04 ` Péter Ujfalusi
2026-08-06 13:18 ` Takashi Iwai
0 siblings, 1 reply; 49+ messages in thread
From: Péter Ujfalusi @ 2026-08-06 13:04 UTC (permalink / raw)
To: Takashi Iwai
Cc: Mark Brown, linux-sound, Liam Girdwood, Bard Liao, Daniel Baluta,
Pierre-Louis Bossart, Vijendar Mukunda
On 06/08/2026 15:06, Takashi Iwai wrote:
>>> - 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.
The only mention I have seen is the header and it does say that one
should avoid having the declaration and allocation split _if_ the
pointer is not initialzied, or do it in one line.
Where it will get a bit blurry is when you have
{
const struct firmware *fw __free(firmware) = NULL;
...
ret = something_which_might_fail();
if (ret)
goto out;
ret = request_firmware();
}
out:
...
> (I don't find whether it's mentioned, though; the documentation about
> the auto-cleanup isn't well organized yet, unfortunately...)
OK, let's leave it as it is, my ack and tested tag still stands ;)
>
>
> thanks,
>
> Takashi
>
--
Péter
^ permalink raw reply [flat|nested] 49+ messages in thread* Re: [PATCH 31/31] ASoC: SOF: Use auto-cleanup for firmware loading
2026-08-06 13:04 ` Péter Ujfalusi
@ 2026-08-06 13:18 ` Takashi Iwai
0 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2026-08-06 13:18 UTC (permalink / raw)
To: Péter Ujfalusi
Cc: Takashi Iwai, Mark Brown, linux-sound, Liam Girdwood, Bard Liao,
Daniel Baluta, Pierre-Louis Bossart, Vijendar Mukunda
On Thu, 06 Aug 2026 15:04:33 +0200,
Péter Ujfalusi wrote:
>
>
>
> On 06/08/2026 15:06, Takashi Iwai wrote:
> >>> - 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.
>
> The only mention I have seen is the header and it does say that one
> should avoid having the declaration and allocation split _if_ the
> pointer is not initialzied, or do it in one line.
>
> Where it will get a bit blurry is when you have
> {
> const struct firmware *fw __free(firmware) = NULL;
>
> ...
> ret = something_which_might_fail();
> if (ret)
> goto out;
>
> ret = request_firmware();
> }
>
> out:
> ...
Yes, and we hits this in a couple patches in this series, and the
workaround is to declare at the beginning.
(One can say that moving the declaration *is* helpful to catch such a
corner case :)
> > (I don't find whether it's mentioned, though; the documentation about
> > the auto-cleanup isn't well organized yet, unfortunately...)
>
> OK, let's leave it as it is, my ack and tested tag still stands ;)
Thanks!
Takashi
^ permalink raw reply [flat|nested] 49+ messages in thread