* [PATCH] ASoC: imx-pcm-rpmsg: Destroy the workqueue after the component is gone
@ 2026-11-29 7:31 Arina Kharlamova via B4 Relay
2026-11-29 7:37 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-11-29 7:31 UTC (permalink / raw)
To: Shengjiu Wang, Xiubo Li, Fabio Estevam, Nicolin Chen,
Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Frank Li, Sascha Hauer, Pengutronix Kernel Team
Cc: Shengjiu Wang, linux-sound, linuxppc-dev, imx, linux-arm-kernel,
Arina Kharlamova
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
The component is registered with devm_snd_soc_register_component(), but
the workqueue used to send messages to the remote core is destroyed by
hand in remove(). devres unregisters the component only after remove()
has returned, which unbinds the card and closes any stream that is
still open. Stopping and freeing that stream goes through
imx_rpmsg_insert_workqueue() and imx_rpmsg_pcm_hw_free(), which call
queue_work() and flush_workqueue() on the workqueue that was already
destroyed.
Allocate the workqueue with devm_alloc_ordered_workqueue() before the
component is registered, so devres destroys it after the component is
gone, and drop remove() and the error path that are no longer needed.
Fixes: 3c00eceb2a53 ("ASoC: imx-pcm-rpmsg: Add platform driver for audio base on rpmsg")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
Found by checks derived from the spec2patch kernel API specifications,
with the help of an AI coding assistant (Claude); I reviewed the
analysis and the fix.
---
sound/soc/fsl/imx-pcm-rpmsg.c | 36 +++++++++---------------------------
1 file changed, 9 insertions(+), 27 deletions(-)
diff --git a/sound/soc/fsl/imx-pcm-rpmsg.c b/sound/soc/fsl/imx-pcm-rpmsg.c
index 6852f49a18ad..266ce3b3d333 100644
--- a/sound/soc/fsl/imx-pcm-rpmsg.c
+++ b/sound/soc/fsl/imx-pcm-rpmsg.c
@@ -696,7 +696,7 @@ static void imx_rpmsg_pcm_work(struct work_struct *work)
static int imx_rpmsg_pcm_probe(struct platform_device *pdev)
{
struct rpmsg_info *info;
- int ret, i;
+ int i;
info = devm_kzalloc_obj(&pdev->dev, *info);
if (!info)
@@ -707,10 +707,11 @@ static int imx_rpmsg_pcm_probe(struct platform_device *pdev)
info->rpdev = container_of(pdev->dev.parent, struct rpmsg_device, dev);
info->dev = &pdev->dev;
/* Setup work queue */
- info->rpmsg_wq = alloc_ordered_workqueue(info->rpdev->id.name,
- WQ_HIGHPRI |
- WQ_UNBOUND |
- WQ_FREEZABLE);
+ info->rpmsg_wq = devm_alloc_ordered_workqueue(&pdev->dev,
+ info->rpdev->id.name,
+ WQ_HIGHPRI |
+ WQ_UNBOUND |
+ WQ_FREEZABLE);
if (!info->rpmsg_wq) {
dev_err(&pdev->dev, "workqueue create failed\n");
return -ENOMEM;
@@ -740,27 +741,9 @@ static int imx_rpmsg_pcm_probe(struct platform_device *pdev)
spin_lock_init(&info->lock[RX]);
spin_lock_init(&info->wq_lock);
- ret = devm_snd_soc_register_component(&pdev->dev,
- &imx_rpmsg_soc_component,
- NULL, 0);
- if (ret)
- goto fail;
-
- return 0;
-
-fail:
- if (info->rpmsg_wq)
- destroy_workqueue(info->rpmsg_wq);
-
- return ret;
-}
-
-static void imx_rpmsg_pcm_remove(struct platform_device *pdev)
-{
- struct rpmsg_info *info = platform_get_drvdata(pdev);
-
- if (info->rpmsg_wq)
- destroy_workqueue(info->rpmsg_wq);
+ return devm_snd_soc_register_component(&pdev->dev,
+ &imx_rpmsg_soc_component,
+ NULL, 0);
}
static int imx_rpmsg_pcm_runtime_resume(struct device *dev)
@@ -832,7 +815,6 @@ MODULE_DEVICE_TABLE(platform, imx_rpmsg_pcm_id_table);
static struct platform_driver imx_pcm_rpmsg_driver = {
.probe = imx_rpmsg_pcm_probe,
- .remove = imx_rpmsg_pcm_remove,
.id_table = imx_rpmsg_pcm_id_table,
.driver = {
.name = IMX_PCM_DRV_NAME,
---
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
change-id: 20261129-s2p-d102-329143cec2f6
Best regards,
--
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ASoC: imx-pcm-rpmsg: Destroy the workqueue after the component is gone
2026-11-29 7:31 [PATCH] ASoC: imx-pcm-rpmsg: Destroy the workqueue after the component is gone Arina Kharlamova via B4 Relay
@ 2026-11-29 7:37 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29 7:37 UTC (permalink / raw)
To: Arina Kharlamova; +Cc: linux-sound, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] ASoC: fsl_rpmsg: non-sync timer_delete() in
imx_rpmsg_pcm_close() [1]
--
commit d5d77f25c6ce2edfdba6c5018de29919ea8a86b3
Author: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
ASoC: imx-pcm-rpmsg: Destroy the workqueue after the component is gone
This commit switches the rpmsg workqueue allocation in imx_rpmsg_pcm_probe()
to devm_alloc_ordered_workqueue() so that devres destroys the workqueue
after unregistering the ASoC component, and removes the manual cleanup in
imx_rpmsg_pcm_remove() and the probe error path.
> diff --git a/sound/soc/fsl/imx-pcm-rpmsg.c b/sound/soc/fsl/imx-pcm-rpmsg.c
> index 6852f49a18adc..266ce3b3d3335 100644
> --- a/sound/soc/fsl/imx-pcm-rpmsg.c
> +++ b/sound/soc/fsl/imx-pcm-rpmsg.c
> @@ -696,7 +696,7 @@ static void imx_rpmsg_pcm_work(struct work_struct *work)
> static int imx_rpmsg_pcm_probe(struct platform_device *pdev)
> {
> struct rpmsg_info *info;
> - int ret, i;
> + int i;
>
> info = devm_kzalloc_obj(&pdev->dev, *info);
> if (!info)
> @@ -707,10 +707,11 @@ static int imx_rpmsg_pcm_probe(struct platform_device *pdev)
> info->rpdev = container_of(pdev->dev.parent, struct rpmsg_device, dev);
> info->dev = &pdev->dev;
> /* Setup work queue */
> - info->rpmsg_wq = alloc_ordered_workqueue(info->rpdev->id.name,
> - WQ_HIGHPRI |
> - WQ_UNBOUND |
> - WQ_FREEZABLE);
> + info->rpmsg_wq = devm_alloc_ordered_workqueue(&pdev->dev,
> + info->rpdev->id.name,
> + WQ_HIGHPRI |
> + WQ_UNBOUND |
> + WQ_FREEZABLE);
[Severity: Critical]
This problem wasn't introduced by this patch, but can
imx_rpmsg_timer_callback() race with stream teardown in
imx_rpmsg_pcm_close() [1] and queue work onto info->rpmsg_wq after
the workqueue has been flushed?
sound/soc/fsl/imx-pcm-rpmsg.c:imx_rpmsg_pcm_close() {
...
info->send_message(msg, info);
timer_delete(&info->stream_timer[substream->stream].timer);
...
}
Because timer_delete() does not wait for a concurrently running timer
callback to finish, imx_rpmsg_timer_callback() on another CPU can enqueue
new PERIOD_DONE work via imx_rpmsg_insert_workqueue() after
flush_workqueue(info->rpmsg_wq) and after the TX_CLOSE or RX_CLOSE command
has been sent:
CPU0 CPU1
imx_rpmsg_pcm_hw_free()
flush_workqueue(info->rpmsg_wq)
imx_rpmsg_timer_callback()
imx_rpmsg_insert_workqueue()
imx_rpmsg_pcm_close()
info->send_message(msg, info)
timer_delete(...)
If the queued work runs after the stream resources or workqueue are torn
down, this causes a use-after-free. Using timer_delete_sync() before
flushing the workqueue and sending the close message would prevent this
race.
[1] https://sashiko.dev/#/bug/linux-df8136ab-43bf-42a8-9969-f817dabe9dcb
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129-s2p-d102-v1-1-3e8ad20db1b9@mbzuai.ac.ae?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 7:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 7:31 [PATCH] ASoC: imx-pcm-rpmsg: Destroy the workqueue after the component is gone Arina Kharlamova via B4 Relay
2026-11-29 7:37 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox