]> git.hungrycats.org Git - linux/commitdiff
ASoC: fsl: Use auto-cleanup for firmware loading
authorTakashi Iwai <tiwai@suse.de>
Thu, 6 Aug 2026 13:59:57 +0000 (15:59 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 10 Aug 2026 14:34:10 +0000 (15:34 +0100)
Simplify the code to manage the firmware loading with __free(firmware)
auto-cleanup.

Only the code refactoring, no functional changes.

Cc: Shengjiu Wang <shengjiu.wang@gmail.com>
Cc: Xiubo Li <Xiubo.Lee@gmail.com>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Nicolin Chen <nicoleotsuka@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20260806140006.1412298-26-tiwai@suse.de
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/fsl/fsl_xcvr.c

index 41d100500534f643583d3a1a42316be023f61858..98282720435112c7e597d4ebe18f6dff06825339 100644 (file)
@@ -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);