From: James Hilliard <james.hilliard1@gmail.com>
To: Robert Jarzmik <robert.jarzmik@free.fr>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Ivan Djelic <ivan.djelic@parrot.com>,
David Woodhouse <David.Woodhouse@intel.com>,
Mike Dunn <mikedunn@newsguy.com>,
Brian Norris <computersforpeace@gmail.com>,
Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
James Hilliard <james.hilliard1@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH 4/5] mtd: docg3: return the requested spare bytes in the selected OOB mode
Date: Fri, 04 Dec 2026 22:49:30 -0700 [thread overview]
Message-ID: <20261204-submit-docg3-oob-fixes-v1-v1-4-ea0bf6c535ca@gmail.com> (raw)
In-Reply-To: <20261204-submit-docg3-oob-fixes-v1-v1-0-ea0bf6c535ca@gmail.com>
An AUTO read of eight bytes should return the seven page-information
bytes and the final free byte. DiskOnChip G3 instead requires reads in
multiples of 16 and copies physical spare bytes, including ECC. PLACE
reads also apply the spare offset to the destination instead of the page.
Read the physical spare area into a local buffer. Keep the chip's read
and drain phases, including the NOPs issued by an empty phase. Copy
AUTO bytes from the free regions and PLACE or RAW bytes from the
requested physical offset. Apply the offset only to the first page and
reject unknown modes before accessing the chip.
Fixes: efa2ca73a7bc ("mtd: Add DiskOnChip G3 support")
Cc: stable@vger.kernel.org
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/mtd/devices/docg3.c | 52 ++++++++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 17 deletions(-)
diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index 5c1d667c8f8b..c00693aba84a 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -852,6 +852,12 @@ static void calc_block_sector(loff_t from, int *block0, int *block1, int *page,
*ofs = 0;
}
+static bool doc_oob_mode_valid(unsigned int mode)
+{
+ return mode == MTD_OPS_PLACE_OOB || mode == MTD_OPS_AUTO_OOB ||
+ mode == MTD_OPS_RAW;
+}
+
/**
* doc_read_oob - Read out of band bytes from flash
* @mtd: the device
@@ -871,6 +877,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
u8 *oobbuf = ops->oobbuf;
u8 *buf = ops->datbuf;
size_t len, ooblen, nbdata, nboob;
+ unsigned int ooboffs = ops->ooboffs, oobavail = mtd_oobavail(mtd, ops);
u8 oob[DOC_LAYOUT_OOB_SIZE] __aligned(2);
u8 hwecc[DOC_ECC_BCH_SIZE], eccconf1;
struct mtd_ecc_stats old_stats;
@@ -885,12 +892,9 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
else
ooblen = 0;
- if (oobbuf && ops->mode == MTD_OPS_PLACE_OOB)
- oobbuf += ops->ooboffs;
-
doc_dbg("doc_read_oob(from=%lld, mode=%d, data=(%p:%zu), oob=(%p:%zu))\n",
from, ops->mode, buf, len, oobbuf, ooblen);
- if (ooblen % DOC_LAYOUT_OOB_SIZE)
+ if (!doc_oob_mode_valid(ops->mode) || (ooblen && ooboffs >= oobavail))
return -EINVAL;
ops->oobretlen = 0;
@@ -900,10 +904,12 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
mutex_lock(&docg3->cascade->lock);
old_stats = mtd->ecc_stats;
while (ret >= 0 && (len > 0 || ooblen > 0)) {
+ unsigned int spare_len;
+
calc_block_sector(from - skip, &block0, &block1, &page, &ofs,
docg3->reliable);
nbdata = min_t(size_t, len, DOC_LAYOUT_PAGE_SIZE - skip);
- nboob = min_t(size_t, ooblen, (size_t)DOC_LAYOUT_OOB_SIZE);
+ nboob = min_t(size_t, ooblen, oobavail - ooboffs);
ret = doc_read_page_prepare(docg3, block0, block1, page, ofs);
if (ret < 0)
goto out;
@@ -919,16 +925,16 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
doc_read_page_getbytes(docg3,
DOC_LAYOUT_PAGE_SIZE - nbdata - skip,
NULL, 0, (skip + nbdata) % 2);
- ret = doc_read_page_getbytes(docg3, nboob, oob, 0, 0);
- if (ret < nboob)
- goto err_in_read;
- doc_read_page_getbytes(docg3, DOC_LAYOUT_OOB_SIZE - nboob,
- oob + nboob, 0, nboob % 2);
+ /* Both spare-area phases issue NOPs, even if one is empty. */
+ spare_len = nboob ? sizeof(oob) : 0;
+ doc_read_page_getbytes(docg3, spare_len, oob, 0, 0);
+ doc_read_page_getbytes(docg3, sizeof(oob) - spare_len,
+ oob + spare_len, 0, 0);
doc_get_bch_hw_ecc(docg3, hwecc);
eccconf1 = doc_register_readb(docg3, DOC_ECCCONF1);
- if (nboob >= DOC_LAYOUT_OOB_SIZE) {
+ if (nboob) {
doc_dbg("OOB - INFO: %*phC\n", 7, oob);
doc_dbg("OOB - HAMMING: %02x\n", oob[7]);
doc_dbg("OOB - BCH_ECC: %*phC\n", 7, oob + 8);
@@ -958,15 +964,28 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
}
}
- if (nboob)
- memcpy(oobbuf, oob, nboob);
+ if (nboob && ops->mode == MTD_OPS_AUTO_OOB) {
+ int err;
+
+ err = mtd_ooblayout_get_databytes(mtd, oobbuf, oob,
+ ooboffs, nboob);
+ if (err) {
+ ret = err;
+ goto err_in_read;
+ }
+ } else if (nboob) {
+ memcpy(oobbuf, oob + ooboffs, nboob);
+ }
doc_read_page_finish(docg3);
ops->retlen += nbdata;
ops->oobretlen += nboob;
- buf += nbdata;
- oobbuf += nboob;
+ if (nbdata)
+ buf += nbdata;
+ if (nboob)
+ oobbuf += nboob;
len -= nbdata;
ooblen -= nboob;
+ ooboffs = 0;
from += DOC_LAYOUT_PAGE_SIZE;
skip = 0;
}
@@ -1316,8 +1335,7 @@ static bool doc_oob_write_valid(struct mtd_info *mtd, u64 to, struct mtd_oob_ops
{
u32 avail = mtd_oobavail(mtd, ops);
- if (ops->mode != MTD_OPS_PLACE_OOB && ops->mode != MTD_OPS_AUTO_OOB &&
- ops->mode != MTD_OPS_RAW)
+ if (!doc_oob_mode_valid(ops->mode))
return false;
if (to % DOC_LAYOUT_PAGE_SIZE || ops->len % DOC_LAYOUT_PAGE_SIZE ||
(ops->ooblen && (ops->ooboffs || ops->ooblen % avail)))
--
2.53.0
next prev parent reply other threads:[~2026-12-05 5:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 5:49 [PATCH 0/5] mtd: docg3: fix spare-area transfers and ECC reporting James Hilliard
2026-12-05 5:49 ` [PATCH 1/5] mtd: docg3: check whole-page OOB writes in the selected mode James Hilliard
2026-12-05 5:49 ` [PATCH 2/5] mtd: docg3: invalidate staged OOB on page write and block erase James Hilliard
2026-12-05 5:49 ` [PATCH 3/5] mtd: docg3: correct BCH errors in the buffer holding the affected byte James Hilliard
2026-12-05 5:49 ` James Hilliard [this message]
2026-12-05 5:49 ` [PATCH 5/5] mtd: docg3: report the maximum bitflip count across read pages James Hilliard
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=20261204-submit-docg3-oob-fixes-v1-v1-4-ea0bf6c535ca@gmail.com \
--to=james.hilliard1@gmail.com \
--cc=David.Woodhouse@intel.com \
--cc=artem.bityutskiy@linux.intel.com \
--cc=computersforpeace@gmail.com \
--cc=ivan.djelic@parrot.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=mikedunn@newsguy.com \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=robert.jarzmik@free.fr \
--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®