From: sashiko-bot@kernel.org
To: "Ajay Kumar Nandam" <ajay.nandam@oss.qualcomm.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live
Date: Thu, 03 Dec 2026 08:09:04 +0000 [thread overview]
Message-ID: <sashiko-outbox-247339@kernel.org> (raw)
In-Reply-To: <20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-1-046ce68c8b0e@oss.qualcomm.com>
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
next prev parent reply other threads:[~2026-12-03 8:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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-247339@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ajay.nandam@oss.qualcomm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.