fix(drivers/SPL06): fix SPI read off-by-one dropping data bytes (#27074)

Fix: transfer `len + 1` bytes and copy received data from offset 1,
skipping the dummy byte. Copy into caller's buffer only on success.
This commit is contained in:
NeverSayGoodby
2026-06-07 03:44:13 +08:00
committed by GitHub
parent 77edb0dda6
commit 403c1cb585

View File

@@ -98,7 +98,17 @@ SPL06_SPI::read(uint8_t addr, uint8_t *buf, uint8_t len)
{
uint8_t tx_buf[len + 1] = {(uint8_t)(addr | DIR_READ)}; // GCC support VLA, let's use it
return transfer(tx_buf, buf, len);
int res = transfer(tx_buf, tx_buf, (len + 1));
if (res < 0) {
return res;
}
for (int i = 0; i < len; i++) {
buf[i] = tx_buf[1 + i];
}
return res;
}
#endif // CONFIG_SPI