[PATCH] spi: dw-mmio: handle clock and reset failures on resume

From: Luo Yifan

Date: Mon Nov 16 2026 - 21:06:03 EST


dw_spi_mmio_resume() ignores the return values of the two
clk_prepare_enable() calls and of reset_control_deassert(). If any of them
fails, the function still calls platform_resume() and
dw_spi_resume_controller(), which access the controller with its clocks or
reset line not ready.

Check every step and unwind in reverse order on failure, including the
controller resume itself.

Signed-off-by: Luo Yifan <luoyifan@xxxxxxxxxxxxxxxxxxxx>
---
drivers/spi/spi-dw-mmio.c | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index dd703c1e56..665805dea3 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -472,23 +472,37 @@ static int dw_spi_mmio_resume(struct device *dev)
struct dw_spi_mmio *dwsmmio = dev_get_drvdata(dev);
int ret;

- clk_prepare_enable(dwsmmio->clk);
- clk_prepare_enable(dwsmmio->pclk);
+ ret = clk_prepare_enable(dwsmmio->clk);
+ if (ret)
+ return ret;
+
+ ret = clk_prepare_enable(dwsmmio->pclk);
+ if (ret)
+ goto err_clk;

- reset_control_deassert(dwsmmio->rstc);
+ ret = reset_control_deassert(dwsmmio->rstc);
+ if (ret)
+ goto err_pclk;

if (dwsmmio->platform_resume) {
ret = dwsmmio->platform_resume(dwsmmio);
- if (ret) {
- reset_control_assert(dwsmmio->rstc);
-
- clk_disable_unprepare(dwsmmio->pclk);
- clk_disable_unprepare(dwsmmio->clk);
- return ret;
- }
+ if (ret)
+ goto err_rst;
}

- return dw_spi_resume_controller(&dwsmmio->dws);
+ ret = dw_spi_resume_controller(&dwsmmio->dws);
+ if (ret)
+ goto err_rst;
+
+ return 0;
+
+err_rst:
+ reset_control_assert(dwsmmio->rstc);
+err_pclk:
+ clk_disable_unprepare(dwsmmio->pclk);
+err_clk:
+ clk_disable_unprepare(dwsmmio->clk);
+ return ret;
}

static DEFINE_SIMPLE_DEV_PM_OPS(dw_spi_mmio_pm_ops,
--
2.24.4