From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>,
"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
Subject: Re: [PATCH 2/5] mtd: docg3: invalidate staged OOB on page write and block erase
Date: Sat, 05 Dec 2026 06:03:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-251125@kernel.org> (raw)
In-Reply-To: <20261204-submit-docg3-oob-fixes-v1-v1-2-ea0bf6c535ca@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mtd: docg3: combined write consumes staged OOB on trailing
pages
- [Low] mtd: docg3: staged OOB survives failed erase in doc_erase()
--
commit 30ea8ea65f185fd87c50880ce4ae46feb2bd99fd
Author: James Hilliard <james.hilliard1@gmail.com>
mtd: docg3: invalidate staged OOB on page write and block erase
This commit starts the staged OOB slot empty, protects it with the
cascade lock, gives explicit OOB precedence in doc_write_oob(), and
clears the slot after the matching page is programmed or its block
pair is erased.
> diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
> index 9617b1ebba0f6..5b03a596e1007 100644
> --- a/drivers/mtd/devices/docg3.c
> +++ b/drivers/mtd/devices/docg3.c
[ ... ]
> @@ -1194,13 +1195,20 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *info)
> if (info->addr + info->len > mtd->size || page || ofs)
> return -EINVAL;
>
> + mutex_lock(&docg3->cascade->lock);
> + if (docg3->oob_write_ofs >= 0)
> + calc_block_sector(docg3->oob_write_ofs, &staged_block, &block1,
> + &page, &ofs, docg3->reliable);
> calc_block_sector(info->addr, &block0, &block1, &page, &ofs,
> docg3->reliable);
> - mutex_lock(&docg3->cascade->lock);
> doc_set_device_id(docg3, docg3->device_id);
> doc_set_reliable_mode(docg3);
> - for (len = info->len; !ret && len > 0; len -= mtd->erasesize) {
> + for (len = info->len; len > 0; len -= mtd->erasesize) {
> ret = doc_erase_block(docg3, block0, block1);
> + if (ret)
> + break;
> + if (block0 == staged_block)
> + docg3->oob_write_ofs = -1;
> block0 += 2;
> block1 += 2;
> }
[Severity: Low]
Can docg3->oob_write_ofs stay armed after doc_erase_block() has already
issued an erase to staged_block?
doc_erase_block() sends DOC_CMD_ERASECYCLE2 before waiting for status, so
a timeout (-EAGAIN) or single-plane failure (-EIO) can still leave the
block erased. Breaking before clearing oob_write_ofs lets a later
data-only write to that page consume stale pre-erase OOB bytes.
[ ... ]
> @@ -1387,15 +1391,23 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
> autoecc = ops->mode != MTD_OPS_RAW;
>
> mutex_lock(&docg3->cascade->lock);
> - while (!ret && len > 0) {
> + while (len > 0) {
> + int page_autoecc = autoecc;
> +
> memset(oob, 0, sizeof(oob));
> - if (ofs == docg3->oob_write_ofs)
> - memcpy(oob, docg3->oob_write_buf, DOC_LAYOUT_OOB_SIZE);
> - else if (ooblen > 0 && ops->mode == MTD_OPS_AUTO_OOB)
> + if (ooblen && ops->mode == MTD_OPS_AUTO_OOB)
> doc_fill_autooob(oob, oobbuf);
> - else if (ooblen > 0)
> + else if (ooblen)
> memcpy(oob, oobbuf, DOC_LAYOUT_OOB_SIZE);
> - ret = doc_write_page(docg3, ofs, buf, oob, autoecc);
> + else if (ofs == docg3->oob_write_ofs) {
> + memcpy(oob, docg3->oob_write_buf, sizeof(oob));
> + page_autoecc = docg3->oob_autoecc;
> + }
> + ret = doc_write_page(docg3, ofs, buf, oob, page_autoecc);
> + if (ret)
> + break;
> + if (ofs == docg3->oob_write_ofs)
> + docg3->oob_write_ofs = -1;
>
> ofs += DOC_LAYOUT_PAGE_SIZE;
> len -= DOC_LAYOUT_PAGE_SIZE;
[Severity: Medium]
Should this branch check !ops->ooblen instead of the loop-decremented
ooblen?
doc_oob_write_valid() allows combined writes where ops->ooblen covers
fewer pages than ops->len, as mtdchar_write_ioctl() can submit. Once
ooblen reaches zero mid-loop, a trailing page matching a staged
docg3->oob_write_ofs enters this branch.
That writes stale staged OOB bytes instead of zeros and overrides
page_autoecc with docg3->oob_autoecc, which can disable hardware ECC on an
ECC-protected write. Guarding this branch with !ops->ooblen prevents
that while still clearing the slot once the page is programmed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-submit-docg3-oob-fixes-v1-v1-0-ea0bf6c535ca@gmail.com?part=2
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-12-05 6:03 UTC|newest]
Thread overview: 13+ 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 ` 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 ` 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 ` James Hilliard
2026-12-05 6:03 ` sashiko-bot [this message]
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
2026-12-05 5:49 ` [PATCH 4/5] mtd: docg3: return the requested spare bytes in the selected OOB mode James Hilliard
2026-12-05 5:49 ` James Hilliard
2026-12-05 5:49 ` [PATCH 5/5] mtd: docg3: report the maximum bitflip count across read pages James Hilliard
2026-12-05 5:49 ` 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=sashiko-outbox-251125@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=David.Woodhouse@intel.com \
--cc=artem.bityutskiy@linux.intel.com \
--cc=computersforpeace@gmail.com \
--cc=ivan.djelic@parrot.com \
--cc=james.hilliard1@gmail.com \
--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=sashiko-reviews@lists.linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.