[PATCH] mtd: core: skip empty read and write requests
From: James Hilliard
Date: Thu Nov 05 2026 - 00:06:33 EST
Converting mtd_read() and mtd_write() to wrappers around the OOB helpers
removed their zero-length checks. Neither mtd_read_oob() nor
mtd_write_oob() stops an empty request from reaching the driver.
For example, the raw NAND read paths select a target and can read a page
or its OOB area before checking the remaining length. An empty request
at the end of the device can therefore select a target past the last
available one.
Return success from the common helpers when both lengths are zero,
after mtd_check_oob_ops() has normalized lengths for absent buffers.
Keep the existing range, write-protection and operation-support checks,
and clear the per-request read statistics before returning. Both return
lengths have already been initialized to zero.
Fixes: 2431c4f5b46c ("mtd: Implement mtd_{read,write}() as wrappers around mtd_{read,write}_oob()")
Cc: stable@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/r/sashiko-outbox-198544@xxxxxxxxxx
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
drivers/mtd/mtdcore.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 491a27d0315f..93e7ff3ba8a0 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: 1c1a342aceec79528b3ba51f376eca2be5928fe7
change-id: 20261104-submit-mtd-empty-io-v1-6a06db864131
Best regards,
--
James Hilliard <james.hilliard1@xxxxxxxxx>