This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 9d39d1caf46 mtd: config: mark the entry released when the data write
fails
9d39d1caf46 is described below
commit 9d39d1caf461ea167056e2cef1e1372c3c795ffe
Author: Honghao Xiang <[email protected]>
AuthorDate: Thu Nov 26 05:50:39 2026 +0000
mtd: config: mark the entry released when the data write fails
In mtdconfig_setconfig(), when the payload write returns fewer bytes than
requested the error path rewrites the header flags with the erased-slot
value. The header was already written with that same value, so the
rewrite changes nothing: the partially written entry keeps a valid
id/instance and mtdconfig_findentry() still returns it, so a later read
returns a truncated payload.
Use the release marker that delete/overwrite already use, so lookups skip
the failed record and consolidation does not copy it.
Signed-off-by: Honghao Xiang <[email protected]>
---
drivers/mtd/mtd_config.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/mtd_config.c b/drivers/mtd/mtd_config.c
index a555931d39b..6bf3e64f10f 100644
--- a/drivers/mtd/mtd_config.c
+++ b/drivers/mtd/mtd_config.c
@@ -1362,9 +1362,12 @@ retry_find:
pdata->configdata, pdata->len);
if (bytes != pdata->len)
{
- /* Error writing data! */
+ /* Error writing data! Mark the entry as released (the same
+ * marker used by delete/overwrite) so that the partially written
+ * payload cannot be read back later.
+ */
- hdr.flags = MTD_ERASED_FLAGS(dev);
+ hdr.flags = (uint8_t)~MTD_ERASED_FLAGS(dev);
mtdconfig_writebytes(dev, offset, (FAR uint8_t *)&hdr,
sizeof(hdr.flags));
ret = -EIO;