* [PATCH] mtd: spi-nor: Skip erase logic when SPI_NOR_NO_ERASE is set
@ 2022-02-28 16:33 Tudor Ambarus
2022-03-01 22:35 ` Michael Walle
2022-03-08 15:41 ` Tudor Ambarus
0 siblings, 2 replies; 3+ messages in thread
From: Tudor Ambarus @ 2022-02-28 16:33 UTC (permalink / raw)
To: p.yadav, michael
Cc: miquel.raynal, richard, vigneshr, linux-mtd, linux-kernel,
nicolas.ferre, Tudor Ambarus, stable
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.
Cc: stable@vger.kernel.org
Fixes: b199489d37b2 ("mtd: spi-nor: add the framework for SPI NOR")
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
drivers/mtd/spi-nor/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 86a536c97c18..cd2d094ef837 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2969,10 +2969,11 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
mtd->flags = MTD_CAP_NORFLASH;
if (nor->info->flags & SPI_NOR_NO_ERASE)
mtd->flags |= MTD_NO_ERASE;
+ else
+ mtd->_erase = spi_nor_erase;
mtd->writesize = nor->params->writesize;
mtd->writebufsize = nor->params->page_size;
mtd->size = nor->params->size;
- mtd->_erase = spi_nor_erase;
mtd->_read = spi_nor_read;
/* Might be already set by some SST flashes. */
if (!mtd->_write)
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd: spi-nor: Skip erase logic when SPI_NOR_NO_ERASE is set
2022-02-28 16:33 [PATCH] mtd: spi-nor: Skip erase logic when SPI_NOR_NO_ERASE is set Tudor Ambarus
@ 2022-03-01 22:35 ` Michael Walle
2022-03-08 15:41 ` Tudor Ambarus
1 sibling, 0 replies; 3+ messages in thread
From: Michael Walle @ 2022-03-01 22:35 UTC (permalink / raw)
To: Tudor Ambarus
Cc: p.yadav, miquel.raynal, richard, vigneshr, linux-mtd,
linux-kernel, nicolas.ferre, stable
Am 2022-02-28 17:33, schrieb Tudor Ambarus:
> 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.
But why is there an erase opcode and erase size set in the
first place? spi_nor_select_erase() should probably return
early if SPI_NOR_NO_ERASE is set. Not setting the erasesize
would also return -ENOTSUPP. I prefer this one for a fixes
patch, though. But spi_nor_select_erase() should also be
fixed.
Reviewed-by: Michael Walle <michael@walle.cc>
>
> Cc: stable@vger.kernel.org
> Fixes: b199489d37b2 ("mtd: spi-nor: add the framework for SPI NOR")
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
> drivers/mtd/spi-nor/core.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 86a536c97c18..cd2d094ef837 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -2969,10 +2969,11 @@ static void spi_nor_set_mtd_info(struct spi_nor
> *nor)
> mtd->flags = MTD_CAP_NORFLASH;
> if (nor->info->flags & SPI_NOR_NO_ERASE)
> mtd->flags |= MTD_NO_ERASE;
> + else
> + mtd->_erase = spi_nor_erase;
> mtd->writesize = nor->params->writesize;
> mtd->writebufsize = nor->params->page_size;
> mtd->size = nor->params->size;
> - mtd->_erase = spi_nor_erase;
> mtd->_read = spi_nor_read;
> /* Might be already set by some SST flashes. */
> if (!mtd->_write)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd: spi-nor: Skip erase logic when SPI_NOR_NO_ERASE is set
2022-02-28 16:33 [PATCH] mtd: spi-nor: Skip erase logic when SPI_NOR_NO_ERASE is set Tudor Ambarus
2022-03-01 22:35 ` Michael Walle
@ 2022-03-08 15:41 ` Tudor Ambarus
1 sibling, 0 replies; 3+ messages in thread
From: Tudor Ambarus @ 2022-03-08 15:41 UTC (permalink / raw)
To: Tudor Ambarus, p.yadav, michael
Cc: linux-mtd, stable, nicolas.ferre, richard, linux-kernel,
vigneshr, miquel.raynal
On Mon, 28 Feb 2022 18:33:34 +0200, Tudor Ambarus wrote:
> 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.
Applied to spi-nor/next, thanks!
[1/1] mtd: spi-nor: Skip erase logic when SPI_NOR_NO_ERASE is set
https://git.kernel.org/mtd/c/151c6b49d679
Best regards,
--
Tudor Ambarus <tudor.ambarus@microchip.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-08 15:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-28 16:33 [PATCH] mtd: spi-nor: Skip erase logic when SPI_NOR_NO_ERASE is set Tudor Ambarus
2022-03-01 22:35 ` Michael Walle
2022-03-08 15:41 ` Tudor Ambarus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).