mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Hilliard <james.hilliard1@gmail.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>,
	 Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	 Arseniy Krasnov <AVKrasnov@sberdevices.ru>
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
	 stable@vger.kernel.org,
	James Hilliard <james.hilliard1@gmail.com>
Subject: [PATCH] mtd: rawnand: macronix: preserve OTP operation errors
Date: Sun, 08 Nov 2026 15:33:04 -0700	[thread overview]
Message-ID: <20261108-submit-macronix-otp-errors-v1-v1-1-8f64a2ad5a10@gmail.com> (raw)

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@vger.kernel.org
Closes: https://lore.kernel.org/r/sashiko-outbox-204080@kernel.org/
Signed-off-by: James Hilliard <james.hilliard1@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@gmail.com>


                 reply	other threads:[~2026-11-08 22:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261108-submit-macronix-otp-errors-v1-v1-1-8f64a2ad5a10@gmail.com \
    --to=james.hilliard1@gmail.com \
    --cc=AVKrasnov@sberdevices.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=stable@vger.kernel.org \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®