[PATCH] mtd: rawnand: macronix: preserve OTP operation errors

James Hilliard james.hilliard1 at gmail.com
Sun Nov 8 14:33:04 PST 2026


The OTP read/write helper replaces the result of enabling OTP mode or
transferring data with the result of disabling OTP mode. Successful cleanup
therefore hides an earlier failure. The read wrapper can report an empty
transfer instead of the error, while the write wrapper converts it to
-ENOSPC because no bytes were reported.

Keep the operation result and the cleanup result separately. Return the
original error when an operation fails, or the cleanup error when the
operation succeeded. Still attempt to disable OTP mode after an enable
failure, since the failed command may already have changed the device.

Fixes: e87161321a40 ("mtd: rawnand: macronix: OTP access for MX30LFxG18AC")
Cc: stable at vger.kernel.org
Closes: https://lore.kernel.org/r/sashiko-outbox-204080@kernel.org/
Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
---
 drivers/mtd/nand/raw/nand_macronix.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c
index 03237310852c..16847f28b19d 100644
--- a/drivers/mtd/nand/raw/nand_macronix.c
+++ b/drivers/mtd/nand/raw/nand_macronix.c
@@ -377,7 +377,7 @@ static int __macronix_30lfxg18ac_rw_otp(struct mtd_info *mtd,
 	size_t bytes_handled;
 	off_t offs_in_page;
 	u64 page;
-	int ret;
+	int ret, cleanup_ret;
 
 	nand = mtd_to_nand(mtd);
 	nand_select_target(nand, 0);
@@ -420,14 +420,14 @@ static int __macronix_30lfxg18ac_rw_otp(struct mtd_info *mtd,
 	if (ret)
 		dev_err(&mtd->dev, "failed to perform OTP IO: %i\n", ret);
 
-	ret = macronix_30lfxg18ac_otp_disable(nand);
-	if (ret)
+	cleanup_ret = macronix_30lfxg18ac_otp_disable(nand);
+	if (cleanup_ret)
 		dev_err(&mtd->dev, "failed to leave OTP mode after %s\n",
 			write ? "write" : "read");
 
 	nand_deselect_target(nand);
 
-	return ret;
+	return ret ? ret : cleanup_ret;
 }
 
 static int macronix_30lfxg18ac_write_otp(struct mtd_info *mtd, loff_t to,

---
base-commit: 30daaf3e7897b4a8d9b72e5b0c86dd6e2a4d7d85
change-id: 20261108-submit-macronix-otp-errors-v1-0f83783917cd

Best regards,
--  
James Hilliard <james.hilliard1 at gmail.com>




More information about the linux-mtd mailing list