[PATCH] ASoC: rt5668: initialize calibrate_mutex before first use
From: Tristan Madani
Date: Wed Nov 11 2026 - 06:50:04 EST
From: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
rt5668_calibrate() is called during i2c_probe() and takes
calibrate_mutex. However, mutex_init() for that mutex is not called
until later in the probe sequence, after the INIT_DELAYED_WORK calls.
This means the first calibration locks an uninitialized mutex.
While this works by accident because devm_kzalloc zeroes the struct
memory, it is incorrect and triggers warnings with
CONFIG_DEBUG_MUTEXES=y.
Move the mutex_init() call to before rt5668_calibrate() so the mutex
is properly initialized before its first use.
Fixes: d59fb2856223 ("ASoC: rt5668: add rt5668B codec driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
---
sound/soc/codecs/rt5668.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/rt5668.c b/sound/soc/codecs/rt5668.c
index cd6245d6b91af..6748bcc63ac39 100644
--- a/sound/soc/codecs/rt5668.c
+++ b/sound/soc/codecs/rt5668.c
@@ -2490,6 +2490,8 @@ static int rt5668_i2c_probe(struct i2c_client *i2c)
rt5668_reset(rt5668->regmap);
+ mutex_init(&rt5668->calibrate_mutex);
+
rt5668_calibrate(rt5668);
regmap_write(rt5668->regmap, RT5668_DEPOP_1, 0x0000);
@@ -2547,8 +2549,6 @@ static int rt5668_i2c_probe(struct i2c_client *i2c)
INIT_DELAYED_WORK(&rt5668->jd_check_work,
rt5668_jd_check_handler);
- mutex_init(&rt5668->calibrate_mutex);
-
if (i2c->irq) {
ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL,
rt5668_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
--
2.47.3