Skip to contentSkip to conversation

mtd: spi-nor: core: Skip setting erase types when SPI_NOR_NO_ERASE is set

PATCH In review Tudor Ambarus 2 participants 3 messages Mar 8, 2022 – Apr 29, 2022

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

PATCH v2 1/1 mtd: spi-nor: core: Skip setting erase types when SPI_NOR_NO_ERASE is set

Even if SPI_NOR_NO_ERASE was specified at flash declaration, the erase type of size nor->info->sector_size was incorrectly set as supported. Don't set erase types when SPI_NOR_NO_ERASE is set.

Fixes b199489d37b2 ("mtd: spi-nor: add the framework for SPI NOR")

---
v2:
- add comment, update commit message, split change in individual commit
- add fixes tag and cc to stable.

 drivers/mtd/spi-nor/core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/spi-nor/core.c +4 -0
index b4f141ad9c9c..64cf7b9df621 100644
@@ -2392,6 +2392,10 @@ static void spi_nor_no_sfdp_init_params(struct spi_nor *nor)
 					SPINOR_OP_PP, SNOR_PROTO_8_8_8_DTR);
 	}
 
+	/* Skip setting erase types when SPI_NOR_NO_ERASE is set. */
+	if (nor->info->flags & SPI_NOR_NO_ERASE)
+		return;
+
 	/*
 	 * Sector Erase settings. Sort Erase Types in ascending order, with the
 	 * smallest erase size starting at BIT(0).
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Tudor Ambarus

Even if SPI_NOR_NO_ERASE was specified at flash declaration, the erase type of size nor->info->sector_size was incorrectly set as supported. Don't set erase types when SPI_NOR_NO_ERASE is set.

Does this have any practical implications? Since we set MTD_NO_ERASE, erase should never be called for this flash anyway, right?

Quoted 30 lines
Fixes b199489d37b2 ("mtd: spi-nor: add the framework for SPI NOR")

---
v2:
- add comment, update commit message, split change in individual commit
- add fixes tag and cc to stable.

 drivers/mtd/spi-nor/core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/spi-nor/core.c +4 -0
index b4f141ad9c9c..64cf7b9df621 100644
@@ -2392,6 +2392,10 @@ static void spi_nor_no_sfdp_init_params(struct spi_nor *nor)
 					SPINOR_OP_PP, SNOR_PROTO_8_8_8_DTR);
 	}
 
+	/* Skip setting erase types when SPI_NOR_NO_ERASE is set. */
+	if (nor->info->flags & SPI_NOR_NO_ERASE)
+		return;
+
 	/*
 	 * Sector Erase settings. Sort Erase Types in ascending order, with the
 	 * smallest erase size starting at BIT(0).
Signature · 1 line
2.25.1
Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.
#2 lore raw
Quoted 28 lines · Pratyush Yadav
Quoted 3 lines · Tudor Ambarus

Even if SPI_NOR_NO_ERASE was specified at flash declaration, the erase type of size nor->info->sector_size was incorrectly set as supported. Don't set erase types when SPI_NOR_NO_ERASE is set.

Does this have any practical implications? Since we set MTD_NO_ERASE, erase should never be called for this flash anyway, right?

Quoted 20 lines
Fixes b199489d37b2 ("mtd: spi-nor: add the framework for SPI NOR")

---
v2:
- add comment, update commit message, split change in individual commit
- add fixes tag and cc to stable.

 drivers/mtd/spi-nor/core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/spi-nor/core.c +0 -0
index b4f141ad9c9c..64cf7b9df621 100644
@@ -2392,6 +2392,10 @@ static void spi_nor_no_sfdp_init_params(struct spi_nor *nor)
 					SPINOR_OP_PP, SNOR_PROTO_8_8_8_DTR);
 	}
 
Quoted 3 lines

drivers/mtd/spi-nor/core.c static void spi_nor_no_sfdp_init_params(struct spi_nor *nor) · line 2397

Quoted 3 lines
drivers/mtd/spi-nor/core.c +3 -0
+	/* Skip setting erase types when SPI_NOR_NO_ERASE is set. */
+	if (nor->info->flags & SPI_NOR_NO_ERASE)
+		return;

Can you instead do

	if (!(nor->info->flags & SPI_NOR_NO_ERASE)) {
		...
	}

This way when someone adds code to the bottom of this function that sets something other than erase types it will execute for flashes with SPI_NOR_NO_ERASE as well.

Quoted 16 lines
Quoted 7 lines
drivers/mtd/spi-nor/core.c +1 -0
+
 	/*
 	 * Sector Erase settings. Sort Erase Types in ascending order, with the
 	 * smallest erase size starting at BIT(0).
Signature · 1 line
2.25.1
Signature · 7 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.