From: "Mukunda,Vijendar" <vijendar.mukunda@amd.com>
To: MuXian Chen <a18165943161@gmail.com>,
Venkata Prasad Potturu <venkataprasad.potturu@amd.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
Mario Limonciello <superm1@kernel.org>
Subject: Re: [PATCH v4 1/5] ASoC: amd: yc: stop the shared IRQ before tearing down platform devices
Date: Fri, 4 Dec 2026 10:43:56 +0530 [thread overview]
Message-ID: <db2ec08d-f9af-41d5-a361-208432c201c9@amd.com> (raw)
In-Reply-To: <CA+gYdc3DYp8VYtro_XTCP+C8ps_+r=Gguo5bWahj_Rpi1cmM6Q@mail.gmail.com>
On 12/4/26 00:00, MuXian Chen wrote:
> [You don't often get email from a18165943161@gmail.com. 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@gmail.com>
> ---
> 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
next prev parent reply other threads:[~2026-12-04 5:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 18:30 [PATCH v4 0/5] ASoC: amd: yc: do not bind the ACP when no DMIC is wired MuXian Chen
2026-12-03 18:30 ` [PATCH v4 1/5] ASoC: amd: yc: stop the shared IRQ before tearing down platform devices MuXian Chen
2026-12-04 5:13 ` Mukunda,Vijendar [this message]
2026-12-03 18:30 ` [PATCH v4 2/5] ASoC: amd: yc: share the ACP6x DMIC board list MuXian Chen
2026-12-04 6:07 ` Mukunda,Vijendar
2026-12-05 13:36 ` MuXian Chen
2026-12-03 18:30 ` [PATCH v4 3/5] ASoC: amd: yc: ask the firmware once about the ACP DMIC path MuXian Chen
2026-12-03 18:30 ` [PATCH v4 4/5] ASoC: amd: yc: refuse the ACP function when no DMIC is wired MuXian Chen
2026-12-03 18:30 ` [PATCH v4 5/5] ASoC: amd: yc: allow forcing the ACP DMIC decision MuXian Chen
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=db2ec08d-f9af-41d5-a361-208432c201c9@amd.com \
--to=vijendar.mukunda@amd.com \
--cc=a18165943161@gmail.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=superm1@kernel.org \
--cc=tiwai@suse.com \
--cc=venkataprasad.potturu@amd.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®