public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mtd: spi-nor: core: Fix false positive in Read CR capability check
@ 2026-02-24  2:55 Cheng Ming Lin
  2026-02-24  8:24 ` Miquel Raynal
  0 siblings, 1 reply; 3+ messages in thread
From: Cheng Ming Lin @ 2026-02-24  2:55 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav, Michael Walle, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: Jakub Czapiga, linux-mtd, linux-kernel, alvinzhou, Cheng Ming Lin

From: Cheng Ming Lin <chengminglin@mxic.com.tw>

The current code uses spi_nor_spimem_check_op() to check if the SPI
controller supports the Read CR operation. However, this leads to a
false positive where capable controllers are wrongly flagged with
SNOR_F_NO_READ_CR.

SPI_NOR_RDCR_OP defines an operation without an address phase
(addr.nbytes = 0, addr.buswidth = 0). When this operation is passed
to spi_nor_spimem_check_op(), the function overwrites op->addr.nbytes
to 3 or 4 to test addressing capabilities (as it was originally designed
for data read/write ops).

This modified operation is then rejected by spi_mem_check_op() in the
core spi-mem.c because it has a non-zero address length but a zero address
buswidth, which is an invalid combination.

Fix this by bypassing spi_nor_spimem_check_op() for register operations.
Instead, directly call spi_mem_supports_op() to test the exact operation
without altering its address phase.

Fixes: 5008c3ec3f89 ("mtd: spi-nor: core: Check read CR support")
Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw>
---
 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 8ffeb41c3e08..13201908a69f 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2466,7 +2466,7 @@ spi_nor_spimem_adjust_hwcaps(struct spi_nor *nor, u32 *hwcaps)
 
 		spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
 
-		if (spi_nor_spimem_check_op(nor, &op))
+		if (!spi_mem_supports_op(nor->spimem, &op))
 			nor->flags |= SNOR_F_NO_READ_CR;
 	}
 }
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-24  8:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-24  2:55 [PATCH] mtd: spi-nor: core: Fix false positive in Read CR capability check Cheng Ming Lin
2026-02-24  8:24 ` Miquel Raynal
2026-02-24  8:32   ` Cheng Ming Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox