Skip to contentSkip to conversation

ASoC: rt5663: Stop jack work on probe failure and unbind

PATCH In review Myeonghun Pak 2 participants 2 messages Nov 18 – Nov 19

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ASoC: rt5663: Stop jack work on probe failure and unbind

rt5663 registers its jack IRQ before registering the ASoC component. If component registration fails, freeing the IRQ leaves any pending or running jack work in place while devres releases rt5663_priv. I2C removal can leave the same work behind.

Stop the IRQ handler before disabling and draining both delayed works on component registration failure and I2C removal. Stop jack_detect_work first because it can queue jd_unplug_work. Keep both works disabled through device teardown because ASoC link cleanup can still call set_jack() after I2C remove returns.

Send earlier probe failures directly to regulator cleanup, before the driver has registered an IRQ or started jack detection.

Found by a static analysis tool under development.

Fixes df7c52168ee1 ("ASoC: add rt5663 codec driver")

---
Changes in v2:
- Drop the duplicate subject from the body (Mark Brown).
- Cover component registration failure after IRQ setup (Mark Brown).
- Share I2C teardown and keep both works disabled through component unregistration to block late set_jack() enqueues.

No hardware test.

 sound/soc/codecs/rt5663.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
sound/soc/codecs/rt5663.c +14 -11
index 58b165e8b6e12537196a775338de1da1667ad82a..5e95ab2666594ea1a8f2a59338cbd513c8c97c4e 100644
@@ -3520,6 +3520,16 @@ static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev)
 	return 0;
 }
 
+static void rt5663_stop_jack_work(struct rt5663_priv *rt5663)
+{
+	if (rt5663->irq)
+		free_irq(rt5663->irq, rt5663);
+
+	/* Jack detection can queue unplug work. */
+	disable_delayed_work_sync(&rt5663->jack_detect_work);
+	disable_delayed_work_sync(&rt5663->jd_unplug_work);
+}
+
 static int rt5663_i2c_probe(struct i2c_client *i2c)
 {
 	struct rt5663_platform_data *pdata = dev_get_platdata(&i2c->dev);
@@ -3724,19 +3734,13 @@ static int rt5663_i2c_probe(struct i2c_client *i2c)
 			rt5663_dai, ARRAY_SIZE(rt5663_dai));
 
 	if (ret)
-		goto err_enable;
+		goto err_jack_work;
 
 	return 0;
 
-
-	/*
-	 * Error after enabling regulators should goto err_enable
-	 * to disable regulators.
-	 */
+err_jack_work:
+	rt5663_stop_jack_work(rt5663);
 err_enable:
-	if (i2c->irq)
-		free_irq(i2c->irq, rt5663);
-
 	regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies);
 	return ret;
 }
@@ -3745,8 +3749,7 @@ static void rt5663_i2c_remove(struct i2c_client *i2c)
 {
 	struct rt5663_priv *rt5663 = i2c_get_clientdata(i2c);
 
-	if (i2c->irq)
-		free_irq(i2c->irq, rt5663);
+	rt5663_stop_jack_work(rt5663);
 
 	regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies);
 }

base-commit: fcfcd6db32adbdfe81c1ded257200e3ea6815d9a

maintainer
#1 lore raw
Quoted 1 line · Myeonghun Pak

ASoC: rt5663: Stop jack work on probe failure and unbind

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5

Thanks!

[1/1] ASoC: rt5663: Stop jack work on probe failure and unbind

      https://git.kernel.org/broonie/sound/c/8a20b9963c66

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark