Skip to contentSkip to conversation

ASoC: rt-sdw: always cancel jack work on remove

PATCH In review Jiale Yao 2 participants 8 messages Sep 25 – Oct 5

Subsystems (3)
lore
Share & tools
lore

Jiale Yao

author
#0 lore raw

cover ASoC: rt-sdw: always cancel jack work on remove

The Realtek SoundWire codec remove callbacks cancel jack work only while hw_init is true. hw_init is cleared by update_status() when the slave becomes unattached, but jack work can already have been queued by the interrupt callback or jack initialization path. If remove runs after that state transition, the pending work is not drained and can run after the codec private data has been freed.

The same lifecycle problem can be triggered in each codec:
1. init queues jack work;
2. update_status(UNATTACHED) clears hw_init;
3. remove sees hw_init false and skips the cancel;
4. the work runs after private data teardown.

Each codec initializes its work objects during probe, so the remove paths can cancel them unconditionally and pair the work lifetime with the codec private data lifetime instead of the mutable hw_init state.

The series fixes rt5682-sdw, rt711-sdw, rt711-sdca-sdw, rt712-sdca-sdw, rt721-sdca-sdw and rt722-sdca-sdw. Each patch is independent and applies to the same baseline.

Jiale Yao (6):
ASoC: rt5682-sdw: always cancel jack work on remove
ASoC: rt711-sdw: always cancel jack work on remove
ASoC: rt711-sdca: always cancel jack work on remove
ASoC: rt712-sdca: always cancel jack work on remove
ASoC: rt721-sdca: always cancel jack work on remove
ASoC: rt722-sdca: always cancel jack work on remove

 sound/soc/codecs/rt5682-sdw.c     | 3 +--
 sound/soc/codecs/rt711-sdca-sdw.c | 6 ++----
 sound/soc/codecs/rt711-sdw.c      | 8 +++-----
 sound/soc/codecs/rt712-sdca-sdw.c | 6 ++----
 sound/soc/codecs/rt721-sdca-sdw.c | 6 ++----
 sound/soc/codecs/rt722-sdca-sdw.c | 6 ++----
 6 files changed, 12 insertions(+), 23 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/6 ASoC: rt5682-sdw: always cancel jack work on remove

rt5682_sdw_remove() cancels jack_detect_work only when hw_init is true. rt5682_update_status() clears hw_init when the SoundWire slave becomes unattached, but jack_detect_work may already have been queued by rt5682_interrupt_callback() or the jack initialization path.

A remove after that status update can therefore skip the cancellation and leave delayed work pending after the codec private data has been freed.

The work object is initialized during probe, so cancel it unconditionally instead of relying on the mutable hw_init state.

Fixes ac63716da307 ("ASoC: Realtek/Maxim SoundWire codecs: disable pm_runtime on remove")
---
 sound/soc/codecs/rt5682-sdw.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/codecs/rt5682-sdw.c +1 -2
index 23c7d2a9dbee..5f2897c58ad7 100644
@@ -704,8 +704,7 @@ static void rt5682_sdw_remove(struct sdw_slave *slave)
 {
 	struct rt5682_priv *rt5682 = dev_get_drvdata(&slave->dev);
 
-	if (rt5682->hw_init)
-		cancel_delayed_work_sync(&rt5682->jack_detect_work);
+	cancel_delayed_work_sync(&rt5682->jack_detect_work);
 
 	pm_runtime_disable(&slave->dev);
 }
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/6 ASoC: rt711-sdw: always cancel jack work on remove

In reply to Jiale Yao

rt711_sdw_remove() cancels the jack and calibration work only when hw_init is true. rt711_update_status() clears hw_init when the SoundWire slave becomes unattached, but work may already have been queued by rt711_interrupt_callback() or the jack initialization path.

A remove after that status update can therefore skip the cancellation and leave work pending after the codec private data has been freed.

The work objects are initialized during probe, so cancel them unconditionally instead of relying on the mutable hw_init state.

Fixes ac63716da307 ("ASoC: Realtek/Maxim SoundWire codecs: disable pm_runtime on remove")
---
 sound/soc/codecs/rt711-sdw.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
sound/soc/codecs/rt711-sdw.c +3 -5
index 4ad2b1da1954..798d181d5c90 100644
@@ -461,11 +461,9 @@ static void rt711_sdw_remove(struct sdw_slave *slave)
 {
 	struct rt711_priv *rt711 = dev_get_drvdata(&slave->dev);
 
-	if (rt711->hw_init) {
-		cancel_delayed_work_sync(&rt711->jack_detect_work);
-		cancel_delayed_work_sync(&rt711->jack_btn_check_work);
-		cancel_work_sync(&rt711->calibration_work);
-	}
+	cancel_delayed_work_sync(&rt711->jack_detect_work);
+	cancel_delayed_work_sync(&rt711->jack_btn_check_work);
+	cancel_work_sync(&rt711->calibration_work);
 
 	pm_runtime_disable(&slave->dev);
 
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 3/6 ASoC: rt711-sdca: always cancel jack work on remove

In reply to Jiale Yao

rt711_sdca_sdw_remove() cancels the jack work only when hw_init is true. rt711_sdca_update_status() clears hw_init when the SoundWire slave becomes unattached, but jack work may already have been queued by rt711_sdca_interrupt_callback() or the jack initialization path.

A remove after that status update can therefore skip the cancellation and leave delayed work pending after the codec private data has been freed.

The work objects are initialized during probe, so cancel them unconditionally instead of relying on the mutable hw_init state.

Fixes ac63716da307 ("ASoC: Realtek/Maxim SoundWire codecs: disable pm_runtime on remove")
---
 sound/soc/codecs/rt711-sdca-sdw.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
sound/soc/codecs/rt711-sdca-sdw.c +2 -4
index e292b28b029e..f74b193c720d 100644
@@ -369,10 +369,8 @@ static void rt711_sdca_sdw_remove(struct sdw_slave *slave)
 {
 	struct rt711_sdca_priv *rt711 = dev_get_drvdata(&slave->dev);
 
-	if (rt711->hw_init) {
-		cancel_delayed_work_sync(&rt711->jack_detect_work);
-		cancel_delayed_work_sync(&rt711->jack_btn_check_work);
-	}
+	cancel_delayed_work_sync(&rt711->jack_detect_work);
+	cancel_delayed_work_sync(&rt711->jack_btn_check_work);
 
 	pm_runtime_disable(&slave->dev);
 
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH 4/6 ASoC: rt712-sdca: always cancel jack work on remove

In reply to Jiale Yao

rt712_sdca_sdw_remove() cancels the jack work only when hw_init is true. rt712_sdca_update_status() clears hw_init when the SoundWire slave becomes unattached, but jack work may already have been queued by rt712_sdca_interrupt_callback() or the jack initialization path.

A remove after that status update can therefore skip the cancellation and leave delayed work pending after the codec private data has been freed.

The work objects are initialized during probe, so cancel them unconditionally instead of relying on the mutable hw_init state.

Fixes 6c39710da75c ("ASoC: rt712-sdca: Add RT712 SDCA driver for Jack and Amp topology")
---
 sound/soc/codecs/rt712-sdca-sdw.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
sound/soc/codecs/rt712-sdca-sdw.c +2 -4
index edba0367d9ce..a9d4e0795175 100644
@@ -386,10 +386,8 @@ static void rt712_sdca_sdw_remove(struct sdw_slave *slave)
 {
 	struct rt712_sdca_priv *rt712 = dev_get_drvdata(&slave->dev);
 
-	if (rt712->hw_init) {
-		cancel_delayed_work_sync(&rt712->jack_detect_work);
-		cancel_delayed_work_sync(&rt712->jack_btn_check_work);
-	}
+	cancel_delayed_work_sync(&rt712->jack_detect_work);
+	cancel_delayed_work_sync(&rt712->jack_btn_check_work);
 
 	pm_runtime_disable(&slave->dev);
 
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH 5/6 ASoC: rt721-sdca: always cancel jack work on remove

In reply to Jiale Yao

rt721_sdca_sdw_remove() cancels the jack work only when hw_init is true. rt721_sdca_update_status() clears hw_init when the SoundWire slave becomes unattached, but jack work may already have been queued by rt721_sdca_interrupt_callback() or the jack initialization path.

A remove after that status update can therefore skip the cancellation and leave delayed work pending after the codec private data has been freed.

The work objects are initialized during probe, so cancel them unconditionally instead of relying on the mutable hw_init state.

Fixes 86ce355c1f9a ("ASoC: rt721-sdca: Add RT721 SDCA driver")
---
 sound/soc/codecs/rt721-sdca-sdw.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
sound/soc/codecs/rt721-sdca-sdw.c +2 -4
index 910583162d3e..c65e4d1369c9 100644
@@ -422,10 +422,8 @@ static void rt721_sdca_sdw_remove(struct sdw_slave *slave)
 {
 	struct rt721_sdca_priv *rt721 = dev_get_drvdata(&slave->dev);
 
-	if (rt721->hw_init) {
-		cancel_delayed_work_sync(&rt721->jack_detect_work);
-		cancel_delayed_work_sync(&rt721->jack_btn_check_work);
-	}
+	cancel_delayed_work_sync(&rt721->jack_detect_work);
+	cancel_delayed_work_sync(&rt721->jack_btn_check_work);
 
 	if (rt721->first_hw_init)
 		pm_runtime_disable(&slave->dev);
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH 6/6 ASoC: rt722-sdca: always cancel jack work on remove

In reply to Jiale Yao

rt722_sdca_sdw_remove() cancels the jack work only when hw_init is true. rt722_sdca_update_status() clears hw_init when the SoundWire slave becomes unattached, but jack work may already have been queued by rt722_sdca_interrupt_callback() or the jack initialization path.

A remove after that status update can therefore skip the cancellation and leave delayed work pending after the codec private data has been freed.

The work objects are initialized during probe, so cancel them unconditionally instead of relying on the mutable hw_init state.

Fixes 7f5d6036ca00 ("ASoC: rt722-sdca: Add RT722 SDCA driver")
---
 sound/soc/codecs/rt722-sdca-sdw.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
sound/soc/codecs/rt722-sdca-sdw.c +2 -4
index 5bc9aed58d14..078255fbe1fc 100644
@@ -471,10 +471,8 @@ static void rt722_sdca_sdw_remove(struct sdw_slave *slave)
 {
 	struct rt722_sdca_priv *rt722 = dev_get_drvdata(&slave->dev);
 
-	if (rt722->hw_init) {
-		cancel_delayed_work_sync(&rt722->jack_detect_work);
-		cancel_delayed_work_sync(&rt722->jack_btn_check_work);
-	}
+	cancel_delayed_work_sync(&rt722->jack_detect_work);
+	cancel_delayed_work_sync(&rt722->jack_btn_check_work);
 
 	if (rt722->first_hw_init)
 		pm_runtime_disable(&slave->dev);
Signature · 1 line
2.34.1
maintainer
#7 lore raw
In reply to Jiale Yao
Quoted 10 lines · Jiale Yao

ASoC: rt-sdw: always cancel jack work on remove

The Realtek SoundWire codec remove callbacks cancel jack work only while hw_init is true. hw_init is cleared by update_status() when the slave becomes unattached, but jack work can already have been queued by the interrupt callback or jack initialization path. If remove runs after that state transition, the pending work is not drained and can run after the codec private data has been freed.

[...]

Applied to

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

Thanks!

[1/6] ASoC: rt5682-sdw: always cancel jack work on remove

      https://git.kernel.org/broonie/sound/c/9a98f7e955d3
[2/6] ASoC: rt711-sdw: always cancel jack work on remove
      https://git.kernel.org/broonie/sound/c/4bf78e3d9e32
[3/6] ASoC: rt711-sdca: always cancel jack work on remove
      https://git.kernel.org/broonie/sound/c/ecc2fca6dece
[4/6] ASoC: rt712-sdca: always cancel jack work on remove
      https://git.kernel.org/broonie/sound/c/c7d07df95ee7
[5/6] ASoC: rt721-sdca: always cancel jack work on remove
      https://git.kernel.org/broonie/sound/c/958d025d6235
[6/6] ASoC: rt722-sdca: always cancel jack work on remove
      https://git.kernel.org/broonie/sound/c/9d29132d81a7

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