[PATCH v3 2/3] mtd: spi-nor: set erasesize_minor for non-uniform erase

Thibaut VARÈNE hacks+kernel at slashdirt.org
Fri Jul 29 02:16:35 PDT 2022


This patch sets erasesize_minor on SPI-NOR devices supporting
non-uniform erase, allowing write access to partitions that sit on
"minor" boundary. It preserves backward compatibility with existing
uniform behavior.

Signed-off-by: John Thomson <git at johnthomson.fastmail.com.au>
Signed-off-by: Thibaut VARÈNE <hacks+kernel at slashdirt.org>
---
 drivers/mtd/spi-nor/core.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 502967c76..bafd3396e 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2144,6 +2144,7 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 {
 	struct spi_nor_erase_map *map = &nor->params->erase_map;
 	const struct spi_nor_erase_type *erase = NULL;
+	const struct spi_nor_erase_type *erase_minor = NULL;
 	struct mtd_info *mtd = &nor->mtd;
 	u32 wanted_size = nor->info->sector_size;
 	int i;
@@ -2172,12 +2173,14 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 
 	/*
 	 * For non-uniform SPI flash memory, set mtd->erasesize to the
-	 * maximum erase sector size. No need to set nor->erase_opcode.
+	 * maximum erase sector size and mtd->erasesize_minor to the minimum.
+	 * No need to set nor->erase_opcode.
 	 */
 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
 		if (map->erase_type[i].size) {
-			erase = &map->erase_type[i];
-			break;
+			if (!erase)
+				erase = &map->erase_type[i];
+			erase_minor = &map->erase_type[i];
 		}
 	}
 
@@ -2185,6 +2188,8 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 		return -EINVAL;
 
 	mtd->erasesize = erase->size;
+	if (erase_minor->size < erase->size)
+		mtd->erasesize_minor = erase_minor->size;
 	return 0;
 }
 
-- 
2.30.2




More information about the linux-mtd mailing list