Skip to contentSkip to conversation

mtd: core: skip empty read and write requests

PATCH Applied James Hilliard 2 participants 2 messages Nov 18 – Nov 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mtd: core: skip empty read and write requests

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()")

---
Changes in v2:
- Clarify that the invalid die index triggers a warning at EOF.
- Link to v1: https://patch.msgid.link/[email protected]

---
 drivers/mtd/mtdcore.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/mtd/mtdcore.c +6 -0
index b170c3144ca8..ea21dc1bb5de 100644
@@ -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,

Signature · 1 line
James Hilliard <[email protected]>
maintainer Applied
#1 lore raw
Quoted 9 lines · James Hilliard

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.

[...]

Applied to mtd/next, thanks!

[1/1] mtd: core: skip empty read and write requests

      commit: 3db54924e7fa664dd6303f3bd0cb1eeceb1f513e

Patche(s) should be available on mtd/linux.git and will be part of the next PR (provided that no robot complains by then).

Kind regards,
Miquèl