[PATCH] mtd: rawnand: copy OOB only after completing read retries

From: James Hilliard

Date: Wed Nov 04 2026 - 01:13:51 EST


nand_do_read_ops() copies OOB to the caller and advances the output cursor
before deciding whether an ECC failure requires another read attempt.
The retry restores ECC statistics but does not restore the OOB cursor or
remaining length.

For a combined data/OOB read, a successful retry can therefore leave OOB
from the failed attempt in the first output slot and put the retried
page's OOB in the next page's slot. A later transport error also leaves
oobretlen accounting for attempts rather than completed pages.

Copy and account for OOB after the retry decision. A successful read or
an exhausted retry sequence contributes OOB once, while an attempt that
will be retried does not consume the caller's output buffer.

Fixes: ba84fb5952af ("mtd: nand: add generic READ RETRY support")
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
drivers/mtd/nand/raw/nand_base.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index a5b278ab9384..361918d11ce4 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -3537,16 +3537,6 @@ static int nand_do_read_ops(struct nand_chip *chip, loff_t from,
memcpy(buf, bufpoi + col, bytes);
}

- if (unlikely(oob)) {
- int toread = min(oobreadlen, max_oobsize);
-
- if (toread) {
- oob = nand_transfer_oob(chip, oob, ops,
- toread);
- oobreadlen -= toread;
- }
- }
-
nand_wait_readrdy(chip);

if (mtd->ecc_stats.failed - ecc_stats.failed) {
@@ -3566,6 +3556,16 @@ static int nand_do_read_ops(struct nand_chip *chip, loff_t from,
}
}

+ if (unlikely(oob)) {
+ int toread = min(oobreadlen, max_oobsize);
+
+ if (toread) {
+ oob = nand_transfer_oob(chip, oob, ops,
+ toread);
+ oobreadlen -= toread;
+ }
+ }
+
buf += bytes;
max_bitflips = max_t(unsigned int, max_bitflips, ret);
} else {

---
base-commit: 30daaf3e7897b4a8d9b72e5b0c86dd6e2a4d7d85
change-id: 20261103-submit-rawnand-read-retry-oob-v1-b97a735a3889

Best regards,
--
James Hilliard <james.hilliard1@xxxxxxxxx>