Skip to content

Commit 61147a3

Browse files
sylvioalvesdanieldegrasse
authored andcommitted
drivers: spi: esp32: fix volatile array zeroing to use explicit loop
Replace memset() with an explicit loop to zero the data_buf array, which is part of a volatile struct. Standard memset does not guarantee volatile stores, which can lead to incorrect hardware access. Signed-off-by: Sylvio Alves <[email protected]>
1 parent a7a4583 commit 61147a3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/spi/spi_esp32_spim.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ static int IRAM_ATTR spi_esp32_transfer(const struct device *dev)
9898
}
9999

100100
/* clean up and prepare SPI hal */
101-
memset((uint32_t *)hal->hw->data_buf, 0, sizeof(hal->hw->data_buf));
101+
for (size_t i = 0; i < ARRAY_SIZE(hal->hw->data_buf); ++i) {
102+
hal->hw->data_buf[i] = 0;
103+
}
102104
hal_trans->send_buffer = tx_temp ? tx_temp : (uint8_t *)ctx->tx_buf;
103105
hal_trans->rcv_buffer = rx_temp ? rx_temp : ctx->rx_buf;
104106
hal_trans->tx_bitlen = bit_len;

0 commit comments

Comments
 (0)