Skip to contentSkip to conversation

mtd: spi-nor: core: Fix false positive in Read CR capability check

PATCH In review Cheng Ming Lin 2 participants 3 messages Feb 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: spi-nor: core: Fix false positive in Read CR capability check

From: Cheng Ming Lin <[email protected]>

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")
---
 drivers/mtd/spi-nor/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/core.c +1 -1
index 8ffeb41c3e08..13201908a69f 100644
@@ -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;
 	}
 }
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi Cheng Ming,

Quoted 17 lines · Cheng Ming Lin

From: Cheng Ming Lin <[email protected]>

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.

Quoted 6 lines

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")

That is indeed a problem, I already sent a patch for that but there is a bit of turnover in the spi-nor team. It hasn't been acked so I didn't took it through the final MR. The problem now exists in 7.0-rc1, see:

https://lore.kernel.org/linux-mtd/[email protected]/

Quoted 17 lines
---
 drivers/mtd/spi-nor/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/core.c +1 -1
index 8ffeb41c3e08..13201908a69f 100644
@@ -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 lore raw

Hi Miquel,

Miquel Raynal <[email protected]> 於 2026年2月24日週二 下午4:24寫道:

Quoted 26 lines

Hi Cheng Ming,

Quoted 21 lines · Cheng Ming Lin

From: Cheng Ming Lin <[email protected]>

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.

Quoted 8 lines
Quoted 2 lines
Fixes 5008c3ec3f89 ("mtd: spi-nor: core: Check read CR support")

That is indeed a problem, I already sent a patch for that but there is a bit of turnover in the spi-nor team. It hasn't been acked so I didn't took it through the final MR. The problem now exists in 7.0-rc1, see:

https://lore.kernel.org/linux-mtd/[email protected]/

Understood, thank you for pointing that out. I completely missed your previous patch when I was looking into this issue.

Thanks again for the clarification!

Quoted 11 lines
Quoted 11 lines
---
 drivers/mtd/spi-nor/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/core.c +0 -0
index 8ffeb41c3e08..13201908a69f 100644
@@ -2466,7 +2466,7 @@ spi_nor_spimem_adjust_hwcaps(struct spi_nor *nor, u32 *hwcaps)
 
Quoted 7 lines

drivers/mtd/spi-nor/core.c spi_nor_spimem_adjust_hwcaps(struct spi_nor *nor, u32 *hwcaps) · line 2472

Quoted 7 lines
drivers/mtd/spi-nor/core.c +1 -1
              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;
      }
 }

Best regards,
Cheng Ming Lin