[PATCH] mtd: spi-nor: cadence: fix csqpi corruption in cqspi_set_protocol

Ian Abbott abbotti at mev.co.uk
Wed Sep 16 12:23:17 EDT 2020


cqspi_set_protocol() sets `inst_width`, `addr_width` and `data_width`
for the previous chip-select in `cqspi->current_cs`, but that is
initially set to -1, leading to corruption of other `cqspi->` members.
Change it to set `inst_width`, `addr_width` and `data_width` for the
chip-select associated with the `nor` parameter.

Fixes: 5085d2ef3fbf ("mtd: spi-nor: cadence: add cqspi_set_protocol")
Signed-off-by: Ian Abbott <abbotti at mev.co.uk>
---
 drivers/mtd/spi-nor/cadence-quadspi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/cadence-quadspi.c b/drivers/mtd/spi-nor/cadence-quadspi.c
index 11e4d236d..2372482ac 100644
--- a/drivers/mtd/spi-nor/cadence-quadspi.c
+++ b/drivers/mtd/spi-nor/cadence-quadspi.c
@@ -896,8 +896,12 @@ static int cqspi_set_protocol(struct spi_nor *nor, const int read)
 {
 	struct cqspi_st *cqspi = nor->priv;
 	struct cqspi_flash_pdata *f_pdata;
+	int cs = cqspi_find_chipselect(nor);
 
-	f_pdata = &cqspi->f_pdata[cqspi->current_cs];
+	if (cs < 0)
+		return -EINVAL;
+
+	f_pdata = &cqspi->f_pdata[cs];
 
 	f_pdata->inst_width = CQSPI_INST_TYPE_SINGLE;
 	f_pdata->addr_width = CQSPI_INST_TYPE_SINGLE;
-- 
2.28.0




More information about the barebox mailing list