summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2026-08-06 15:59:42 +0200
committerMark Brown <broonie@kernel.org>2026-08-10 15:33:51 +0100
commit5dd15c805eefd56baabdca3cbe8f64e6c5f02eba (patch)
tree1c591b6e0d19df30788bf40e9ea3b5842d5436a4
parentb37d70e5bfc32be630b2b86943f0c9f49382eee3 (diff)
ASoC: ntpfw: 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> Link: https://patch.msgid.link/20260806140006.1412298-11-tiwai@suse.de Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/codecs/ntpfw.c21
1 files 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);