* [PATCH] mtd: spi-nor: Report missing SR2 support as -EOPNOTSUPP
@ 2026-12-04 11:08 Miquel Raynal
2026-12-04 11:23 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Miquel Raynal @ 2026-12-04 11:08 UTC (permalink / raw)
To: Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Alan Borzeszkowski
Cc: Thomas Petazzoni, linux-mtd, linux-kernel, stable, Miquel Raynal
Commit 63489002d397 ("mtd: spi-nor: Refactor Read Status/Write Status
support") made spi_nor_read_sr2() return -EINVAL when opcodes.read_sr2
is unset. This does not only happen with flashes lacking SR2, but also
when the controller cannot issue the read opcode.
The OTP NVMEM registration path treats -EOPNOTSUPP as "OTP unsupported"
and ignores it, but not -EINVAL. Probe may therefore fail on Intel SPI
platforms with chips featuring an OTP region.
Return -EOPNOTSUPP instead, restoring the v7.3 behaviour for
spi_nor_otp_is_locked_sr2().
Fixes: 63489002d397 ("mtd: spi-nor: Refactor Read Status/Write Status support")
Cc: stable@vger.kernel.org
Reported-by: Alan Borzeszkowski <alan.borzeszkowski@linux.intel.com>
Closes: https://lore.kernel.org/linux-mtd/111cfeb5ffc603883b6573c62e49675bc3924b0a.camel@linux.intel.com/
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
Build tested only.
---
drivers/mtd/spi-nor/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index a04d22d2e2e1..2374e1f5fadb 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -842,7 +842,7 @@ int spi_nor_read_sr2(struct spi_nor *nor, u8 *sr2)
struct spi_nor_flash_parameter *params = nor->params;
if (!params->opcodes.read_sr2)
- return -EINVAL;
+ return -EOPNOTSUPP;
return spi_nor_read_sr_ll(nor, params->opcodes.read_sr2, sr2, 1);
}
---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20261204-winbond-upstreaming-fix-sr2-einval-972091bb0c1f
Best regards,
--
Miquel Raynal <miquel.raynal@bootlin.com>
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] mtd: spi-nor: Report missing SR2 support as -EOPNOTSUPP
2026-12-04 11:08 [PATCH] mtd: spi-nor: Report missing SR2 support as -EOPNOTSUPP Miquel Raynal
@ 2026-12-04 11:23 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04 11:23 UTC (permalink / raw)
To: Miquel Raynal, Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Alan Borzeszkowski
Cc: Thomas Petazzoni, linux-mtd
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mtd: spi-nor: spi_nor_otp_lock_sr2() clobbers SR2 when
read_sr2 is unset
--
commit 9454071366aa9e347080887fe00c54b14d0e92c3
Author: Miquel Raynal <miquel.raynal@bootlin.com>
mtd: spi-nor: Report missing SR2 support as -EOPNOTSUPP
This commit changes spi_nor_read_sr2() to return -EOPNOTSUPP instead of
-EINVAL when params->opcodes.read_sr2 is unset, allowing OTP NVMEM
registration to ignore unsupported SR2 reads instead of failing probe.
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index a04d22d2e2e1c..2374e1f5fadb9 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -842,7 +842,7 @@ int spi_nor_read_sr2(struct spi_nor *nor, u8 *sr2)
> struct spi_nor_flash_parameter *params = nor->params;
>
> if (!params->opcodes.read_sr2)
> - return -EINVAL;
> + return -EOPNOTSUPP;
>
> return spi_nor_read_sr_ll(nor, params->opcodes.read_sr2, sr2, 1);
> }
[Severity: Medium]
Does allowing probe to succeed with opcodes.read_sr2 unset expose
spi_nor_otp_lock_sr2() to clobbering SR2?
On Intel SPI and similar controllers that support WRSR without RDCR,
spi_nor_spimem_adjust_hwcaps() clears opcodes.read_sr2 while leaving
write_sr1_and_sr2 and the MTD OTP callbacks active. Once registered,
OTPLOCK runs spi_nor_otp_lock_sr2() -> spi_nor_read_sr1_and_sr2():
drivers/mtd/spi-nor/core.c:spi_nor_read_sr1_and_sr2() {
...
if (nor->params->opcodes.read_sr2)
ret = spi_nor_read_sr2(nor, &sr[1]);
else
sr[1] = 0;
return ret;
}
Because sr[1] is synthesized as 0, spi_nor_otp_lock_sr2() writes
sr[1] |= lock_bit via spi_nor_write_sr1_and_sr2_and_check(). That
clears all other non-volatile SR2 bits (such as QE and CMP), skips SR2
read-back verification because opcodes.read_sr2 is 0, and returns 0.
Should spi_nor_otp_lock_sr2() call spi_nor_read_sr1() and
spi_nor_read_sr2() directly (or reject !nor->params->opcodes.read_sr2
with -EOPNOTSUPP) so it fails cleanly like spi_nor_otp_is_locked_sr2()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-winbond-upstreaming-fix-sr2-einval-v1-1-ab136bfb2129@bootlin.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 11:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 11:08 [PATCH] mtd: spi-nor: Report missing SR2 support as -EOPNOTSUPP Miquel Raynal
2026-12-04 11:23 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox