2023-07-17 16:50:25

by Tudor Ambarus

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

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: [email protected]
Signed-off-by: Tudor Ambarus <[email protected]>
---
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



2023-07-17 16:54:17

by Tudor Ambarus

[permalink] [raw]
Subject: [PATCH 3/4] mtd: spi-nor: spansion: make sure op does not contain garbage

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: [email protected]
Signed-off-by: Tudor Ambarus <[email protected]>
---
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;

--
2.34.1


2023-07-17 17:29:43

by Tudor Ambarus

[permalink] [raw]
Subject: [PATCH 4/4] mtd: spi-nor: spansion: make sure op does not contain garbage (2)

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: [email protected]
Signed-off-by: Tudor Ambarus <[email protected]>
---
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);
--
2.34.1