[PATCH v2 04/10] spi: sprd-adi: Do not copy uninitialised data to rx_buf on read failure
From: Lee Jones
Date: Fri Nov 27 2026 - 10:32:41 EST
sprd_adi_read() returns early without writing to *read_val if it fails
to take the hardware spinlock, if the register address is out of range,
if the read times out or if the read-back check fails.
sprd_adi_transfer_one() stores val into rx_buf regardless of the return
value, so on any of those failures the caller's buffer is filled with
uninitialised stack data.
Only update rx_buf when the read succeeded. The error code is still
propagated as before.
Fixes: 5dc349ec131c ("spi: sprd: Pass offset instead of physical address to adi_read/_write()")
Closes: https://sashiko.dev/#/bug/linux-4e21848f-9195-4645-a277-501803f17e95
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
v1 => v2:
- Rebase onto spi/for-next; no functional changes.
drivers/spi/spi-sprd-adi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-sprd-adi.c b/drivers/spi/spi-sprd-adi.c
index 32e445cea0d3..68c8f8b808cf 100644
--- a/drivers/spi/spi-sprd-adi.c
+++ b/drivers/spi/spi-sprd-adi.c
@@ -348,7 +348,8 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr,
}
reg = *(u32 *)t->rx_buf;
ret = sprd_adi_read(sadi, reg, &val);
- *(u32 *)t->rx_buf = val;
+ if (!ret)
+ *(u32 *)t->rx_buf = val;
} else if (t->tx_buf) {
/* ADI writes consume exactly two u32: reg and value. */
if (t->len != 2 * sizeof(u32)) {
--
2.56.1.839.g22a8290db9-goog