During writing, the entire flash page (including OOB) will be updated
with the values from the temporary buffer, so we need to fill the
untouched areas of the buffer with 0xff value to prevent accidental
data overwriting.

Signed-off-by: Mikhail Kshevetskiy <[email protected]>
---
 drivers/spi/airoha_snfi_spi.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/spi/airoha_snfi_spi.c b/drivers/spi/airoha_snfi_spi.c
index f25c5df5783..9fc44e7088a 100644
--- a/drivers/spi/airoha_snfi_spi.c
+++ b/drivers/spi/airoha_snfi_spi.c
@@ -764,7 +764,11 @@ static ssize_t airoha_snand_dirmap_write(struct 
spi_mem_dirmap_desc *desc,
                return -EOPNOTSUPP;
        }
 
+       if (offs > 0)
+               memset(txrx_buf, 0xff, offs);
        memcpy(txrx_buf + offs, buf, len);
+       if (bytes > offs + len)
+               memset(txrx_buf + offs + len, 0xff, bytes - offs - len);
 
        err = airoha_snand_set_mode(priv, SPI_MODE_DMA);
        if (err < 0)
-- 
2.51.0

Reply via email to