[PATCH v2 16/31] ASoC: rt722-sdca: 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 __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 <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
---
 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
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.