Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Charles Keepax" <ckeepax@opensource.cirrus.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v4 1/4] ASoC: SOF: Intel: Add IRQ chip to distribute the SoundWire IRQ
Date: Tue, 24 Nov 2026 16:36:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-231578@kernel.org> (raw)
In-Reply-To: <20261124161001.702882-2-ckeepax@opensource.cirrus.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Medium] ASoC: SOF: Intel: swapped error labels and unset ret in
  hda_dsp_probe()
- [Medium] soundwire: intel_auxdevice: missing free_irq() in
  intel_link_probe()
- [Medium] ASoC: SOF: Intel: undisposed IRQ mapping on hda_sdw_probe()
  failure
- [Medium] soundwire: intel_auxdevice: free_irq() called before
  disabling link IRQs
- [Medium] ASoC: SOF: Intel: race between hda_sdw_exit() and
  hda_dsp_sdw_thread()
- [Low] ASoC: SOF: Intel: missing IRQ_DOMAIN select for
  SND_SOC_SOF_HDA_GENERIC
--

commit 5df72fed7029dd88ed89bc7f4dff6d1d49c10ae2
Author: Charles Keepax <ckeepax@opensource.cirrus.com>

ASoC: SOF: Intel: Add IRQ chip to distribute the SoundWire IRQ

This commit introduces an IRQ domain and chip in the Intel HDA SOF driver
to dispatch the SoundWire interrupt to per-link threaded IRQ handlers.

> diff --git a/drivers/soundwire/intel_auxdevice.c b/drivers/soundwire/intel_auxdevice.c
> index 8bdb2bf1c6446..d84fbe716febc 100644
> --- a/drivers/soundwire/intel_auxdevice.c
> +++ b/drivers/soundwire/intel_auxdevice.c
> @@ -366,6 +366,14 @@ static int intel_link_probe(struct auxiliary_device *auxdev,
>  	/* use generic bandwidth allocation algorithm */
>  	sdw->cdns.bus.compute_params = sdw_compute_params;
>  
> +	ret = request_threaded_irq(sdw->link_res->irq, NULL, sdw_cdns_irq,
> +				   IRQF_SHARED | IRQF_ONESHOT, dev_name(dev),
> +				   cdns);
> +	if (ret) {
> +		dev_err(dev, "failed to request IRQ: %d\n", ret);
> +		return ret;
> +	}
> +
>  	ret = sdw_bus_master_add(bus, dev, dev->fwnode);
>  	if (ret) {
>  		dev_err(dev, "sdw_bus_master_add fail: %d\n", ret);

[Severity: Medium]
If sdw_bus_master_add() fails, does intel_link_probe() return without
calling free_irq(sdw->link_res->irq, cdns)?  Because sdw is allocated with
devm_kzalloc_obj(), probe failure frees cdns while leaving the irqaction
registered on the shared virtual IRQ, causing a use-after-free when the
IRQ fires or is inspected.

> @@ -503,6 +511,8 @@ static void intel_link_remove(struct auxiliary_device *auxdev)
>  	struct sdw_intel *sdw = cdns_to_intel(cdns);
>  	struct sdw_bus *bus = &cdns->bus;
>  
> +	free_irq(sdw->link_res->irq, cdns);
> +
>  	/*
>  	 * Since pm_runtime is already disabled, we don't decrease
>  	 * the refcount when the clock_stop_quirk is

[Severity: Medium]
Should sdw_cdns_enable_interrupt(cdns, false) run before free_irq() here?

sdw_intel_exit() resumes the link and re-enables Cadence interrupts before
removing the auxiliary device, and sdw_cdns_enable_interrupt(cdns, false)
flushes cdns->work before masking CDNS_MCP_INTMASK.  Freeing the IRQ
handler first means any SoundWire transfer in cdns->work (or attach_dwork
and slave teardown before commit "soundwire: intel_auxdevice: Don't
disable IRQs before removing children" later in the series) will never get
its CDNS_MCP_INT_RX_WL completion interrupt and will stall for
CDNS_TX_TIMEOUT, while hardware interrupts remain unmasked without a
handler.

> diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c
> index 9fc95806697e1..06961e5e666ff 100644
> --- a/sound/soc/sof/intel/hda.c
> +++ b/sound/soc/sof/intel/hda.c
> @@ -46,6 +46,22 @@
>  /* platform specific devices */
>  #include "shim.h"
>  
> +static int hda_irq_map(struct irq_domain *h, unsigned int virq, irq_hw_number_t hw)
> +{
> +	struct sof_intel_hda_dev *hdev = h->host_data;
> +
> +	irq_set_chip_data(virq, hdev);
> +	irq_set_chip(virq, &hdev->irq_chip);
> +	irq_set_nested_thread(virq, 1);
> +	irq_set_noprobe(virq);
> +
> +	return 0;
> +}
> +
> +static const struct irq_domain_ops hda_domain_ops = {
> +	.map = hda_irq_map,
> +};

[Severity: Low]
Does SND_SOC_SOF_HDA_GENERIC in sound/soc/sof/intel/Kconfig need to select
IRQ_DOMAIN?  struct irq_domain_ops and irq_domain_create_linear() are only
declared when CONFIG_IRQ_DOMAIN is enabled, which breaks COMPILE_TEST
builds on architectures that do not unconditionally select IRQ_DOMAIN.

> @@ -198,7 +214,7 @@ static int hda_sdw_probe(struct snd_sof_dev *sdev)
>  		if (chip->hw_ip_version >= SOF_INTEL_ACE_3_0)
>  			res.mic_privacy = true;
>  	}
> -	res.irq = sdev->ipc_irq;
> +	res.irq = irq_create_mapping(hdev->domain, HDA_IRQ_SDW);
>  	res.handle = hdev->info.handle;
>  	res.parent = sdev->dev;
>  

[Severity: Medium]
Does this leak the HDA_IRQ_SDW mapping if sdw_intel_probe(&res) fails in
hda_sdw_probe(), or if hda_sdw_startup() later fails in hda_dsp_probe()?

In both cases hda_dsp_probe() unwinds to irq_domain_remove(hdev->domain)
without disposing of the mapping (or calling hda_sdw_exit() on
hda_sdw_startup() failure), triggering the WARN_ON() in
irq_domain_remove() and leaving the leaked irq_desc pointing to freed
hdev->domain and hdev->irq_chip.

> @@ -260,6 +276,8 @@ static int hda_sdw_exit(struct snd_sof_dev *sdev)
>  		sdw_intel_exit(hdev->sdw);
>  	hdev->sdw = NULL;
>  
> +	irq_dispose_mapping(irq_find_mapping(hdev->domain, HDA_IRQ_SDW));
> +
>  	hda_sdw_int_enable(sdev, false);
>  
>  	return 0;
> @@ -307,9 +325,9 @@ static bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev)
>  	return false;
>  }
>  
> -static irqreturn_t hda_dsp_sdw_thread(int irq, void *context)
> +static void hda_dsp_sdw_thread(struct sof_intel_hda_dev *hdev)
>  {
> -	return sdw_intel_thread(irq, context);
> +	handle_nested_irq(irq_find_mapping(hdev->domain, HDA_IRQ_SDW));
>  }

[Severity: Medium]
Can hda_sdw_exit() dispose of the HDA_IRQ_SDW mapping while
hda_dsp_interrupt_thread() is still running?

In hda_dsp_remove(), hda_sdw_exit() runs before SOF_HDA_INT_GLOBAL_EN is
cleared and before free_irq(sdev->ipc_irq, sdev) stops
hda_dsp_interrupt_thread():

CPU0                                CPU1
hda_dsp_remove()                    hda_dsp_interrupt_thread()
  hda_sdw_exit()                      if (hda_dsp_check_sdw_irq(sdev))
    sdw_intel_exit()
      ...
        free_irq(virq, cdns)
    irq_dispose_mapping(virq)
                                        hda_dsp_sdw_thread(hdev)
                                          virq = irq_find_mapping(...)
                                          handle_nested_irq(virq)
                                            <-- virq is 0 or freed desc

Once irq_dispose_mapping() unmaps HDA_IRQ_SDW and frees its irq_desc,
irq_find_mapping() returns 0 (which on x86 resolves to legacy timer IRQ 0
where action->thread_fn is NULL, causing a NULL pointer dereference in
handle_nested_irq()) or races with irq_free_desc().

[ ... ]

> @@ -883,6 +900,14 @@ int hda_dsp_probe(struct snd_sof_dev *sdev)
>  		sdev->ipc_irq = pci->irq;
>  	}
>  
> +	hdev->irq_chip.name = dev_name(sdev->dev);
> +	hdev->domain = irq_domain_create_linear(NULL, HDA_IRQ_COUNT,
> +						&hda_domain_ops, hdev);
> +	if (!hdev->domain) {
> +		dev_err(sdev->dev, "failed to create IRQ domain\n");
> +		goto remove_irq_domain;
> +	}
> +
>  	dev_dbg(sdev->dev, "using IPC IRQ %d\n", sdev->ipc_irq);
>  	ret = request_threaded_irq(sdev->ipc_irq, hda_dsp_interrupt_handler,
>  				   hda_dsp_interrupt_thread,
> @@ -941,6 +966,8 @@ int hda_dsp_probe(struct snd_sof_dev *sdev)
>  free_ipc_irq:
>  	hda_dsp_ctrl_stop_chip(sdev);
>  	free_irq(sdev->ipc_irq, sdev);
> +remove_irq_domain:
> +	irq_domain_remove(hdev->domain);
>  free_irq_vector:
>  	if (sdev->msi_enabled)
>  		pci_free_irq_vectors(pci);

[Severity: Medium]
Are the error labels for irq_domain_create_linear() and
request_threaded_irq() swapped here?

When irq_domain_create_linear() returns NULL, ret is still 0 from
hda_dsp_stream_init(), and jumping to remove_irq_domain passes NULL to
irq_domain_remove(), which immediately dereferences domain->exit.
Conversely, if request_threaded_irq() fails, it jumps to free_irq_vector
and skips remove_irq_domain, leaking hdev->domain.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124161001.702882-1-ckeepax@opensource.cirrus.com?part=1

  reply	other threads:[~2026-11-24 16:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 16:09 [PATCH v4 0/4] Allow SoundWire devices to communicate during remove Charles Keepax
2026-11-24 16:09 ` [PATCH v4 1/4] ASoC: SOF: Intel: Add IRQ chip to distribute the SoundWire IRQ Charles Keepax
2026-11-24 16:36   ` sashiko-bot [this message]
2026-11-24 16:49   ` Pierre-Louis Bossart
2026-11-24 17:06     ` Charles Keepax
2026-11-24 16:09 ` [PATCH v4 2/4] soundwire: bus: Don't unassign dev_num before unregistering device Charles Keepax
2026-11-24 16:10 ` [PATCH v4 3/4] soundwire: bus: Expose a helper to remove devices from the bus Charles Keepax
2026-11-24 16:29   ` sashiko-bot
2026-11-24 16:10 ` [PATCH v4 4/4] soundwire: intel_auxdevice: Don't disable IRQs before removing children Charles Keepax
2026-11-24 16:27   ` sashiko-bot

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=sashiko-outbox-231578@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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