]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: cs35l56: Fix potential probe() deadlock
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Thu, 16 Jul 2026 13:20:44 +0000 (14:20 +0100)
committerMark Brown <broonie@kernel.org>
Thu, 16 Jul 2026 14:25:11 +0000 (15:25 +0100)
On I2C/SPI call cs35l56_init() before calling
snd_soc_register_component() to prevent the potential for a deadlock
on init_completion.

For most buses all the hardware would be ready when probe() returns,
but on SoundWire, probe() must return before the SoundWire bus driver
will enumerate the device. All access to the registers must be deferred
until the driver receives an ATTACHED notification. But anything that
could return -EPROBE_DEFER must be called during probe, and that includes
snd_soc_register_component(). Because of that, on SoundWire the ASoC
component can be created before the registers are accssible, so
cs35l56_component_probe() waits for init_completion to signal that the
registers are accessible.

On I2C/SPI this 2-stage startup isn't required so their probe()
functions simply called cs35l56_common_probe() and then cs35l56_init().
The problem with this was that snd_soc_register_component() was still
called early. If this triggered ASoC to create the card, ASoC would call
cs35l56_component_probe() which waits on init_completion - but this would
be running inside the cs35l56 driver probe() so blocking it from reaching
the code that signals init_completion, causing a deadlock.

Fixes: e496112529006 ("ASoC: cs35l56: Add driver for Cirrus Logic CS35L56")
Reported-by: Salman S. Tahir <salman.abusaad@gmail.com>
Closes: https://lore.kernel.org/linux-sound/95c21574-97d5-4311-9263-9e174d22d22c@opensource.cirrus.com/T/#u
Tested-by: Salman S. Tahir <salman.abusaad@gmail.com>
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260716132045.1469156-2-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/cs35l56-i2c.c
sound/soc/codecs/cs35l56-spi.c
sound/soc/codecs/cs35l56.c

index 0f64ab628b03bdd3a64faefdde0e59d2a3b16951..4f6ddf1c5a3f6a02f2443b28d9523679442da40f 100644 (file)
@@ -55,9 +55,7 @@ static int cs35l56_i2c_probe(struct i2c_client *client)
        if (ret != 0)
                return ret;
 
-       ret = cs35l56_init(cs35l56);
-       if (ret == 0)
-               ret = cs35l56_irq_request(&cs35l56->base, client->irq);
+       ret = cs35l56_irq_request(&cs35l56->base, client->irq);
        if (ret < 0)
                cs35l56_remove(cs35l56);
 
index 9bc9b7c98390dc43210cfb8ed209afa4b64ecbe1..b1eb924a5b6ccf0ccd610dd99be98f36d8ddba5d 100644 (file)
@@ -44,9 +44,7 @@ static int cs35l56_spi_probe(struct spi_device *spi)
        if (ret != 0)
                return ret;
 
-       ret = cs35l56_init(cs35l56);
-       if (ret == 0)
-               ret = cs35l56_irq_request(&cs35l56->base, spi->irq);
+       ret = cs35l56_irq_request(&cs35l56->base, spi->irq);
        if (ret < 0)
                cs35l56_remove(cs35l56);
 
index 570a68829ccd0716b25b4b980978dde016ae7e3a..fea4362e74cddb212292818ea376ef9cadb9a548 100644 (file)
@@ -2008,6 +2008,16 @@ int cs35l56_common_probe(struct cs35l56_private *cs35l56)
                goto err;
        }
 
+       /*
+        * On SoundWire the cs35l56_init() cannot be run until after the
+        * device has been enumerated by the SoundWire core.
+        */
+       if (!cs35l56->sdw_peripheral) {
+               ret = cs35l56_init(cs35l56);
+               if (ret)
+                       goto err_remove_wm_adsp;
+       }
+
        ret = snd_soc_register_component(cs35l56->base.dev,
                                         &soc_component_dev_cs35l56,
                                         cs35l56_dai, ARRAY_SIZE(cs35l56_dai));
@@ -2022,6 +2032,11 @@ err_remove_wm_adsp:
        wm_adsp2_remove(&cs35l56->dsp);
 
 err:
+       if (pm_runtime_enabled(cs35l56->base.dev)) {
+               pm_runtime_dont_use_autosuspend(cs35l56->base.dev);
+               pm_runtime_disable(cs35l56->base.dev);
+       }
+
        gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 0);
        regulator_bulk_disable(ARRAY_SIZE(cs35l56->supplies), cs35l56->supplies);