From: Hongyan Xu <getshell@seu.edu.cn>
To: lgirdwood@gmail.com, broonie@kernel.org
Cc: perex@perex.cz, tiwai@suse.com, matthias.bgg@gmail.com,
angelogioacchino.delregno@collabora.com, phucduc.bui@gmail.com,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, jianhao.xu@seu.edu.cn,
Hongyan Xu <getshell@seu.edu.cn>
Subject: [PATCH] ASoC: mt6359-accdet: manage private workqueues with devres
Date: Mon, 28 Sep 2026 21:40:54 +0800 [thread overview]
Message-ID: <20260928134054.312-1-getshell@seu.edu.cn> (raw)
The threaded jack-detect interrupts queue work on two private
workqueues. Neither queue is destroyed on device removal, so queued
callbacks can retain pointers to devm-allocated state after it is
released. Probe error paths also leak the queues.
Create and initialize both workqueues before requesting interrupts, then
add a managed cleanup action. Since the managed IRQs are acquired
afterwards, devres releases and synchronizes them before draining and
destroying the workqueues on both removal and probe failure.
Fixes: eef07b9e0925 ("ASoC: mediatek: mt6359: add MT6359 accdet jack driver")
Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
---
sound/soc/codecs/mt6359-accdet.c | 50 ++++++++++++++++++--------------
1 file changed, 28 insertions(+), 22 deletions(-)
diff --git a/sound/soc/codecs/mt6359-accdet.c b/sound/soc/codecs/mt6359-accdet.c
index e1190c644021..54ec1c6bd64b 100644
--- a/sound/soc/codecs/mt6359-accdet.c
+++ b/sound/soc/codecs/mt6359-accdet.c
@@ -914,6 +914,14 @@ int mt6359_accdet_enable_jack_detect(struct snd_soc_component *component,
}
EXPORT_SYMBOL_GPL(mt6359_accdet_enable_jack_detect);
+static void mt6359_accdet_destroy_workqueues(void *data)
+{
+ struct mt6359_accdet *priv = data;
+
+ destroy_workqueue(priv->jd_workqueue);
+ destroy_workqueue(priv->accdet_workqueue);
+}
+
static int mt6359_accdet_probe(struct platform_device *pdev)
{
struct mt6359_accdet *priv;
@@ -955,6 +963,26 @@ static int mt6359_accdet_probe(struct platform_device *pdev)
}
mutex_init(&priv->res_lock);
+ priv->accdet_workqueue = create_singlethread_workqueue("accdet");
+ INIT_WORK(&priv->accdet_work, mt6359_accdet_work);
+ if (!priv->accdet_workqueue) {
+ dev_err(&pdev->dev, "Failed to create accdet workqueue\n");
+ return -ENOMEM;
+ }
+
+ priv->jd_workqueue = create_singlethread_workqueue("mt6359_accdet_jd");
+ INIT_WORK(&priv->jd_work, mt6359_accdet_jd_work);
+ if (!priv->jd_workqueue) {
+ dev_err(&pdev->dev, "Failed to create jack detect workqueue\n");
+ destroy_workqueue(priv->accdet_workqueue);
+ return -ENOMEM;
+ }
+
+ ret = devm_add_action_or_reset(&pdev->dev,
+ mt6359_accdet_destroy_workqueues, priv);
+ if (ret)
+ return ret;
+
priv->accdet_irq = platform_get_irq(pdev, 0);
if (priv->accdet_irq >= 0) {
ret = devm_request_threaded_irq(&pdev->dev, priv->accdet_irq,
@@ -1000,22 +1028,6 @@ static int mt6359_accdet_probe(struct platform_device *pdev)
}
}
- priv->accdet_workqueue = create_singlethread_workqueue("accdet");
- INIT_WORK(&priv->accdet_work, mt6359_accdet_work);
- if (!priv->accdet_workqueue) {
- dev_err(&pdev->dev, "Failed to create accdet workqueue\n");
- ret = -1;
- goto err_accdet_wq;
- }
-
- priv->jd_workqueue = create_singlethread_workqueue("mt6359_accdet_jd");
- INIT_WORK(&priv->jd_work, mt6359_accdet_jd_work);
- if (!priv->jd_workqueue) {
- dev_err(&pdev->dev, "Failed to create jack detect workqueue\n");
- ret = -1;
- goto err_eint_wq;
- }
-
platform_set_drvdata(pdev, priv);
ret = devm_snd_soc_register_component(&pdev->dev,
&mt6359_accdet_soc_driver,
@@ -1034,12 +1046,6 @@ static int mt6359_accdet_probe(struct platform_device *pdev)
mt6359_accdet_jack_report(priv);
return 0;
-
-err_eint_wq:
- destroy_workqueue(priv->accdet_workqueue);
-err_accdet_wq:
- dev_err(&pdev->dev, "%s error. now exit.!\n", __func__);
- return ret;
}
static struct platform_driver mt6359_accdet_driver = {
--
2.50.1.windows.1
reply other threads:[~2026-09-28 13:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260928134054.312-1-getshell@seu.edu.cn \
--to=getshell@seu.edu.cn \
--cc=angelogioacchino.delregno@collabora.com \
--cc=broonie@kernel.org \
--cc=jianhao.xu@seu.edu.cn \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-sound@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=perex@perex.cz \
--cc=phucduc.bui@gmail.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®