Skip to contentSkip to conversation

mtd: spi-nor: Check the return value from read_sr()

PATCH In review Fabio Estevam 2 participants 2 messages Nov 20, 2015 – Dec 10, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mtd: spi-nor: Check the return value from read_sr()

From: Fabio Estevam <[email protected]>

We should better check the return value from read_sr() and propagate it in the case of error.

---
Changes since v1:
- Change status_old and status_new to int (Brian).

 drivers/mtd/spi-nor/spi-nor.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +8 -2
index 16c9f55..b5e505d 100644
@@ -459,11 +459,13 @@ static int stm_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len,
 static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 {
 	struct mtd_info *mtd = &nor->mtd;
-	u8 status_old, status_new;
+	int status_old, status_new;
 	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
 	u8 shift = ffs(mask) - 1, pow, val;
 
 	status_old = read_sr(nor);
+	if (status_old < 0)
+		return status_old;
 
 	/* SPI NOR always locks to the end */
 	if (ofs + len != mtd->size) {
@@ -509,11 +511,13 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 {
 	struct mtd_info *mtd = &nor->mtd;
-	uint8_t status_old, status_new;
+	int status_old, status_new;
 	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
 	u8 shift = ffs(mask) - 1, pow, val;
 
 	status_old = read_sr(nor);
+	if (status_old < 0)
+		return status_old;
 
 	/* Cannot unlock; would unlock larger region than requested */
 	if (stm_is_locked_sr(nor, status_old, ofs - mtd->erasesize,
@@ -1013,6 +1017,8 @@ static int macronix_quad_enable(struct spi_nor *nor)
 	int ret, val;
 
 	val = read_sr(nor);
+	if (val < 0)
+		return val;
 	write_enable(nor);
 
 	write_sr(nor, val | SR_QUAD_EN_MX);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 19 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

We should better check the return value from read_sr() and propagate it in the case of error.

---
Changes since v1:
- Change status_old and status_new to int (Brian).

 drivers/mtd/spi-nor/spi-nor.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +0 -0
index 16c9f55..b5e505d 100644
@@ -459,11 +459,13 @@ static int stm_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len,
 static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)

drivers/mtd/spi-nor/spi-nor.c static int stm_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len, · line 468

Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +3 -1
 {
 	struct mtd_info *mtd = &nor->mtd;
-	u8 status_old, status_new;
+	int status_old, status_new;
 	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
 	u8 shift = ffs(mask) - 1, pow, val;
 
 	status_old = read_sr(nor);
+	if (status_old < 0)
+		return status_old;

This wasn't exactly what I was imagining (I figured have an 'int ret' just for th error code, but still keep 'u8 status_{old,new}'), but still looks good to me. Applied to l2-mtd.git. Thanks!

Brian

Quoted 30 lines
drivers/mtd/spi-nor/spi-nor.c +5 -1
 	/* SPI NOR always locks to the end */
 	if (ofs + len != mtd->size) {
@@ -509,11 +511,13 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 {
 	struct mtd_info *mtd = &nor->mtd;
-	uint8_t status_old, status_new;
+	int status_old, status_new;
 	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
 	u8 shift = ffs(mask) - 1, pow, val;
 
 	status_old = read_sr(nor);
+	if (status_old < 0)
+		return status_old;
 
 	/* Cannot unlock; would unlock larger region than requested */
 	if (stm_is_locked_sr(nor, status_old, ofs - mtd->erasesize,
@@ -1013,6 +1017,8 @@ static int macronix_quad_enable(struct spi_nor *nor)
 	int ret, val;
 
 	val = read_sr(nor);
+	if (val < 0)
+		return val;
 	write_enable(nor);
 
 	write_sr(nor, val | SR_QUAD_EN_MX);
Signature · 1 line
1.9.1