Skip to content

Commit 59e1be1

Browse files
eghidolibroonie
authored andcommitted
spi: cadence-qspi: Fix exec_mem_op error handling
cqspi_exec_mem_op() increments the runtime PM usage counter before all refcount checks are performed. If one of these checks fails, the function returns without dropping the PM reference. Move the pm_runtime_resume_and_get() call after the refcount checks so that runtime PM is only acquired when the operation can proceed and drop the inflight_ops refcount if the PM resume fails. Cc: stable@vger.kernel.org Fixes: 7446284 ("spi: cadence-quadspi: Implement refcount to handle unbind during busy") Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com> Link: https://patch.msgid.link/20260313135236.46642-1-ghidoliemanuele@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent b0dc7e7 commit 59e1be1

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

drivers/spi/spi-cadence-quadspi.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,14 +1483,6 @@ static int cqspi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op)
14831483
if (refcount_read(&cqspi->inflight_ops) == 0)
14841484
return -ENODEV;
14851485

1486-
if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM))) {
1487-
ret = pm_runtime_resume_and_get(dev);
1488-
if (ret) {
1489-
dev_err(&mem->spi->dev, "resume failed with %d\n", ret);
1490-
return ret;
1491-
}
1492-
}
1493-
14941486
if (!refcount_read(&cqspi->refcount))
14951487
return -EBUSY;
14961488

@@ -1502,6 +1494,14 @@ static int cqspi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op)
15021494
return -EBUSY;
15031495
}
15041496

1497+
if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM))) {
1498+
ret = pm_runtime_resume_and_get(dev);
1499+
if (ret) {
1500+
dev_err(&mem->spi->dev, "resume failed with %d\n", ret);
1501+
goto dec_inflight_refcount;
1502+
}
1503+
}
1504+
15051505
ret = cqspi_mem_process(mem, op);
15061506

15071507
if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM)))
@@ -1510,6 +1510,7 @@ static int cqspi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op)
15101510
if (ret)
15111511
dev_err(&mem->spi->dev, "operation failed with %d\n", ret);
15121512

1513+
dec_inflight_refcount:
15131514
if (refcount_read(&cqspi->inflight_ops) > 1)
15141515
refcount_dec(&cqspi->inflight_ops);
15151516

0 commit comments

Comments
 (0)