[PATCH] ASoC: ak4375: Power off the codec on probe failure

From: Haowen Tu

Date: Tue Nov 17 2026 - 01:24:38 EST


After ak4375_power_on() succeeds, probe can still fail while reading the
device ID, rejecting an unsupported ID or registering the ASoC component.
These paths return without disabling the supplies or taking PDN low.
Managed regulator acquisition does not undo regulator_bulk_enable(), so
the enabled supplies are leaked when the probe resources are released.

Route these failures through ak4375_power_off(). Also disable runtime PM
if component registration fails, since the remove callback is not called
for a failed probe, and mark the device suspended after powering it off.
Restore normal cache access after the device ID read regardless of whether
it succeeds.

Fixes: 53778b8292b5 ("ASoC: Add AK4375 support")
Signed-off-by: Haowen Tu <tuhaowen@xxxxxxxxxxxxx>
---
sound/soc/codecs/ak4375.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/sound/soc/codecs/ak4375.c b/sound/soc/codecs/ak4375.c
index 28cc41014bd9..04c99b188981 100644
--- a/sound/soc/codecs/ak4375.c
+++ b/sound/soc/codecs/ak4375.c
@@ -536,19 +536,19 @@ static int ak4375_i2c_probe(struct i2c_client *i2c)
regcache_cache_bypass(ak4375->regmap, true);

ret = regmap_read(ak4375->regmap, AK4375_15_AUDIO_IF_FORMAT, &deviceid);
+ regcache_cache_bypass(ak4375->regmap, false);
if (ret < 0) {
dev_err(ak4375->dev, "unable to read DEVICEID!\n");
- return ret;
+ goto err_power_off;
}

- regcache_cache_bypass(ak4375->regmap, false);
-
deviceid = (deviceid & DEVICEID_MASK) >> 5;

+ ret = -EINVAL;
switch (deviceid) {
case DEVICEID_AK4331:
dev_err(ak4375->dev, "found untested AK4331\n");
- return -EINVAL;
+ goto err_power_off;
case DEVICEID_AK4375:
dev_dbg(ak4375->dev, "found AK4375\n");
break;
@@ -557,13 +557,13 @@ static int ak4375_i2c_probe(struct i2c_client *i2c)
break;
case DEVICEID_AK4376A:
dev_err(ak4375->dev, "found unsupported AK4376/A!\n");
- return -EINVAL;
+ goto err_power_off;
case DEVICEID_AK4377:
dev_err(ak4375->dev, "found unsupported AK4377!\n");
- return -EINVAL;
+ goto err_power_off;
default:
dev_err(ak4375->dev, "unrecognized DEVICEID!\n");
- return -EINVAL;
+ goto err_power_off;
}

pm_runtime_set_active(ak4375->dev);
@@ -573,10 +573,17 @@ static int ak4375_i2c_probe(struct i2c_client *i2c)
drvdata->dai_drv, 1);
if (ret < 0) {
dev_err(ak4375->dev, "Failed to register CODEC: %d\n", ret);
+ pm_runtime_disable(ak4375->dev);
+ ak4375_power_off(ak4375);
+ pm_runtime_set_suspended(ak4375->dev);
return ret;
}

return 0;
+
+err_power_off:
+ ak4375_power_off(ak4375);
+ return ret;
}

static void ak4375_i2c_remove(struct i2c_client *i2c)
--
2.50.1