[PATCH 1/4] mtd: spi-nor: make sure op does not contain garbage

Tudor Ambarus tudor.ambarus at linaro.org
Mon Jul 17 09:35:57 PDT 2023


Initialize local struct spi_mem_op at declaration to avoid having
garbage data from stack for members that were not explicitly
initialized afterwards. Zeroise the local struct after the first
use, so that we have it clean for the second use.

Fixes: d73ee7534cc5 ("mtd: spi-nor: core: perform a Soft Reset on shutdown")
Cc: stable at vger.kernel.org
Signed-off-by: Tudor Ambarus <tudor.ambarus at linaro.org>
---
 drivers/mtd/spi-nor/core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 273258f7e77f..603791497523 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3235,11 +3235,9 @@ static int spi_nor_init(struct spi_nor *nor)
  */
 static void spi_nor_soft_reset(struct spi_nor *nor)
 {
-	struct spi_mem_op op;
+	struct spi_mem_op op = SPINOR_SRSTEN_OP;
 	int ret;
 
-	op = (struct spi_mem_op)SPINOR_SRSTEN_OP;
-
 	spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
 
 	ret = spi_mem_exec_op(nor->spimem, &op);
@@ -3248,6 +3246,7 @@ static void spi_nor_soft_reset(struct spi_nor *nor)
 		return;
 	}
 
+	memset(&op, 0, sizeof(op));
 	op = (struct spi_mem_op)SPINOR_SRST_OP;
 
 	spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
-- 
2.34.1




More information about the linux-mtd mailing list