[PATCH 04/10] spi: sprd-adi: Do not copy uninitialised data to rx_buf on read failure
From: Lee Jones
Date: Thu Nov 19 2026 - 04:18:56 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>
---
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 a6baaf02b3c8..3586fc1aac7b 100644
--- a/drivers/spi/spi-sprd-adi.c
+++ b/drivers/spi/spi-sprd-adi.c
@@ -341,7 +341,8 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr,
if (t->rx_buf) {
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) {
u32 *p = (u32 *)t->tx_buf;
reg = *p++;
--
2.56.1.708.g77570a6a1d-goog