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@vger.kernel.org Signed-off-by: Tudor Ambarus tudor.ambarus@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);
Initialise local struct spi_mem_op with all zeros at declaration, or by memset before the second use, in order to avoid using garbage data for fields that are not explicitly set afterwards.
Fixes: ad624dfd7bb6 ("mtd: spi-nor: micron-st: allow using MT35XU512ABA in Octal DTR mode") Cc: stable@vger.kernel.org Signed-off-by: Tudor Ambarus tudor.ambarus@linaro.org --- drivers/mtd/spi-nor/micron-st.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/spi-nor/micron-st.c b/drivers/mtd/spi-nor/micron-st.c index f79e71d99124..8390ed6a47b6 100644 --- a/drivers/mtd/spi-nor/micron-st.c +++ b/drivers/mtd/spi-nor/micron-st.c @@ -49,7 +49,7 @@
static int micron_st_nor_octal_dtr_en(struct spi_nor *nor) { - struct spi_mem_op op; + struct spi_mem_op op = {}; u8 *buf = nor->bouncebuf; int ret; u8 addr_mode_nbytes = nor->params->addr_mode_nbytes; @@ -64,6 +64,7 @@ static int micron_st_nor_octal_dtr_en(struct spi_nor *nor) return ret;
buf[0] = SPINOR_MT_OCT_DTR; + memset(&op, 0, sizeof(op)); op = (struct spi_mem_op) MICRON_ST_NOR_WR_ANY_REG_OP(addr_mode_nbytes, SPINOR_REG_MT_CFR0V, 1, buf); @@ -86,7 +87,7 @@ static int micron_st_nor_octal_dtr_en(struct spi_nor *nor)
static int micron_st_nor_octal_dtr_dis(struct spi_nor *nor) { - struct spi_mem_op op; + struct spi_mem_op op = {}; u8 *buf = nor->bouncebuf; int ret;
Initialise local struct spi_mem_op with all zeros at declaration, or by memset before the second use, in order to avoid using garbage data for fields that are not explicitly set afterwards.
Fixes: c3266af101f2 ("mtd: spi-nor: spansion: add support for Cypress Semper flash") Cc: stable@vger.kernel.org Signed-off-by: Tudor Ambarus tudor.ambarus@linaro.org --- drivers/mtd/spi-nor/spansion.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c index 6d6466a3436e..c03445e46d56 100644 --- a/drivers/mtd/spi-nor/spansion.c +++ b/drivers/mtd/spi-nor/spansion.c @@ -143,7 +143,7 @@ static int cypress_nor_sr_ready_and_clear(struct spi_nor *nor)
static int cypress_nor_octal_dtr_en(struct spi_nor *nor) { - struct spi_mem_op op; + struct spi_mem_op op = {}; u8 *buf = nor->bouncebuf; int ret; u8 addr_mode_nbytes = nor->params->addr_mode_nbytes; @@ -161,6 +161,7 @@ static int cypress_nor_octal_dtr_en(struct spi_nor *nor) nor->read_dummy = 24;
/* Set the octal and DTR enable bits. */ + memset(&op, 0, sizeof(op)); buf[0] = SPINOR_REG_CYPRESS_CFR5_OCT_DTR_EN; op = (struct spi_mem_op) CYPRESS_NOR_WR_ANY_REG_OP(addr_mode_nbytes, @@ -186,7 +187,7 @@ static int cypress_nor_octal_dtr_en(struct spi_nor *nor)
static int cypress_nor_octal_dtr_dis(struct spi_nor *nor) { - struct spi_mem_op op; + struct spi_mem_op op = {}; u8 *buf = nor->bouncebuf; int ret;
Initialise local struct spi_mem_op with all zeros at declaration, or by memset before the second use, in order to avoid using garbage data for fields that are not explicitly set afterwards.
Fixes: b6b23833fc42 ("mtd: spi-nor: spansion: Add s25hl-t/s25hs-t IDs and fixups") Cc: stable@vger.kernel.org Signed-off-by: Tudor Ambarus tudor.ambarus@linaro.org --- drivers/mtd/spi-nor/spansion.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c index c03445e46d56..7485b708158f 100644 --- a/drivers/mtd/spi-nor/spansion.c +++ b/drivers/mtd/spi-nor/spansion.c @@ -220,7 +220,7 @@ static int cypress_nor_octal_dtr_dis(struct spi_nor *nor)
static int cypress_nor_quad_enable_volatile_reg(struct spi_nor *nor, u64 addr) { - struct spi_mem_op op; + struct spi_mem_op op = {}; u8 addr_mode_nbytes = nor->params->addr_mode_nbytes; u8 cfr1v_written; int ret; @@ -237,6 +237,7 @@ static int cypress_nor_quad_enable_volatile_reg(struct spi_nor *nor, u64 addr) return 0;
/* Update the Quad Enable bit. */ + memset(&op, 0, sizeof(op)); nor->bouncebuf[0] |= SPINOR_REG_CYPRESS_CFR1_QUAD_EN; op = (struct spi_mem_op) CYPRESS_NOR_WR_ANY_REG_OP(addr_mode_nbytes, addr, 1, @@ -248,6 +249,7 @@ static int cypress_nor_quad_enable_volatile_reg(struct spi_nor *nor, u64 addr) cfr1v_written = nor->bouncebuf[0];
/* Read back and check it. */ + memset(&op, 0, sizeof(op)); op = (struct spi_mem_op) CYPRESS_NOR_RD_ANY_REG_OP(addr_mode_nbytes, addr, 0, nor->bouncebuf);
linux-stable-mirror@lists.linaro.org