Skip to content

Commit 151c6b4

Browse files
committed
mtd: spi-nor: Skip erase logic when SPI_NOR_NO_ERASE is set
Even if SPI_NOR_NO_ERASE was set, one could still send erase opcodes to the flash. It is not recommended to send unsupported opcodes to flashes. Fix the logic and do not set mtd->_erase when SPI_NOR_NO_ERASE is specified. With this users will not be able to issue erase opcodes to flashes and instead they will recive an -ENOTSUPP error. Fixes: b199489 ("mtd: spi-nor: add the framework for SPI NOR") Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Reviewed-by: Michael Walle <michael@walle.cc> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20220228163334.277730-1-tudor.ambarus@microchip.com
1 parent 3c55288 commit 151c6b4

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

drivers/mtd/spi-nor/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2948,10 +2948,11 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
29482948
mtd->flags = MTD_CAP_NORFLASH;
29492949
if (nor->info->flags & SPI_NOR_NO_ERASE)
29502950
mtd->flags |= MTD_NO_ERASE;
2951+
else
2952+
mtd->_erase = spi_nor_erase;
29512953
mtd->writesize = nor->params->writesize;
29522954
mtd->writebufsize = nor->params->page_size;
29532955
mtd->size = nor->params->size;
2954-
mtd->_erase = spi_nor_erase;
29552956
mtd->_read = spi_nor_read;
29562957
/* Might be already set by some SST flashes. */
29572958
if (!mtd->_write)

0 commit comments

Comments
 (0)