* [PATCH 0/4] soundwire: qcom: controller lifecycle fixes on unbind/reprobe
@ 2026-12-03 7:41 Ajay Kumar Nandam
2026-12-03 7:41 ` [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live Ajay Kumar Nandam
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Ajay Kumar Nandam @ 2026-12-03 7:41 UTC (permalink / raw)
To: Srinivas Kandagatla, Vinod Koul, Bard Liao, Pierre-Louis Bossart
Cc: linux-arm-msm, linux-sound, Ajay Kumar Nandam, Ravi Hothi
This series fixes four Qualcomm SoundWire controller lifecycle issues
seen while testing recovery after an ADSP restart. The problems are
not specific to an ADSP restart and can happen whenever a controller is
unbound and probed again.
1. Runtime resume/suspend can access controller registers after the
interface-clock provider goes away. Skip the access when the clock
is not live.
2. The default/primary remove path does not balance runtime PM and may
disable an interface clock runtime suspend already disabled.
Balance runtime PM and only release an active clock.
3. IRQ mappings obtained through of_irq_get() are not disposed on
probe failure or controller removal. Dispose each mapping with the
controller instance.
4. A peripheral can remain attached with its previous device number
across controller reprobe and therefore never generate a new attach
event. Reconcile such peripherals after normal enumeration.
Each patch fixes a separate controller lifetime issue and does not
depend on the other patches.
Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
---
Ajay Kumar Nandam (4):
soundwire: qcom: don't touch registers when the iface clock is not live
soundwire: qcom: disable runtime PM on controller unbind
soundwire: qcom: dispose IRQ mappings on controller unbind
soundwire: qcom: reconcile a retained peripheral after controller re-probe
drivers/soundwire/qcom.c | 111 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 108 insertions(+), 3 deletions(-)
---
base-commit: d138596e9f822033490b2e577ec2ea64f2aa246c
change-id: 20261203-ak-gt-soundwire-qcom-mmrole-rework-49eeac51ddaf
Best regards,
--
Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live
2026-12-03 7:41 [PATCH 0/4] soundwire: qcom: controller lifecycle fixes on unbind/reprobe Ajay Kumar Nandam
@ 2026-12-03 7:41 ` Ajay Kumar Nandam
2026-12-03 8:09 ` sashiko-bot
2026-12-03 7:41 ` [PATCH 2/4] soundwire: qcom: disable runtime PM on controller unbind Ajay Kumar Nandam
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Ajay Kumar Nandam @ 2026-12-03 7:41 UTC (permalink / raw)
To: Srinivas Kandagatla, Vinod Koul, Bard Liao, Pierre-Louis Bossart
Cc: linux-arm-msm, linux-sound, Ajay Kumar Nandam, Ravi Hothi
swrm_runtime_resume() and swrm_runtime_suspend() enable or disable the
interface clock before accessing controller registers. The clock's
parent provider can go away while the controller still holds a valid
struct clk.
During an ADSP restart, this can happen when the provider disappears
before the SoundWire controller finishes its runtime-PM transition.
Check that the interface clock still has a parent before touching the
clock or the registers it gates, and treat a missing parent as a
no-op. Do this check before the multi-master role is handled, so it
covers the dependent role's early-return path as well.
Co-developed-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
---
drivers/soundwire/qcom.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index ad28a0fa345d..bd44d8913267 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -2076,11 +2076,20 @@ static void qcom_swrm_remove(struct platform_device *pdev)
clk_disable_unprepare(ctrl->hclk);
}
+/* Check that the interface clock provider is still present. */
+static bool swrm_iface_clk_live(struct qcom_swrm_ctrl *ctrl)
+{
+ return !IS_ERR_OR_NULL(clk_get_parent(ctrl->hclk));
+}
+
static int __maybe_unused swrm_runtime_resume(struct device *dev)
{
struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev);
int ret;
+ if (!swrm_iface_clk_live(ctrl))
+ return 0;
+
/* no bus of its own; the primary restarts the link */
if (ctrl->mm_role == QCOM_SWRM_MM_DEPENDENT)
return clk_prepare_enable(ctrl->hclk);
@@ -2159,6 +2168,9 @@ static int __maybe_unused swrm_runtime_suspend(struct device *dev)
struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev);
int ret;
+ if (!swrm_iface_clk_live(ctrl))
+ return 0;
+
/* the primary has already stopped the bus clock */
if (ctrl->mm_role == QCOM_SWRM_MM_DEPENDENT) {
clk_disable_unprepare(ctrl->hclk);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/4] soundwire: qcom: disable runtime PM on controller unbind
2026-12-03 7:41 [PATCH 0/4] soundwire: qcom: controller lifecycle fixes on unbind/reprobe Ajay Kumar Nandam
2026-12-03 7:41 ` [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live Ajay Kumar Nandam
@ 2026-12-03 7:41 ` Ajay Kumar Nandam
2026-12-03 8:08 ` sashiko-bot
2026-12-03 7:41 ` [PATCH 3/4] soundwire: qcom: dispose IRQ mappings " Ajay Kumar Nandam
2026-12-03 7:41 ` [PATCH 4/4] soundwire: qcom: reconcile a retained peripheral after controller re-probe Ajay Kumar Nandam
3 siblings, 1 reply; 9+ messages in thread
From: Ajay Kumar Nandam @ 2026-12-03 7:41 UTC (permalink / raw)
To: Srinivas Kandagatla, Vinod Koul, Bard Liao, Pierre-Louis Bossart
Cc: linux-arm-msm, linux-sound, Ajay Kumar Nandam, Ravi Hothi
qcom_swrm_remove() does not balance the pm_runtime_enable() done in
probe() for the default and primary roles. It also disables the
interface clock even when runtime suspend already disabled it.
During an ADSP restart, the controller can be removed while runtime
suspended. This can leave runtime PM enabled for the old controller
instance, or disable the interface clock twice.
The dependent remove path already handles both cases. Do the same
for the default and primary paths by disabling runtime PM before
tearing down the bus, and only releasing the clock when it is still
active.
Co-developed-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
---
drivers/soundwire/qcom.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index bd44d8913267..d23d6ec56fed 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -2051,6 +2051,10 @@ static void qcom_swrm_remove(struct platform_device *pdev)
return;
}
+ /* Balance probe()'s pm_runtime_enable() before tearing the bus down. */
+ pm_runtime_disable(&pdev->dev);
+ pm_runtime_dont_use_autosuspend(&pdev->dev);
+
/* delete bus before dropping peer_ctrl; in-flight ops deref it */
sdw_bus_master_delete(&ctrl->bus);
@@ -2073,7 +2077,9 @@ static void qcom_swrm_remove(struct platform_device *pdev)
ctrl->peer_ctrl = NULL;
}
- clk_disable_unprepare(ctrl->hclk);
+ /* Skip if runtime suspend already dropped the clock. */
+ if (!pm_runtime_status_suspended(&pdev->dev))
+ clk_disable_unprepare(ctrl->hclk);
}
/* Check that the interface clock provider is still present. */
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/4] soundwire: qcom: dispose IRQ mappings on controller unbind
2026-12-03 7:41 [PATCH 0/4] soundwire: qcom: controller lifecycle fixes on unbind/reprobe Ajay Kumar Nandam
2026-12-03 7:41 ` [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live Ajay Kumar Nandam
2026-12-03 7:41 ` [PATCH 2/4] soundwire: qcom: disable runtime PM on controller unbind Ajay Kumar Nandam
@ 2026-12-03 7:41 ` Ajay Kumar Nandam
2026-12-03 7:55 ` sashiko-bot
2026-12-03 7:41 ` [PATCH 4/4] soundwire: qcom: reconcile a retained peripheral after controller re-probe Ajay Kumar Nandam
3 siblings, 1 reply; 9+ messages in thread
From: Ajay Kumar Nandam @ 2026-12-03 7:41 UTC (permalink / raw)
To: Srinivas Kandagatla, Vinod Koul, Bard Liao, Pierre-Louis Bossart
Cc: linux-arm-msm, linux-sound, Ajay Kumar Nandam, Ravi Hothi
of_irq_get() creates an irqdomain mapping that persists until it is
explicitly disposed; devm_request_threaded_irq() only manages the
interrupt handler, not that mapping.
During an ADSP restart, repeated controller remove/probe cycles leave
mappings from earlier controller instances behind, on both the
primary and wake IRQs.
Add a devm_add_action_or_reset() disposal action right after each
successful of_irq_get(), so a later probe failure or a normal
remove() disposes the mapping exactly once.
Also reject a 0 return from the primary of_irq_get(): of_irq_get()
never returns 0 for a valid IRQ, and the code was treating it as one.
Co-developed-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
---
drivers/soundwire/qcom.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index d23d6ec56fed..b1656412ffab 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -1825,6 +1825,12 @@ static int qcom_swrm_multi_master_setup(struct qcom_swrm_ctrl *ctrl)
return ret;
}
+/* devm_request_threaded_irq() frees the handler, not this mapping. */
+static void qcom_swrm_dispose_irq_mapping(void *data)
+{
+ irq_dispose_mapping((unsigned long)data);
+}
+
static int qcom_swrm_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -1879,11 +1885,16 @@ static int qcom_swrm_probe(struct platform_device *pdev)
}
ctrl->irq = of_irq_get(dev->of_node, 0);
- if (ctrl->irq < 0) {
- ret = ctrl->irq;
+ if (ctrl->irq <= 0) {
+ ret = ctrl->irq ? : -EINVAL;
goto err_init;
}
+ ret = devm_add_action_or_reset(dev, qcom_swrm_dispose_irq_mapping,
+ (void *)(unsigned long)ctrl->irq);
+ if (ret)
+ goto err_init;
+
ctrl->hclk = devm_clk_get(dev, "iface");
if (IS_ERR(ctrl->hclk)) {
ret = dev_err_probe(dev, PTR_ERR(ctrl->hclk), "unable to get iface clock\n");
@@ -1950,6 +1961,11 @@ static int qcom_swrm_probe(struct platform_device *pdev)
ctrl->wake_irq = of_irq_get(dev->of_node, 1);
if (ctrl->wake_irq > 0) {
+ ret = devm_add_action_or_reset(dev, qcom_swrm_dispose_irq_mapping,
+ (void *)(unsigned long)ctrl->wake_irq);
+ if (ret)
+ goto err_clk;
+
ret = devm_request_threaded_irq(dev, ctrl->wake_irq, NULL,
qcom_swrm_wake_irq_handler,
IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/4] soundwire: qcom: reconcile a retained peripheral after controller re-probe
2026-12-03 7:41 [PATCH 0/4] soundwire: qcom: controller lifecycle fixes on unbind/reprobe Ajay Kumar Nandam
` (2 preceding siblings ...)
2026-12-03 7:41 ` [PATCH 3/4] soundwire: qcom: dispose IRQ mappings " Ajay Kumar Nandam
@ 2026-12-03 7:41 ` Ajay Kumar Nandam
2026-12-03 8:08 ` sashiko-bot
3 siblings, 1 reply; 9+ messages in thread
From: Ajay Kumar Nandam @ 2026-12-03 7:41 UTC (permalink / raw)
To: Srinivas Kandagatla, Vinod Koul, Bard Liao, Pierre-Louis Bossart
Cc: linux-arm-msm, linux-sound, Ajay Kumar Nandam, Ravi Hothi
Normal SoundWire enumeration binds a peripheral through an attach
transition: the peripheral asserts an attach interrupt, and the
controller assigns it a device number and binds it. A peripheral
that keeps its previously assigned device number across a
controller unbind/rebind, because it stayed attached throughout,
never generates that transition, so it is left unbound even though
it is physically present.
During an ADSP restart, the controller can reprobe while the
peripheral remains attached with its previous device number.
Because there is no new attach transition, normal enumeration
leaves it unbound.
After the bounded enumeration wait in probe(), check each attached
device-number slot's SCP DevID for a uniquely matching unbound
slave, and bind it through the same device-number/status path the
attach interrupt uses. An already-bound peripheral is left
unchanged.
Disable the status interrupt while reconciling the slot state,
since this reads and can update the same slot-status state the
threaded status interrupt handler writes.
This applies to the default and primary roles, the only roles that
register a bus and reach this point in probe(); the dependent role
returns earlier and never reaches it.
Co-developed-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
---
drivers/soundwire/qcom.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index b1656412ffab..95d3e4ecd2a9 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -772,6 +772,73 @@ static int qcom_swrm_enumerate(struct sdw_bus *bus)
return 0;
}
+/* Caller must disable the status IRQ while updating slot state. */
+static void swrm_reconcile_slaves(struct qcom_swrm_ctrl *ctrl)
+{
+ struct sdw_bus *bus = &ctrl->bus;
+ u32 slv_status_raw = 0;
+ int i;
+
+ ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &slv_status_raw);
+
+ for (i = 1; i <= SDW_MAX_DEVICES; i++) {
+ u32 slot_status = (slv_status_raw >> (i * SWRM_MCP_SLV_STATUS_SZ)) &
+ SWRM_MCP_SLV_STATUS_MASK;
+ u8 buf[SDW_NUM_DEV_ID_REGISTERS] = {0};
+ struct sdw_slave *slave, *match = NULL;
+ struct sdw_slave_id id;
+ int nmatch = 0, n, all_ok = 1;
+ u32 recheck_raw = 0, recheck_slot;
+ u64 addr;
+
+ if (slot_status != SDW_SLAVE_ATTACHED)
+ continue;
+
+ mutex_lock(&bus->msg_lock);
+ for (n = 0; n < SDW_NUM_DEV_ID_REGISTERS; n++) {
+ if (qcom_swrm_cmd_fifo_rd_cmd(ctrl, i, SDW_SCP_DEVID_0 + n,
+ 1, &buf[n]) != SDW_CMD_OK)
+ all_ok = 0;
+ }
+ mutex_unlock(&bus->msg_lock);
+ if (!all_ok)
+ continue;
+
+ /* Match the DevID byte order used by the generic enumerator. */
+ addr = buf[5] | (buf[4] << 8) | (buf[3] << 16) |
+ ((u64)buf[2] << 24) | ((u64)buf[1] << 32) |
+ ((u64)buf[0] << 40);
+ sdw_extract_slave_id(bus, addr, &id);
+
+ /* Reconcile only a unique DevID match. */
+ list_for_each_entry(slave, &bus->slaves, node) {
+ if (sdw_compare_devid(slave, id) != 0)
+ continue;
+ nmatch++;
+ if (!match)
+ match = slave;
+ }
+ if (nmatch != 1)
+ continue;
+
+ if (!(match->dev_num == 0 && match->status == SDW_SLAVE_UNATTACHED))
+ continue;
+
+ /* Re-check the slot after the SCP reads. */
+ ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &recheck_raw);
+ recheck_slot = (recheck_raw >> (i * SWRM_MCP_SLV_STATUS_SZ)) &
+ SWRM_MCP_SLV_STATUS_MASK;
+ if (recheck_slot != SDW_SLAVE_ATTACHED ||
+ match->dev_num != 0 ||
+ match->status != SDW_SLAVE_UNATTACHED)
+ continue;
+
+ qcom_swrm_set_slave_dev_num(bus, match, i);
+ qcom_swrm_get_device_status(ctrl);
+ sdw_handle_slave_status(&ctrl->bus, ctrl->status);
+ }
+}
+
static irqreturn_t qcom_swrm_wake_irq_handler(int irq, void *dev_id)
{
struct qcom_swrm_ctrl *ctrl = dev_id;
@@ -2015,6 +2082,10 @@ static int qcom_swrm_probe(struct platform_device *pdev)
wait_for_completion_timeout(&ctrl->enumeration,
msecs_to_jiffies(TIMEOUT_MS));
+ /* Serialize reconciliation with the status handler. */
+ disable_irq(ctrl->irq);
+ swrm_reconcile_slaves(ctrl);
+ enable_irq(ctrl->irq);
ret = qcom_swrm_register_dais(ctrl);
if (ret)
goto err_master_add;
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] soundwire: qcom: dispose IRQ mappings on controller unbind
2026-12-03 7:41 ` [PATCH 3/4] soundwire: qcom: dispose IRQ mappings " Ajay Kumar Nandam
@ 2026-12-03 7:55 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-03 7:55 UTC (permalink / raw)
To: Ajay Kumar Nandam; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] soundwire: qcom: missing Fixes trailers for IRQ mapping leak and
zero check
--
commit 480b8eb6de830f6687e1b801b382d8876984d659
Author: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
> soundwire: qcom: dispose IRQ mappings on controller unbind
>
> of_irq_get() creates an irqdomain mapping that persists until it is
> explicitly disposed; devm_request_threaded_irq() only manages the
> interrupt handler, not that mapping.
>
> During an ADSP restart, repeated controller remove/probe cycles leave
> mappings from earlier controller instances behind, on both the
> primary and wake IRQs.
>
> Add a devm_add_action_or_reset() disposal action right after each
> successful of_irq_get(), so a later probe failure or a normal
> remove() disposes the mapping exactly once.
>
> Also reject a 0 return from the primary of_irq_get(): of_irq_get()
> never returns 0 for a valid IRQ, and the code was treating it as one.
>
> Co-developed-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
> Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
> Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
[Severity: Low]
This looks like a bug fix for the primary and wake IRQ mapping leaks and
the missing zero check on the primary of_irq_get() return. Should this
include:
Fixes: 02efb49aa805 ("soundwire: qcom: add support for SoundWire controller")
Fixes: 04d46a7b3837 ("soundwire: qcom: add in-band wake up interrupt support")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-0-046ce68c8b0e@oss.qualcomm.com?part=3
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/4] soundwire: qcom: disable runtime PM on controller unbind
2026-12-03 7:41 ` [PATCH 2/4] soundwire: qcom: disable runtime PM on controller unbind Ajay Kumar Nandam
@ 2026-12-03 8:08 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-03 8:08 UTC (permalink / raw)
To: Ajay Kumar Nandam; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] soundwire: qcom: unclocked peer MMIO writes in
qcom_swrm_remove()
- [Medium] soundwire: qcom: hclk disable check in qcom_swrm_remove()
desyncs on dead clk
- [Medium] soundwire: qcom: hclk refcount mismatch in qcom_swrm_remove()
on ADSP restart
- [Medium] soundwire: qcom: pm_runtime_disable() before teardown allows
unclocked MMIO
- [Low] soundwire: qcom: missing Fixes trailer for commit 74e79da9fd46
--
commit b31693c684ab42b0a6bf2fee75c49470bacdd1ea
Author: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
> soundwire: qcom: disable runtime PM on controller unbind
>
> qcom_swrm_remove() does not balance the pm_runtime_enable() done in
> probe() for the default and primary roles. It also disables the
> interface clock even when runtime suspend already disabled it.
>
> During an ADSP restart, the controller can be removed while runtime
> suspended. This can leave runtime PM enabled for the old controller
> instance, or disable the interface clock twice.
>
> The dependent remove path already handles both cases. Do the same
> for the default and primary paths by disabling runtime PM before
> tearing down the bus, and only releasing the clock when it is still
> active.
>
> Co-developed-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
> Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
> Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
[Severity: Low]
This fixes missing runtime PM teardown and an unbalanced
clk_disable_unprepare() in qcom_swrm_remove(). Should this include:
Fixes: 74e79da9fd46 ("soundwire: qcom: add runtime pm support")
> diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
> index bd44d89132675..d23d6ec56fed9 100644
> --- a/drivers/soundwire/qcom.c
> +++ b/drivers/soundwire/qcom.c
> @@ -2051,6 +2051,10 @@ static void qcom_swrm_remove(struct platform_device *pdev)
> return;
> }
>
> + /* Balance probe()'s pm_runtime_enable() before tearing the bus down. */
> + pm_runtime_disable(&pdev->dev);
> + pm_runtime_dont_use_autosuspend(&pdev->dev);
> +
> /* delete bus before dropping peer_ctrl; in-flight ops deref it */
> sdw_bus_master_delete(&ctrl->bus);
[Severity: Medium]
Can disabling runtime PM before sdw_bus_master_delete() and ASoC DAI
teardown allow unclocked MMIO accesses from swrm_reg_show() or
qcom_swrm_startup()?
If &pdev->dev enters qcom_swrm_remove() runtime-suspended with ctrl->hclk
gated off (for example when autosuspend_delay_ms is 0 so
__device_release_driver()'s pm_runtime_put_sync() suspends synchronously),
pm_runtime_disable() makes subsequent pm_runtime_get_sync(ctrl->dev) calls
return -EACCES without enabling ctrl->hclk.
CPU0 CPU1
qcom_swrm_remove()
pm_runtime_disable(&pdev->dev)
qcom_swrm_startup()
pm_runtime_get_sync() -> -EACCES
/* ignores -EACCES, returns 0 */
qcom_swrm_shutdown()
swrm_wait_for_wr_fifo_done()
ctrl->reg_read() <-- unclocked MMIO
sdw_bus_master_delete()
...
devres_release_all()
Both swrm_reg_show() and qcom_swrm_startup() treat -EACCES from
pm_runtime_get_sync() as success, so a concurrent debugfs read before
sdw_bus_debugfs_exit() or a DAI callback before the devm ASoC component is
unregistered can issue unclocked MMIO accesses and cause an SError or bus
hang.
> @@ -2073,7 +2077,9 @@ static void qcom_swrm_remove(struct platform_device *pdev)
> ctrl->peer_ctrl = NULL;
> }
[Severity: High]
Can the primary remove path still issue unclocked MMIO writes to the
dependent peer when the interface clock provider is gone?
Just above these lines, qcom_swrm_remove() resumes the dependent peer and
writes its registers whenever pm_runtime_resume_and_get() succeeds:
drivers/soundwire/qcom.c:qcom_swrm_remove() {
...
ret = pm_runtime_resume_and_get(peer->dev);
if (ret < 0) {
dev_err(&pdev->dev, "peer resume failed on remove: %d\n", ret);
} else {
peer->reg_write(peer,
peer->reg_layout[SWRM_REG_INTERRUPT_CPU_EN], 0);
/* disable peer SWRM; releases shared SWR_CLK */
peer->reg_write(peer, SWRM_COMP_CFG_ADDR, 0);
pm_runtime_put(peer->dev);
}
...
}
After commit "soundwire: qcom: don't touch registers when the iface clock is
not live", swrm_runtime_resume() returns 0 without calling
clk_prepare_enable(peer->hclk) when swrm_iface_clk_live(peer) is false.
During an ADSP restart, pm_runtime_resume_and_get(peer->dev) then returns 0
while peer->hclk is dead and gated, so qcom_swrm_remove() writes to
unclocked peer MMIO registers and risks an SError or bus hang. Checking
swrm_iface_clk_live(peer) before the peer->reg_write() calls would avoid
this.
>
> - clk_disable_unprepare(ctrl->hclk);
> + /* Skip if runtime suspend already dropped the clock. */
> + if (!pm_runtime_status_suspended(&pdev->dev))
> + clk_disable_unprepare(ctrl->hclk);
> }
[Severity: Medium]
Does checking pm_runtime_status_suspended(&pdev->dev) still match whether
ctrl->hclk is prepared and enabled after commit "soundwire: qcom: don't
touch registers when the iface clock is not live"?
When swrm_iface_clk_live(ctrl) is false, both swrm_runtime_resume() and
swrm_runtime_suspend() return 0 without calling clk_prepare_enable() or
clk_disable_unprepare(), so the runtime PM core still transitions
runtime_status between RPM_SUSPENDED and RPM_ACTIVE while ctrl->hclk is
left unchanged. That can either leak the ctrl->hclk prepare/enable count
(if runtime suspend returns 0 on a dead clock before remove) or disable
ctrl->hclk when the parent provider is already gone. Tracking whether
ctrl->hclk is enabled in driver state would avoid relying on runtime PM
status here.
[Severity: Medium]
Can this still call clk_disable_unprepare(ctrl->hclk) twice during an ADSP
restart on a runtime-suspended default or primary controller?
Before calling device_remove() -> qcom_swrm_remove(),
__device_release_driver() calls pm_runtime_get_sync(dev) followed by
pm_runtime_put_sync(dev). If the controller was already RPM_SUSPENDED
(ctrl->hclk count 0) and the clock parent disappeared, pm_runtime_get_sync()
invokes swrm_runtime_resume(), which returns 0 without enabling ctrl->hclk
and transitions runtime_status to RPM_ACTIVE. Because default and primary
roles enable a 3000 ms autosuspend delay in qcom_swrm_probe(),
pm_runtime_put_sync() only arms the autosuspend timer and leaves
runtime_status at RPM_ACTIVE, so qcom_swrm_remove() calls
clk_disable_unprepare(ctrl->hclk) a second time and triggers
clk_core_disable()/clk_core_unprepare() warnings.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-0-046ce68c8b0e@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/4] soundwire: qcom: reconcile a retained peripheral after controller re-probe
2026-12-03 7:41 ` [PATCH 4/4] soundwire: qcom: reconcile a retained peripheral after controller re-probe Ajay Kumar Nandam
@ 2026-12-03 8:08 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-03 8:08 UTC (permalink / raw)
To: Ajay Kumar Nandam; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] soundwire: qcom: swrm_reconcile_slaves() clobbers
ctrl->slave_status
- [High] soundwire: qcom: missing clock_stop_not_supported update on
reconcile
- [Medium] soundwire: qcom: swrm_reconcile_slaves() skips alerting
peripherals
- [Medium] soundwire: qcom: swrm_reconcile_slaves() may assign duplicate
dev_num
- [Low] soundwire: qcom: redundant reads and checks in
swrm_reconcile_slaves()
- [Low] soundwire: qcom: missing break on FIFO read error in
swrm_reconcile_slaves()
- [Low] soundwire: qcom: swrm_reconcile_slaves() reads DevIDs of
already-bound slaves
--
commit b4c7c081a46d27523980bc34cc988e2f4829cddd
Author: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
soundwire: qcom: reconcile a retained peripheral after controller re-probe
This commit adds swrm_reconcile_slaves() to scan attached device-number
slots after the enumeration wait in qcom_swrm_probe() and bind any
uniquely matching unbound peripheral that retained its device number
across a controller re-probe. It disables ctrl->irq while reconciling
slot state.
> diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
> index b1656412ffab1..95d3e4ecd2a9c 100644
> --- a/drivers/soundwire/qcom.c
> +++ b/drivers/soundwire/qcom.c
> @@ -772,6 +772,73 @@ static int qcom_swrm_enumerate(struct sdw_bus *bus)
> return 0;
> }
>
> +/* Caller must disable the status IRQ while updating slot state. */
> +static void swrm_reconcile_slaves(struct qcom_swrm_ctrl *ctrl)
> +{
> + struct sdw_bus *bus = &ctrl->bus;
> + u32 slv_status_raw = 0;
> + int i;
> +
> + ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &slv_status_raw);
> +
> + for (i = 1; i <= SDW_MAX_DEVICES; i++) {
> + u32 slot_status = (slv_status_raw >> (i * SWRM_MCP_SLV_STATUS_SZ)) &
> + SWRM_MCP_SLV_STATUS_MASK;
> + u8 buf[SDW_NUM_DEV_ID_REGISTERS] = {0};
> + struct sdw_slave *slave, *match = NULL;
> + struct sdw_slave_id id;
> + int nmatch = 0, n, all_ok = 1;
> + u32 recheck_raw = 0, recheck_slot;
> + u64 addr;
> +
> + if (slot_status != SDW_SLAVE_ATTACHED)
> + continue;
[Severity: Medium]
Can a retained peripheral reporting SDW_SLAVE_ALERT be skipped here and
left permanently unbound?
Unlike a freshly reset peripheral, one that stayed attached across a
controller re-probe keeps its previously programmed SDW_SCP_INTMASK1
(for example bus clash and parity enabled by wsa881x_probe()). If an
interrupt latches during an ADSP restart, SWRM_MCP_SLV_STATUS reports
SDW_SLAVE_ALERT instead of SDW_SLAVE_ATTACHED, so this check, the
recheck below, and qcom_swrm_set_slave_dev_num() all skip it.
Once enable_irq() runs, sdw_handle_slave_status() ignores unassigned
slots, so the alert is never cleared and the peripheral never returns
to SDW_SLAVE_ATTACHED.
> +
> + mutex_lock(&bus->msg_lock);
> + for (n = 0; n < SDW_NUM_DEV_ID_REGISTERS; n++) {
> + if (qcom_swrm_cmd_fifo_rd_cmd(ctrl, i, SDW_SCP_DEVID_0 + n,
> + 1, &buf[n]) != SDW_CMD_OK)
> + all_ok = 0;
> + }
> + mutex_unlock(&bus->msg_lock);
> + if (!all_ok)
> + continue;
[Severity: Low]
Does this execute six sleeping FIFO reads for every already-bound
peripheral on normal boots?
Each qcom_swrm_cmd_fifo_rd_cmd() sleeps at least 350 us via
usleep_range(), adding over 2 ms per already-bound peripheral across
synchronous controller probes while ctrl->irq is disabled, only to
discard the result below. Checking up front whether bus->slaves has
any unbound entry, and skipping slots already owned by a slave's
dev_num, would avoid this bus I/O when enumeration already succeeded.
[Severity: Low]
Should this loop break on the first qcom_swrm_cmd_fifo_rd_cmd() failure?
Because !all_ok discards buf[] right after unlocking bus->msg_lock,
continuing issues up to five extra failing reads. On a read FIFO
underflow, swrm_wait_for_rd_fifo_avail() sleeps ~15.5 ms per call,
turning one timeout into ~95 ms per failing slot with ctrl->irq
disabled.
[ ... ]
> + if (!(match->dev_num == 0 && match->status == SDW_SLAVE_UNATTACHED))
> + continue;
> +
> + /* Re-check the slot after the SCP reads. */
> + ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &recheck_raw);
> + recheck_slot = (recheck_raw >> (i * SWRM_MCP_SLV_STATUS_SZ)) &
> + SWRM_MCP_SLV_STATUS_MASK;
> + if (recheck_slot != SDW_SLAVE_ATTACHED ||
> + match->dev_num != 0 ||
> + match->status != SDW_SLAVE_UNATTACHED)
> + continue;
[Severity: Low]
Are the match->dev_num and match->status checks here redundant?
The same condition was just verified above with only ctrl->reg_read()
in between while ctrl->irq is disabled, so nothing can mutate those
fields here. Skipping already-bound slots before the FIFO reads and
breaking on the first read error would also avoid redundant bus traffic
and repeated error logs.
> +
> + qcom_swrm_set_slave_dev_num(bus, match, i);
[Severity: Medium]
Can this assign a duplicate dev_num if another slave in bus->slaves
already owns slot i?
When a peripheral detaches, sdw_modify_slave_status() marks it
SDW_SLAVE_UNATTACHED without clearing its dev_num. If slave A attached
on slot i during the enumeration wait, detached, and hardware
auto-enumeration reused slot i for unbound slave B before
reconciliation, this assigns dev_num = i to slave B as well.
Because sdw_get_slave() returns the first matching entry in
bus->slaves, subsequent status transitions, alerts, and initialization
for slot i are misdirected to slave A while slave B remains stuck
unattached. Checking whether any slave in bus->slaves already has
dev_num == i before binding would prevent this.
[Severity: High]
Does binding match here miss updating ctrl->clock_stop_not_supported?
In qcom_swrm_enumerate(), binding a slave with prop.clk_stop_mode1 set
(such as wsa881x_probe()) sets ctrl->clock_stop_not_supported = true.
Leaving it false here causes swrm_runtime_suspend() and
swrm_runtime_resume() to run SoundWire clock-stop sequences instead of
performing SWRM_COMP_SW_RESET and re-initializing the controller when
the 3-second autosuspend timer fires.
> + qcom_swrm_get_device_status(ctrl);
> + sdw_handle_slave_status(&ctrl->bus, ctrl->status);
[Severity: High]
Can calling qcom_swrm_get_device_status() here clobber
ctrl->slave_status and drop attach events for other peripherals on the
bus?
swrm_reconcile_slaves() snapshots SWRM_MCP_SLV_STATUS once before the
loop and runs with ctrl->irq disabled, so another peripheral on slot j
can finish attaching during the SCP DevID reads:
CPU0 (probe) Hardware / IRQ
qcom_swrm_probe()
disable_irq(ctrl->irq)
swrm_reconcile_slaves()
read SWRM_MCP_SLV_STATUS
(slot i attached,
slot j unattached)
SCP DevID reads on slot i
slot j attaches, IRQ pending
qcom_swrm_set_slave_dev_num(match, i)
qcom_swrm_get_device_status()
ctrl->slave_status = live <-- absorbs slot j = ATTACHED
sdw_handle_slave_status() <-- skips unassigned slot j
enable_irq(ctrl->irq)
qcom_swrm_irq_handler()
ctrl->slave_status == live
skips qcom_swrm_enumerate()
When enable_irq() delivers the pending attach interrupt,
qcom_swrm_irq_handler() sees ctrl->slave_status == slave_status, skips
qcom_swrm_enumerate(), and leaves peripheral j permanently unbound.
Calling sdw_handle_slave_status() inside the loop also re-invokes
sdw_update_slave_status() on every already-attached slave for each
reconciled slot.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-0-046ce68c8b0e@oss.qualcomm.com?part=4
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live
2026-12-03 7:41 ` [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live Ajay Kumar Nandam
@ 2026-12-03 8:09 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-03 8:09 UTC (permalink / raw)
To: Ajay Kumar Nandam; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] soundwire: qcom: returning 0 from swrm_runtime_resume() allows
unclocked MMIO
- [High] soundwire: qcom: no-op runtime PM returns desynchronize hclk
and IRQ state
- [High] soundwire: qcom: swrm_runtime_resume() returns 0 when iface
clock is not live
- [Medium] soundwire: qcom: TOCTOU race in swrm_iface_clk_live() during
ADSP restart
- [Medium] soundwire: qcom: swrm_iface_clk_live() misuses
clk_get_parent() for liveness
- [Medium] soundwire: qcom: clk refcount desync when
swrm_iface_clk_live() is false
- [Low] soundwire: qcom: missing Fixes trailer for commit 74e79da9fd46
--
commit 683e39c266e972c60d809e7105dea93e9dd7f4e3
Author: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
> soundwire: qcom: don't touch registers when the iface clock is not live
>
> swrm_runtime_resume() and swrm_runtime_suspend() enable or disable the
> interface clock before accessing controller registers. The clock's
> parent provider can go away while the controller still holds a valid
> struct clk.
>
> During an ADSP restart, this can happen when the provider disappears
> before the SoundWire controller finishes its runtime-PM transition.
>
> Check that the interface clock still has a parent before touching the
> clock or the registers it gates, and treat a missing parent as a
> no-op. Do this check before the multi-master role is handled, so it
> covers the dependent role's early-return path as well.
>
> Co-developed-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
> Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
> Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
[Severity: Low]
This looks like a bug fix for the runtime PM callbacks. Should it
include:
Fixes: 74e79da9fd46 ("soundwire: qcom: add runtime pm support")
> diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
> index ad28a0fa345df..bd44d89132675 100644
> --- a/drivers/soundwire/qcom.c
> +++ b/drivers/soundwire/qcom.c
> @@ -2076,11 +2076,20 @@ static void qcom_swrm_remove(struct platform_device *pdev)
> clk_disable_unprepare(ctrl->hclk);
> }
>
> +/* Check that the interface clock provider is still present. */
> +static bool swrm_iface_clk_live(struct qcom_swrm_ctrl *ctrl)
> +{
> + return !IS_ERR_OR_NULL(clk_get_parent(ctrl->hclk));
> +}
[Severity: Medium]
Can clk_get_parent(ctrl->hclk) reliably tell whether the interface clock
provider is still present?
When ctrl->hclk's own provider unregisters, clk_unregister() replaces
ops with clk_nodrv_ops and unlinks child_node without clearing
core->parent. clk_get_parent() still returns non-NULL, letting runtime
PM access unclocked registers, and if the parent later unregisters and
is freed it dereferences a dangling core->parent pointer.
It also misses grandparent unregistration (which marks descendants
orphan without clearing core->parent) and sibling ADSP vote clocks such
as q6afecc in kodiak.dtsi. Under !CONFIG_HAVE_CLK, clk_get_parent() is
stubbed to return NULL, making runtime PM a permanent no-op.
[Severity: Medium]
Is there a race between swrm_iface_clk_live() and asynchronous ADSP
clock teardown?
clk_get_parent() drops prepare_lock before returning, so the parent
clock can unregister right after the check:
CPU0 CPU1
swrm_runtime_resume()
swrm_iface_clk_live() -> true
clk_unregister(parent)
clk_core_set_parent_nolock(..., NULL)
clk_prepare_enable(ctrl->hclk)
ctrl->reg_write(...) <-- unclocked MMIO access
Because clk_core_prepare(NULL) returns 0 on an orphaned clock, and the
non-dependent path ignores the return value of clk_prepare_enable(),
swrm_runtime_resume() proceeds into unclocked MMIO accesses. The same
window exists across the sleeping waits in swrm_runtime_suspend().
>
> static int __maybe_unused swrm_runtime_resume(struct device *dev)
> {
> struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev);
> int ret;
>
> + if (!swrm_iface_clk_live(ctrl))
> + return 0;
[Severity: High]
Can returning 0 here let callers access unclocked MMIO registers?
When runtime_resume returns 0, rpm_resume() marks the device RPM_ACTIVE
and reports success even though ctrl->hclk was never enabled. In
qcom_swrm_remove(), pm_runtime_resume_and_get(peer->dev) then succeeds
and writes SWRM_REG_INTERRUPT_CPU_EN and SWRM_COMP_CFG_ADDR to the
unclocked peer, risking external aborts or bus hangs.
Returning a negative error instead would keep the device RPM_SUSPENDED
and let callers abort before touching registers.
[Severity: High]
Will returning 0 from swrm_runtime_resume() cause a double
clk_disable_unprepare() when an autosuspended controller unbinds?
During unbind of a suspended controller, __device_release_driver() runs
pm_runtime_get_sync() (marking it RPM_ACTIVE without enabling hclk) and
pm_runtime_put_sync(), which defers autosuspend and leaves it
RPM_ACTIVE.
qcom_swrm_remove() then calls clk_disable_unprepare(ctrl->hclk) a second
time and triggers WARN() in clk_core_unprepare(). Commit "soundwire:
qcom: disable runtime PM on controller unbind" does not avoid this,
since pm_runtime_status_suspended() is false.
[ ... ]
> @@ -2159,6 +2168,9 @@ static int __maybe_unused swrm_runtime_suspend(struct device *dev)
> struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev);
> int ret;
>
> + if (!swrm_iface_clk_live(ctrl))
> + return 0;
[Severity: High]
Does skipping swrm_runtime_suspend() desynchronize ctrl->irq and
ctrl->hclk from runtime PM state?
Returning 0 transitions an active controller to RPM_SUSPENDED without
calling disable_irq(ctrl->irq) or clk_disable_unprepare(ctrl->hclk).
While suspended, qcom_swrm_irq_handler() can still fire and read
SWRM_REG_INTERRUPT_STATUS.
When ADSP recovers and the parent clock re-attaches, the next
swrm_runtime_resume() calls clk_prepare_enable(ctrl->hclk) a second time
(leaking a reference) and calls enable_irq(ctrl->irq) on an already
enabled IRQ, triggering an unbalanced-enable WARN() in __enable_irq().
[Severity: Medium]
Can returning 0 here leak ctrl->hclk when an active dependent controller
unbinds?
QCOM_SWRM_MM_DEPENDENT controllers do not use autosuspend, so during
unbind __device_release_driver() -> pm_runtime_put_sync() runs
swrm_runtime_suspend() synchronously. When swrm_iface_clk_live() is
false, this returns 0 without disabling ctrl->hclk and sets RPM_SUSPENDED.
qcom_swrm_remove() then sees pm_runtime_status_suspended() as true and
skips clk_disable_unprepare(ctrl->hclk), leaking the clock reference.
Tracking whether ctrl->hclk is actually enabled would prevent runtime PM
state from diverging from clock ownership.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-0-046ce68c8b0e@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-03 8:09 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 7:41 [PATCH 0/4] soundwire: qcom: controller lifecycle fixes on unbind/reprobe Ajay Kumar Nandam
2026-12-03 7:41 ` [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live Ajay Kumar Nandam
2026-12-03 8:09 ` sashiko-bot
2026-12-03 7:41 ` [PATCH 2/4] soundwire: qcom: disable runtime PM on controller unbind Ajay Kumar Nandam
2026-12-03 8:08 ` sashiko-bot
2026-12-03 7:41 ` [PATCH 3/4] soundwire: qcom: dispose IRQ mappings " Ajay Kumar Nandam
2026-12-03 7:55 ` sashiko-bot
2026-12-03 7:41 ` [PATCH 4/4] soundwire: qcom: reconcile a retained peripheral after controller re-probe Ajay Kumar Nandam
2026-12-03 8:08 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox