summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2026-08-10 15:34:19 +0100
committerMark Brown <broonie@kernel.org>2026-08-10 15:34:19 +0100
commite7a5d3b04cc6aaabed031c0e08b369dee46e2ded (patch)
treedf787023e1606e5d6005578ed7ce43ee7031dc62
parent530e344e4b7ebaef88b845c3a2413a114f517d79 (diff)
parent6d0a9e4df17979ef8acbf8d7d6145fb1375e45cd (diff)
ASoC: Use auto-cleanup for firmware loading
Takashi Iwai <tiwai@suse.de> says: here is a revised series of trivial patches to use the auto-cleanup (via __free(firmware)) for firmware management. Now compile warnings due to the mixture with goto have been addressed for rt1320-sdw and wm2000 drivers. Others remain identical, just took a few review Acks. Link: https://patch.msgid.link/20260806140006.1412298-1-tiwai@suse.de
-rw-r--r--sound/soc/codecs/aw87390.c7
-rw-r--r--sound/soc/codecs/aw88081.c9
-rw-r--r--sound/soc/codecs/aw88166.c8
-rw-r--r--sound/soc/codecs/aw88261.c8
-rw-r--r--sound/soc/codecs/aw88395/aw88395.c8
-rw-r--r--sound/soc/codecs/aw88399-lib.c8
-rw-r--r--sound/soc/codecs/fs-amp-lib.c3
-rw-r--r--sound/soc/codecs/hdac_hda.c3
-rw-r--r--sound/soc/codecs/max98390.c16
-rw-r--r--sound/soc/codecs/ntpfw.c21
-rw-r--r--sound/soc/codecs/pcm6240.c16
-rw-r--r--sound/soc/codecs/peb2466.c7
-rw-r--r--sound/soc/codecs/rt1320-sdw.c17
-rw-r--r--sound/soc/codecs/rt5575-spi.c3
-rw-r--r--sound/soc/codecs/rt5677.c8
-rw-r--r--sound/soc/codecs/rt722-sdca.c9
-rw-r--r--sound/soc/codecs/sigmadsp.c13
-rw-r--r--sound/soc/codecs/sma1307.c6
-rw-r--r--sound/soc/codecs/tas2781-fmwlib.c45
-rw-r--r--sound/soc/codecs/tas5805m.c9
-rw-r--r--sound/soc/codecs/tlv320aic31xx.c8
-rw-r--r--sound/soc/codecs/wm0010.c58
-rw-r--r--sound/soc/codecs/wm2000.c7
-rw-r--r--sound/soc/codecs/zl38060.c11
-rw-r--r--sound/soc/fsl/fsl_xcvr.c10
-rw-r--r--sound/soc/intel/avs/topology.c3
-rw-r--r--sound/soc/intel/catpt/loader.c15
-rw-r--r--sound/soc/qcom/qdsp6/topology.c4
-rw-r--r--sound/soc/renesas/siu_dai.c4
-rw-r--r--sound/soc/sdca/sdca_fdl.c8
-rw-r--r--sound/soc/sof/fw-file-profile.c19
-rw-r--r--sound/soc/sof/topology.c20
32 files changed, 129 insertions, 262 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) {
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;
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) {
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;
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;
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) {
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;
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
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)
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);
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);
}
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)
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__);
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;
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)
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 @@ verify_abort:
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;
}
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;
}
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];
diff --git a/sound/soc/codecs/tas2781-fmwlib.c b/sound/soc/codecs/tas2781-fmwlib.c
index 11d1c2ac865b..df30abfb3b6b 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");
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
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)
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 @@ abort1:
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)
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;
}
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);
}
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);
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;
}
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;
}
diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
index 54661bcb006c..faafbc5c0ad0 100644
--- a/sound/soc/qcom/qdsp6/topology.c
+++ b/sound/soc/qcom/qdsp6/topology.c
@@ -1416,7 +1416,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 */
@@ -1426,6 +1425,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);
@@ -1438,8 +1438,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);
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;
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;
}
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 @@ out:
if (ret >= 0 && sdev->led_present)
ret = snd_ctl_led_request();
- kfree(tplg_files);
-
return ret;
}
EXPORT_SYMBOL(snd_sof_load_topology);