[PATCH 06/14] ALSA: hda: cs35l56: Use auto-cleanup for firmware loading

Takashi Iwai <[email protected]>
Newsgroups org.kernel.vger.linux-sound
Message-ID <[email protected]>
Simplify the code to manage the firmware loading with auto-cleanup.
By the use of __free(firmware), we can replace the manual mutex locks
with guard() gracefully, too.

Only the code refactoring, no functional changes.

Cc: [email protected]
Signed-off-by: Takashi Iwai <[email protected]>
---
 sound/hda/codecs/side-codecs/cs35l56_hda.c | 35 ++++++----------------
 1 file changed, 9 insertions(+), 26 deletions(-)

diff --git a/sound/hda/codecs/side-codecs/cs35l56_hda.c b/sound/hda/codecs/side-codecs/cs35l56_hda.c
index 78c2cf387a00..bc207ab5b020 100644
--- a/sound/hda/codecs/side-codecs/cs35l56_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l56_hda.c
@@ -527,18 +527,6 @@ static void cs35l56_hda_request_firmware_files(struct cs35l56_hda *cs35l56,
 						  base_name, NULL, NULL, "bin");
 }
 
-static void cs35l56_hda_release_firmware_files(const struct firmware *wmfw_firmware,
-					       char *wmfw_filename,
-					       const struct firmware *coeff_firmware,
-					       char *coeff_filename)
-{
-	release_firmware(wmfw_firmware);
-	kfree(wmfw_filename);
-
-	release_firmware(coeff_firmware);
-	kfree(coeff_filename);
-}
-
 static int cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56)
 {
 	int ret;
@@ -561,10 +549,10 @@ static int cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56)
 
 static void cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)
 {
-	const struct firmware *coeff_firmware = NULL;
-	const struct firmware *wmfw_firmware = NULL;
-	char *coeff_filename = NULL;
-	char *wmfw_filename = NULL;
+	const struct firmware *coeff_firmware __free(firmware) = NULL;
+	const struct firmware *wmfw_firmware __free(firmware) = NULL;
+	char *coeff_filename __free(kfree) = NULL;
+	char *wmfw_filename __free(kfree) = NULL;
 	unsigned int preloaded_fw_ver;
 	bool firmware_missing;
 	int ret;
@@ -606,14 +594,14 @@ static void cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)
 	if (firmware_missing) {
 		if (!wmfw_firmware) {
 			dev_err(cs35l56->base.dev, ".%s file required but not found\n", "wmfw");
-			goto err_fw_release;
+			return;
 		} else if (!coeff_firmware) {
 			dev_err(cs35l56->base.dev, ".%s file required but not found\n", "bin");
-			goto err_fw_release;
+			return;
 		}
 	}
 
-	mutex_lock(&cs35l56->base.irq_lock);
+	guard(mutex)(&cs35l56->base.irq_lock);
 
 	/*
 	 * If the firmware hasn't been patched it must be shutdown before
@@ -624,14 +612,14 @@ static void cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)
 	if (firmware_missing && (wmfw_firmware || coeff_firmware)) {
 		ret = cs35l56_firmware_shutdown(&cs35l56->base);
 		if (ret)
-			goto err;
+			return;
 	}
 
 	ret = cs_dsp_power_up(&cs35l56->cs_dsp, wmfw_firmware, wmfw_filename,
 			      coeff_firmware, coeff_filename, "misc");
 	if (ret) {
 		dev_dbg(cs35l56->base.dev, "%s: cs_dsp_power_up ret %d\n", __func__, ret);
-		goto err;
+		return;
 	}
 
 	if (wmfw_filename)
@@ -679,11 +667,6 @@ static void cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)
 err_powered_up:
 	if (!cs35l56->base.fw_patched)
 		cs_dsp_power_down(&cs35l56->cs_dsp);
-err:
-	mutex_unlock(&cs35l56->base.irq_lock);
-err_fw_release:
-	cs35l56_hda_release_firmware_files(wmfw_firmware, wmfw_filename,
-					   coeff_firmware, coeff_filename);
 }
 
 static void cs35l56_hda_dsp_work(struct work_struct *work)
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.