[PATCH v5 1/7] spi: cadence-xspi: Properly handle errors in .transfer_one_message
From: Paul Cercueil
Date: Fri Nov 20 2026 - 07:00:01 EST
From: Tanmay Jagdale <tanmay@xxxxxxxxxxx>
The cdns_xspi_transfer_one_message_b0() function was not setting
m->status on error, causing it to be stuck at -EINPROGRESS, confusing
the SPI core.
Additionally, reset cdns_xspi->xfer_in_progress on error.
Fixes: 931e389ded0f ("spi: cadence: Add Marvell xfer operation support")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tanmay Jagdale <tanmay@xxxxxxxxxxx>
Co-developed-by: Paul Cercueil <paul.cercueil@xxxxxxxxxxx>
Signed-off-by: Paul Cercueil <paul.cercueil@xxxxxxxxxxx>
---
v2: New patch
v3: No change
v4: Also reset cdns_xspi->xfer_in_progress on error.
v5: Reset hardware FIFO on error
---
drivers/spi/spi-cadence-xspi.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c
index 72852849ba27..e2d5d464bd30 100644
--- a/drivers/spi/spi-cadence-xspi.c
+++ b/drivers/spi/spi-cadence-xspi.c
@@ -1243,6 +1243,7 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,
int current_transfer_len;
int cs = spi_get_chipselect(spi, 0);
int cs_change = 0;
+ int ret = -EIO;
/* Enable xfer state machine */
if (!cdns_xspi->xfer_in_progress) {
@@ -1283,7 +1284,7 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,
false, cmd_regs);
cdns_xspi_trigger_command(cdns_xspi, cmd_regs);
if (!cdns_xspi_is_stig_ready(cdns_xspi, true))
- return -EIO;
+ goto out;
} else {
cdns_xspi_prepare_generic(cs, txd, 1, true, cmd_regs);
cdns_xspi_trigger_command(cdns_xspi, cmd_regs);
@@ -1292,11 +1293,11 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,
cdns_xspi_trigger_command(cdns_xspi, cmd_regs);
cdns_xspi->sdma_xfer_len = current_transfer_len - 1;
if (!cdns_xspi_is_sdma_ready(cdns_xspi, true))
- return -EIO;
+ goto out;
if (cdns_xspi->sdma_handler(cdns_xspi))
- return -EIO;
+ goto out;
if (!cdns_xspi_is_stig_ready(cdns_xspi, true))
- return -EIO;
+ goto out;
if (rxd)
cdns_xspi->in_buffer += current_transfer_len;
@@ -1324,7 +1325,10 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,
spi_transfer_delay_exec(t);
}
- if (!cs_change) {
+ ret = 0;
+
+out:
+ if (ret != 0 || !cs_change) {
u32 xfer_control = readl(cdns_xspi->xferbase + MRVL_XFER_FUNC_CTRL);
xfer_control &= ~(MRVL_XFER_RECEIVE_ENABLE |
@@ -1333,10 +1337,12 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,
cdns_xspi->xfer_in_progress = false;
}
- m->status = 0;
+ if (m->status == -EINPROGRESS)
+ m->status = ret;
+
spi_finalize_current_message(controller);
- return 0;
+ return ret;
}
#endif
--
2.47.3