[PATCH] mtd: spi-nor: micron-st: fix FSR read fallback for controllers returning -ENOTSUPP

Bean Huo posted 1 patch 2 weeks, 5 days ago
drivers/mtd/spi-nor/micron-st.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] mtd: spi-nor: micron-st: fix FSR read fallback for controllers returning -ENOTSUPP
Posted by Bean Huo 2 weeks, 5 days ago
From: Bean Huo <beanhuo@micron.com>

micron_st_nor_ready() falls back to SR-only polling when the SPI
controller does not support low-level FSR reads, but only checks for
-EOPNOTSUPP (95).  Some SPI master drivers return the kernel-internal
-ENOTSUPP (524) for the same condition.  The two codes carry identical
semantics but have different numeric values, so the fallback is never
reached when the master returns -ENOTSUPP; the function propagates the
error instead, causing all subsequent erase/program operations on the
Micron flash to fail.

Fix this by treating -ENOTSUPP equivalently to -EOPNOTSUPP in the FSR
error path.  Note that spi-mem.c already treats both error codes as
equivalent in its own fallback logic, so this aligns micron_st_nor_ready()
with that existing convention.

Fixes: 90c517f435a9 ("mtd: spi-nor: micron-st: Skip FSR reading if SPI controller does not support it")
Reported-by: Zailiang Zhang <zaizhang@cisco.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
---
 drivers/mtd/spi-nor/micron-st.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/micron-st.c b/drivers/mtd/spi-nor/micron-st.c
index 88033384a71e..4be6a76fc3e5 100644
--- a/drivers/mtd/spi-nor/micron-st.c
+++ b/drivers/mtd/spi-nor/micron-st.c
@@ -598,7 +598,7 @@ static int micron_st_nor_ready(struct spi_nor *nor)
 		 * operations to the software. If this is the case we use
 		 * only the status register value.
 		 */
-		return ret == -EOPNOTSUPP ? sr_ready : ret;
+		return (ret == -EOPNOTSUPP || ret == -ENOTSUPP) ? sr_ready : ret;
 	}
 
 	if (nor->bouncebuf[0] & (FSR_E_ERR | FSR_P_ERR)) {
-- 
2.34.1
Re: [PATCH] mtd: spi-nor: micron-st: fix FSR read fallback for controllers returning -ENOTSUPP
Posted by Tudor Ambarus 2 weeks, 5 days ago
Hi, Bean!

On 3/18/26 3:18 PM, Bean Huo wrote:
> From: Bean Huo <beanhuo@micron.com>
> 
> micron_st_nor_ready() falls back to SR-only polling when the SPI
> controller does not support low-level FSR reads, but only checks for
> -EOPNOTSUPP (95).  Some SPI master drivers return the kernel-internal
> -ENOTSUPP (524) for the same condition.  The two codes carry identical

Isn't it a better fix to update the spi controllers to use EOPNOTSUPP?
Re: [PATCH] mtd: spi-nor: micron-st: fix FSR read fallback for controllers returning -ENOTSUPP
Posted by Bean Huo 2 weeks, 5 days ago
On Wed, 2026-03-18 at 15:26 +0200, Tudor Ambarus wrote:
> Hi, Bean!
> 
> On 3/18/26 3:18 PM, Bean Huo wrote:
> > From: Bean Huo <beanhuo@micron.com>
> > 
> > micron_st_nor_ready() falls back to SR-only polling when the SPI
> > controller does not support low-level FSR reads, but only checks for
> > -EOPNOTSUPP (95).  Some SPI master drivers return the kernel-internal
> > -ENOTSUPP (524) for the same condition.  The two codes carry identical
> 
> Isn't it a better fix to update the spi controllers to use EOPNOTSUPP?


Hi Zailiang Zhang, 

Can you forward this to your colleagues and check if the SPI master driver can
be fixed to return -EOPNOTSUPP instead of -ENOTSUPP?


Hi Tudor,
                                                                                                                      
Thank you for the review.
                                                                                                                      
You are right that fixing the spi controller to return -EOPNOTSUPP is the ideal
solution, and I have reached out to the reporter to investigate on their end.  
                                                                                                                      
However, I would suggest keeping this fix in micron-st.c for the following
reasons:                           
   
1, The offending SPI master driver appears to be out-of-tree/downstream, so we
cannot guarantee an upstream fix will reach all affected platforms.
2, spi-mem.c already treats both -ENOTSUPP and -EOPNOTSUPP as equivalent in
spi_mem_exec_op() so this one-liner aligns micron_st_nor_ready() with the
convention already established in the SPI mem framework.
3, there may be other SPI controllers in the field with the same behavior that
we are not aware of. A defensive fix here costs nothing and prevents future
reports. 

I am happy to drop this patch if you feel strongly that the fix belongs only in
the controller driver and the reporter confirms they can fix it on their spi nor
master driver.

Kind regards,
Bean