Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [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

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