[PATCH 10/31] ASoC: ntpfw: Use auto-cleanup for firmware loading

Takashi Iwai <[email protected]> Wed, 5 Aug 2026 15:52:11 +0200
Newsgroups org.kernel.vger.linux-sound
Message-ID <[email protected]>
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.

Only the code refactoring, no functional changes.

Signed-off-by: Takashi Iwai <[email protected]>
---
 sound/soc/codecs/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