Skip to contentSkip to conversation

ASoC: ak4613: cancel dummy write work on component removal

PATCH In review Hyunjung Ko 3 participants 3 messages Nov 10 – Nov 11

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

PATCH 1/1 ASoC: ak4613: cancel dummy write work on component removal

ak4613_dai_trigger() schedules priv->dummy_write_work on playback start to issue the PW_MGMT1/PW_MGMT3 dummy writes from a non-atomic context. The worker dereferences ak4613_priv and accesses the component over I2C.

priv is allocated with devm_kzalloc() and the component driver has no remove callback, so nothing cancels the work on unbind. If the device is unbound while the work is still pending, the worker runs after priv has been freed by devres, resulting in a use-after-free.

Cancel the work from a component remove callback, which runs while priv and the component are still valid.

Fixes 03bbf9f5e4eb ("ASoC: ak4613: call dummy write for PW_MGMT1/3 when Playback")
---
 sound/soc/codecs/ak4613.c | 8 ++++++++
 1 file changed, 8 insertions(+)
sound/soc/codecs/ak4613.c +8 -0
index 0000000..0000000 100644
@@ -807,7 +807,15 @@ static int ak4613_resume(struct snd_soc_component *component)
 	return regcache_sync(regmap);
 }
 
+static void ak4613_remove(struct snd_soc_component *component)
+{
+	struct ak4613_priv *priv = snd_soc_component_get_drvdata(component);
+
+	cancel_work_sync(&priv->dummy_write_work);
+}
+
 static const struct snd_soc_component_driver soc_component_dev_ak4613 = {
+	.remove			= ak4613_remove,
 	.suspend		= ak4613_suspend,
 	.resume			= ak4613_resume,
 	.set_bias_level		= ak4613_set_bias_level,

--
2.43.0

Acked-by on v1 1/1
#1 lore raw

Hi Hyunjung

Quoted 9 lines

ak4613_dai_trigger() schedules priv->dummy_write_work on playback start to issue the PW_MGMT1/PW_MGMT3 dummy writes from a non-atomic context. The worker dereferences ak4613_priv and accesses the component over I2C.

priv is allocated with devm_kzalloc() and the component driver has no remove callback, so nothing cancels the work on unbind. If the device is unbound while the work is still pending, the worker runs after priv has been freed by devres, resulting in a use-after-free.

Quoted 7 lines

Cancel the work from a component remove callback, which runs while priv and the component are still valid.

Fixes 03bbf9f5e4eb ("ASoC: ak4613: call dummy write for PW_MGMT1/3 when Playback")

---

Yes, indeed.

Thank you for your help !!

Best regards
---
Kuninori Morimoto

maintainer
#2 lore raw
In reply to Hyunjung Ko
Quoted 1 line · Hyunjung Ko

ASoC: ak4613: cancel dummy write work on component removal

Applied to

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

Thanks!

[1/1] ASoC: ak4613: cancel dummy write work on component removal

      https://git.kernel.org/broonie/sound/c/c07982ac9dce

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