[PATCH] ASoC: Intel: bytcr_rt5640: Add missing return after put_device()

From: Tang Bin

Date: Sat Oct 24 2026 - 23:29:27 EST


In the fallback i2c_client path, when i2c_verify_client() fails, the
code calls put_device(codec_dev) to drop the device reference but does
not return an error. Instead, it falls through and stores the
already-dereferenced pointer in priv->codec_dev. This leads to two
problems:

1. The code continues to use codec_dev after its reference was dropped,
accessing potentially freed memory (use-after-free).
2. The remove function calls put_device(priv->codec_dev) again,
resulting in a double-put that unbalances the device reference count.

Fix this by adding 'return -ENODEV;' after put_device(codec_dev) to
abort the probe cleanly when the fallback device is not a valid
i2c_client.

Fixes: 4a8b3a682be9 ("ASoC: Intel: bytcr_rt5640: fallback mechanism if MCLK is not enabled")
Signed-off-by: Tang Bin <tangbin@xxxxxxxxxxxxxxxxxxxx>
---
sound/soc/intel/boards/bytcr_rt5640.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/sound/soc/intel/boards/bytcr_rt5640.c b/sound/soc/intel/boards/bytcr_rt5640.c
index 40da3eea5..557486c6f 100644
--- a/sound/soc/intel/boards/bytcr_rt5640.c
+++ b/sound/soc/intel/boards/bytcr_rt5640.c
@@ -1764,6 +1764,7 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
dev_err(dev, "Error '%s' is not an i2c_client\n",
BYT_RT5640_FALLBACK_CODEC_DEV_NAME);
put_device(codec_dev);
+ return -ENODEV;
}

/* fixup codec name */
--
2.52.0.windows.1