From: James Hilliard <james.hilliard1@gmail.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Boris Brezillon <bbrezillon@kernel.org>
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
James Hilliard <james.hilliard1@gmail.com>
Subject: [PATCH v2] mtd: core: skip empty read and write requests
Date: Wed, 18 Nov 2026 10:18:36 -0700 [thread overview]
Message-ID: <20261118-submit-mtd-empty-io-v1-v2-1-b980927931ef@gmail.com> (raw)
When mtd_read() and mtd_write() became wrappers around the OOB helpers,
they lost their zero-length checks. An empty read at the end of a raw
NAND device can then compute a die index one past the last die and hit
the WARN_ON() in nand_select_target().
Return success from the common helpers without calling the driver when
the request is valid but has neither data nor OOB bytes to transfer.
Fixes: 2431c4f5b46c ("mtd: Implement mtd_{read,write}() as wrappers around mtd_{read,write}_oob()")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/sashiko-outbox-198544@kernel.org
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
Changes in v2:
- Clarify that the invalid die index triggers a warning at EOF.
- Link to v1: https://patch.msgid.link/20261104-submit-mtd-empty-io-v1-v1-1-3f6bcf474e2a@gmail.com
---
drivers/mtd/mtdcore.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index b170c3144ca8..ea21dc1bb5de 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1805,6 +1805,9 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
if (ops->stats)
memset(ops->stats, 0, sizeof(*ops->stats));
+ if (!ops->len && !ops->ooblen)
+ return 0;
+
if (mtd->flags & MTD_SLC_ON_MLC_EMULATION)
ret_code = mtd_io_emulated_slc(mtd, from, true, ops);
else
@@ -1849,6 +1852,9 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,
if (!master->_write_oob && (!master->_write || ops->oobbuf))
return -EOPNOTSUPP;
+ if (!ops->len && !ops->ooblen)
+ return 0;
+
if (mtd->flags & MTD_SLC_ON_MLC_EMULATION)
return mtd_io_emulated_slc(mtd, to, false, ops);
---
base-commit: 760d2efe91a84363d25c1051a10572242e75fe86
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes
change-id: 20261104-submit-mtd-empty-io-v1-6a06db864131
Best regards,
--
James Hilliard <james.hilliard1@gmail.com>
reply other threads:[~2026-11-18 17:19 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=20261118-submit-mtd-empty-io-v1-v2-1-b980927931ef@gmail.com \
--to=james.hilliard1@gmail.com \
--cc=bbrezillon@kernel.org \
--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®