soundwire: qcom: handle interface clock failure on runtime resume
Subsystems (4)
PATCH 1/1 soundwire: qcom: handle interface clock failure on runtime resume
After runtime suspend releases the interface clock, PCM startup can request a runtime resume. On SDM845 with WCD9340, an RPMh active vote for the parent clock can time out during clk_prepare_enable(). swrm_runtime_resume() ignores the error, enables the main IRQ and accesses controller registers. Runtime PM then marks the controller active, so callers can proceed with I/O without the interface clock.
Return the clock error before enabling the main IRQ or accessing the controller. Keep masking the optional wake IRQ before the clock call to prevent an asserted level-triggered wake IRQ from retriggering on failure. Unbind can proceed after a failed resume, so disable runtime PM during remove and release the clock only if the controller is still active.
Verification covered source review,
arm64 builds of qcom.o with CONFIG_PM enabled and disabled, and git diff --check and checkpatch.pl. Runtime and hardware reproduction were not performed.
--- drivers/soundwire/qcom.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/soundwire/qcom.c +7 -2
@@ -1787,7 +1787,9 @@ static void qcom_swrm_remove(struct platform_device *pdev)struct qcom_swrm_ctrl *ctrl =dev_get_drvdata (&pdev->dev);sdw_bus_master_delete (&ctrl->bus); -clk_disable_unprepare (ctrl->hclk); +pm_runtime_disable (ctrl->dev); +if (!pm_runtime_status_suspended (ctrl->dev)) +clk_disable_unprepare (ctrl->hclk); }static int __maybe_unused swrm_runtime_resume (struct device *dev)
@@ -1800,7 +1802,10 @@ static int __maybe_unused swrm_runtime_resume(struct device *dev)disable_irq_nosync (ctrl->wake_irq); } -clk_prepare_enable (ctrl->hclk); + ret =clk_prepare_enable (ctrl->hclk); +if (ret) +return ret; +enable_irq (ctrl->irq);if (ctrl->clock_stop_not_supported) {
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] soundwire: qcom: pm_runtime_disable() called after sdw_bus_master_delete() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] soundwire: qcom: pm_runtime_disable() called after sdw_bus_master_delete()
--
commit 0bb49a0cfd730102126279a4ada1a6ea8640b778
Author: Jiawen Liu <[email protected]>
soundwire: qcom: handle interface clock failure on runtime resume
This commit checks the return value of clk_prepare_enable() in swrm_runtime_resume() and updates qcom_swrm_remove() to disable runtime PM and only disable the interface clock if the device is not runtime suspended.
drivers/soundwire/qcom.c static void qcom_swrm_remove(struct platform_device *pdev) · line 1793
Quoted 13 lines
drivers/soundwire/qcom.c +3
-1@@ -1787,7 +1787,9 @@ static void qcom_swrm_remove(struct platform_device *pdev)struct qcom_swrm_ctrl *ctrl =dev_get_drvdata (&pdev->dev);sdw_bus_master_delete (&ctrl->bus); -clk_disable_unprepare (ctrl->hclk); +pm_runtime_disable (ctrl->dev); +if (!pm_runtime_status_suspended (ctrl->dev)) +clk_disable_unprepare (ctrl->hclk); }
[Severity: Medium]
Should pm_runtime_disable(ctrl->dev) be called before sdw_bus_master_delete(&ctrl->bus)?
__device_release_driver() drops its runtime PM reference via pm_runtime_put_sync() before calling qcom_swrm_remove(), so ctrl->dev enters remove with usage_count == 0 and runtime PM still enabled. While sdw_bus_master_delete() unregisters active child slaves, pm_runtime_reinit() decrements ctrl->dev->power.child_count and queues an async runtime suspend on ctrl->dev (or the autosuspend timer can fire):
CPU0 CPU1 (pm_wq)qcom_swrm_remove()
sdw_bus_master_delete(&ctrl->bus)
device_for_each_child(...,
sdw_delete_slave)
device_unregister(&slave->dev)
...
pm_request_idle(ctrl->dev)
swrm_runtime_suspend()
sdw_bus_prep_clk_stop(&ctrl->bus)
list_for_each_entry(slave,
&bus->slaves, node)
list_del_init(&slave->node)
put_device(&slave->dev) <-- list corruption / UAF pm_runtime_disable(ctrl->dev)
Calling pm_runtime_disable(ctrl->dev) before sdw_bus_master_delete() matches the reverse of qcom_swrm_probe() and waits for any in-flight runtime PM transitions before tearing down the bus.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1