Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH v3 0/2] ASoC: wm8994: fix the mic detect IRQ handling
@ 2026-12-01 19:25 Arina Kharlamova via B4 Relay
  2026-12-01 19:25 ` [PATCH v3 1/2] ASoC: wm8994: free only the mic detect IRQ that was requested Arina Kharlamova via B4 Relay
  2026-12-01 19:25 ` [PATCH v3 2/2] ASoC: wm8994: free the Mic 2 short IRQ on component remove Arina Kharlamova via B4 Relay
  0 siblings, 2 replies; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:25 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
  Cc: Charles Keepax, patches, linux-sound, Arina Kharlamova

Patch 1 frees only the mic detect interrupt that probe really requested,
and falls back to the internal MIC1_DET interrupt when the platform one
cannot be requested. Patch 2 frees the Mic 2 short interrupt on
component remove, which has been left behind since 9b7c525dfaa9.

I found the first issue with spec2patch. I model-checked the probe and
remove paths of the driver with CBMC against formal specifications of
the kernel APIs it calls. The specifications are checked against the
kernel source, and some of them are proved in Rocq against a
transcription of the kernel code. I noticed the second one while
reworking the first. With the help of an AI coding assistant (Claude);
I reviewed the analysis and the fixes. Compile-tested only, not tested
on hardware.

---
Changes in v3:
- Rebase on broonie/sound for-next; v2 did not apply after
  905d79dffa3e ("ASoC: wm8994: drain delayed works on remove and
  probe error").
- Add patch 2, which frees the Mic 2 short IRQ on component remove.
- Link to v2: https://patch.msgid.link/20261201-s2p-v07-v2-1-80d13362a61b@mbzuai.ac.ae

Changes in v2:
- Fall back to the internal MIC1_DET interrupt when the platform one
  cannot be requested, and free the internal one in remove() and on
  the probe error path only when it was requested (Mark).
- Drop the Reviewed-by from Charles, the patch changed.
- Link to v1: https://patch.msgid.link/20261129-s2p-v07-v1-1-ed39c1bd86de@mbzuai.ac.ae

---
Arina Kharlamova (2):
      ASoC: wm8994: free only the mic detect IRQ that was requested
      ASoC: wm8994: free the Mic 2 short IRQ on component remove

 sound/soc/codecs/wm8994.c | 43 +++++++++++++++++++++++++++++++------------
 1 file changed, 31 insertions(+), 12 deletions(-)
---
base-commit: 20ee6031645dbed8ddf8f4833edf415f3760607f
change-id: 20261129-s2p-v07-785155fb235d

Best regards,
--  
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/2] ASoC: wm8994: free only the mic detect IRQ that was requested
  2026-12-01 19:25 [PATCH v3 0/2] ASoC: wm8994: fix the mic detect IRQ handling Arina Kharlamova via B4 Relay
@ 2026-12-01 19:25 ` Arina Kharlamova via B4 Relay
  2026-12-03 11:23   ` Charles Keepax
  2026-12-01 19:25 ` [PATCH v3 2/2] ASoC: wm8994: free the Mic 2 short IRQ on component remove Arina Kharlamova via B4 Relay
  1 sibling, 1 reply; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:25 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
  Cc: Charles Keepax, patches, linux-sound, Arina Kharlamova

From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

wm8994_component_probe() requests either the platform mic detect
interrupt or the internal MIC1_DET one. When the platform request
fails, it only warns and keeps micdet_irq set, so the probe error path
and remove() call free_irq() on an interrupt this driver never got.
remove() on WM8994 also frees the internal MIC1_DET interrupt when the
platform one is in use, and on WM8958 and WM1811 it never frees the
internal one.

When the platform request fails, clear micdet_irq and fall back to the
internal interrupt. On the probe error path and in remove(), free the
platform interrupt if micdet_irq is set and the internal one otherwise.

Fixes: 9b7c525dfaa9 ("ASoC: Support WM8958 direct microphone detection IRQ")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
 sound/soc/codecs/wm8994.c | 41 +++++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index fcaeff208eb7..20b78dc56fca 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -4288,23 +4288,31 @@ static int wm8994_component_probe(struct snd_soc_component *component)
 
 	switch (control->type) {
 	case WM8994:
-		if (wm8994->micdet_irq)
+		if (wm8994->micdet_irq) {
 			ret = request_threaded_irq(wm8994->micdet_irq, NULL,
 						   wm8994_mic_irq,
 						   IRQF_TRIGGER_RISING |
 						   IRQF_ONESHOT,
 						   "Mic1 detect",
 						   wm8994);
-		 else
+			if (ret != 0) {
+				dev_warn(component->dev,
+					 "Failed to request Mic1 detect IRQ: %d\n",
+					 ret);
+				wm8994->micdet_irq = 0;
+			}
+		}
+
+		if (!wm8994->micdet_irq) {
 			ret = wm8994_request_irq(wm8994->wm8994,
 					WM8994_IRQ_MIC1_DET,
 					wm8994_mic_irq, "Mic 1 detect",
 					wm8994);
-
-		if (ret != 0)
-			dev_warn(component->dev,
-				 "Failed to request Mic1 detect IRQ: %d\n",
-				 ret);
+			if (ret != 0)
+				dev_warn(component->dev,
+					 "Failed to request Mic1 detect IRQ: %d\n",
+					 ret);
+		}
 
 
 		ret = wm8994_request_irq(wm8994->wm8994,
@@ -4344,15 +4352,18 @@ static int wm8994_component_probe(struct snd_soc_component *component)
 						   IRQF_ONESHOT,
 						   "Mic detect",
 						   wm8994);
-			if (ret != 0)
+			if (ret != 0) {
 				dev_warn(component->dev,
 					 "Failed to request Mic detect IRQ: %d\n",
 					 ret);
-		} else {
+				wm8994->micdet_irq = 0;
+			}
+		}
+
+		if (!wm8994->micdet_irq)
 			wm8994_request_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
 					   wm8958_mic_irq, "Mic detect",
 					   wm8994);
-		}
 	}
 
 	switch (control->type) {
@@ -4595,6 +4606,8 @@ err_irq:
 	wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT, wm8994);
 	if (wm8994->micdet_irq)
 		free_irq(wm8994->micdet_irq, wm8994);
+	else
+		wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET, wm8994);
 	for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
 		wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_FLL1_LOCK + i,
 				&wm8994->fll_locked[i]);
@@ -4638,18 +4651,22 @@ static void wm8994_component_remove(struct snd_soc_component *component)
 	case WM8994:
 		if (wm8994->micdet_irq)
 			free_irq(wm8994->micdet_irq, wm8994);
+		else
+			wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
+					wm8994);
 		wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
 				wm8994);
 		wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,
 				wm8994);
-		wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
-				wm8994);
 		break;
 
 	case WM1811:
 	case WM8958:
 		if (wm8994->micdet_irq)
 			free_irq(wm8994->micdet_irq, wm8994);
+		else
+			wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
+					wm8994);
 		break;
 	}
 	if (control->type == WM8994 || control->type == WM1811)

-- 
Git-157)



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] ASoC: wm8994: free the Mic 2 short IRQ on component remove
  2026-12-01 19:25 [PATCH v3 0/2] ASoC: wm8994: fix the mic detect IRQ handling Arina Kharlamova via B4 Relay
  2026-12-01 19:25 ` [PATCH v3 1/2] ASoC: wm8994: free only the mic detect IRQ that was requested Arina Kharlamova via B4 Relay
@ 2026-12-01 19:25 ` Arina Kharlamova via B4 Relay
  2026-12-03 11:28   ` Charles Keepax
  1 sibling, 1 reply; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:25 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
  Cc: Charles Keepax, patches, linux-sound, Arina Kharlamova

From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

On WM8994, wm8994_component_probe() requests the MIC2_SHRT interrupt,
but wm8994_component_remove() does not free it. The handler stays
registered with the driver data as its cookie. A later probe of the
component cannot request the interrupt again, and if the codec driver
is unbound the handler can run with freed driver data.

Free it in remove() like the other microphone interrupts.

Fixes: 9b7c525dfaa9 ("ASoC: Support WM8958 direct microphone detection IRQ")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
 sound/soc/codecs/wm8994.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 20b78dc56fca..6fc42ceeace3 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -4654,6 +4654,8 @@ static void wm8994_component_remove(struct snd_soc_component *component)
 		else
 			wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_DET,
 					wm8994);
+		wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_SHRT,
+				wm8994);
 		wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC2_DET,
 				wm8994);
 		wm8994_free_irq(wm8994->wm8994, WM8994_IRQ_MIC1_SHRT,

-- 
Git-157)



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 1/2] ASoC: wm8994: free only the mic detect IRQ that was requested
  2026-12-01 19:25 ` [PATCH v3 1/2] ASoC: wm8994: free only the mic detect IRQ that was requested Arina Kharlamova via B4 Relay
@ 2026-12-03 11:23   ` Charles Keepax
  0 siblings, 0 replies; 5+ messages in thread
From: Charles Keepax @ 2026-12-03 11:23 UTC (permalink / raw)
  To: arina.kharlamova
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai, patches,
	linux-sound

On Tue, Dec 01, 2026 at 11:25:22PM +0400, Arina Kharlamova via B4 Relay wrote:
> From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> 
> wm8994_component_probe() requests either the platform mic detect
> interrupt or the internal MIC1_DET one. When the platform request
> fails, it only warns and keeps micdet_irq set, so the probe error path
> and remove() call free_irq() on an interrupt this driver never got.
> remove() on WM8994 also frees the internal MIC1_DET interrupt when the
> platform one is in use, and on WM8958 and WM1811 it never frees the
> internal one.
> 
> When the platform request fails, clear micdet_irq and fall back to the
> internal interrupt. On the probe error path and in remove(), free the
> platform interrupt if micdet_irq is set and the internal one otherwise.
> 
> Fixes: 9b7c525dfaa9 ("ASoC: Support WM8958 direct microphone detection IRQ")
> Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> ---

Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Thanks,
Charles

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] ASoC: wm8994: free the Mic 2 short IRQ on component remove
  2026-12-01 19:25 ` [PATCH v3 2/2] ASoC: wm8994: free the Mic 2 short IRQ on component remove Arina Kharlamova via B4 Relay
@ 2026-12-03 11:28   ` Charles Keepax
  0 siblings, 0 replies; 5+ messages in thread
From: Charles Keepax @ 2026-12-03 11:28 UTC (permalink / raw)
  To: arina.kharlamova
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai, patches,
	linux-sound

On Tue, Dec 01, 2026 at 11:25:23PM +0400, Arina Kharlamova via B4 Relay wrote:
> From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> 
> On WM8994, wm8994_component_probe() requests the MIC2_SHRT interrupt,
> but wm8994_component_remove() does not free it. The handler stays
> registered with the driver data as its cookie. A later probe of the
> component cannot request the interrupt again, and if the codec driver
> is unbound the handler can run with freed driver data.
> 
> Free it in remove() like the other microphone interrupts.
> 
> Fixes: 9b7c525dfaa9 ("ASoC: Support WM8958 direct microphone detection IRQ")
> Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> ---

Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Thanks,
Charles

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-03 11:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 19:25 [PATCH v3 0/2] ASoC: wm8994: fix the mic detect IRQ handling Arina Kharlamova via B4 Relay
2026-12-01 19:25 ` [PATCH v3 1/2] ASoC: wm8994: free only the mic detect IRQ that was requested Arina Kharlamova via B4 Relay
2026-12-03 11:23   ` Charles Keepax
2026-12-01 19:25 ` [PATCH v3 2/2] ASoC: wm8994: free the Mic 2 short IRQ on component remove Arina Kharlamova via B4 Relay
2026-12-03 11:28   ` Charles Keepax

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox