Re: [PATCH v4 1/5] ASoC: amd: yc: stop the shared IRQ before tearing down platform devices

From: Mukunda,Vijendar

Date: Fri Dec 04 2026 - 00:15:22 EST




On 12/4/26 00:00, MuXian Chen wrote:
[You don't often get email from a18165943161@xxxxxxxxx. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

The IRQ handler dereferences adata->pdev[0], which is freed by
platform_device_unregister(). The IRQ is released only afterwards via
devres, so a spurious interrupt in that window dereferences freed
memory:

BUG: kernel NULL pointer dereference, address: 0x10
RIP: acp6x_irq_handler

Disable the interrupts and release the IRQ before unregistering the
platform devices, and return IRQ_NONE if the drvdata has already been
cleared.

Signed-off-by: MuXian Chen <a18165943161@xxxxxxxxx>
---
sound/soc/amd/yc/pci-acp6x.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/sound/soc/amd/yc/pci-acp6x.c b/sound/soc/amd/yc/pci-acp6x.c
index baf2baeb9952..a961e38c25ef 100644
--- a/sound/soc/amd/yc/pci-acp6x.c
+++ b/sound/soc/amd/yc/pci-acp6x.c
@@ -133,6 +133,8 @@ static irqreturn_t acp6x_irq_handler(int irq, void *dev_id)
val = acp6x_readl(adata->acp6x_base + ACP_EXTERNAL_INTR_STAT);
if (val & BIT(PDM_DMA_STAT)) {
yc_pdm_data = dev_get_drvdata(&adata->pdev[0]->dev);
+ if (!yc_pdm_data)
+ return IRQ_NONE;
ACP uses line-based level-triggered interrupts. ACP_EXTERNAL_INTR_STAT
is a write-1-to-clear register; until that write happens the interrupt
line stays asserted. Returning IRQ_NONE here leaves PDM_DMA_STAT latched
in hardware, the level remains high, and the GIC re-presents the
interrupt immediately. The handler fires again, sees !yc_pdm_data again,
returns IRQ_NONE again -- this spins until the kernel detects "nobody
cared" and hard-disables the IRQ.

The fix must clear the status bit before returning, and return
IRQ_HANDLED since the interrupt did originate from this device:

        if (!yc_pdm_data) {
                acp6x_writel(BIT(PDM_DMA_STAT),
                             adata->acp6x_base +
                             ACP_EXTERNAL_INTR_STAT);
                return IRQ_HANDLED;
        }

acp6x_writel(BIT(PDM_DMA_STAT), adata->acp6x_base + ACP_EXTERNAL_INTR_STAT);
if (yc_pdm_data->capture_stream)
snd_pcm_period_elapsed(yc_pdm_data->capture_stream);
@@ -355,6 +357,13 @@ static void snd_acp6x_remove(struct pci_dev *pci)
int ret, index;

adata = pci_get_drvdata(pci);
+
+ /* Stop the shared IRQ before the platform devices it dereferences
+ * are unregistered.
+ */
+ acp6x_disable_interrupts(adata->acp6x_base);
+ devm_free_irq(&pci->dev, pci->irq, adata);
+

With the remove reordering in place the !yc_pdm_data path in the IRQ
handler is dead code for the teardown race. The sequence is now:

  1. acp6x_disable_interrupts() -- masks HW interrupt generation
  2. devm_free_irq() -- releases the IRQ; synchronize_irq() inside
     ensures any in-flight handler has returned before this call
     returns
  3. platform_device_unregister() -- tears down pdev and clears drvdata

After step 2 no handler can run. drvdata is only cleared in step 3.
So the handler can never observe !yc_pdm_data due to this race.

If the guard is kept as a defensive check for other scenarios (e.g. a
pdev whose probe failed and left drvdata NULL), it still must clear
ACP_EXTERNAL_INTR_STAT before returning, as described in the previous
comment, otherwise a level-triggered IRQ storm results.

devm_free_irq() is not needed here. The IRQ was registered with
devm_request_irq() in snd_acp6x_probe(), so devres already holds the
release action. Calling devm_free_irq() removes that action from the
devres list prematurely and breaks the devres ownership model -- the
IRQ lifecycle should be managed entirely by devres.

acp6x_disable_interrupts() is sufficient to prevent the ACP block from
generating new interrupts before platform_device_unregister() is called.
devres will release the IRQ automatically during the normal unwind.
if (adata->acp6x_audio_mode == ACP6x_PDM_MODE) {
for (index = 0; index < ACP6x_DEVS; index++)
platform_device_unregister(adata->pdev[index]);
--
2.56.1