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 de8df96e860 mtd: config: check the release-marker write
de8df96e860 is described below
commit de8df96e860c900cc81b1523b1a4adaf3dcb791c
Author: Honghao Xiang <[email protected]>
AuthorDate: Thu Nov 26 06:30:23 2026 +0000
mtd: config: check the release-marker write
Both mtdconfig_setconfig() (overwriting an existing entry) and
mtdconfig_deleteconfig() mark an entry as released by writing a single
flag byte, but neither checks the return value of
mtdconfig_writebytes(). A failed write is therefore reported as success,
and the old entry stays valid while the caller believes the value was
overwritten or deleted.
Check the returned byte count in both paths and report -EIO when the
marker could not be written.
Signed-off-by: Honghao Xiang <[email protected]>
---
drivers/mtd/mtd_config.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/mtd_config.c b/drivers/mtd/mtd_config.c
index 6bf3e64f10f..2a30fd49817 100644
--- a/drivers/mtd/mtd_config.c
+++ b/drivers/mtd/mtd_config.c
@@ -1236,7 +1236,13 @@ retry:
/* Mark this entry as released */
hdr.flags = (uint8_t)~MTD_ERASED_FLAGS(dev);
- mtdconfig_writebytes(dev, offset, &hdr.flags, sizeof(hdr.flags));
+ ret = mtdconfig_writebytes(dev, offset, &hdr.flags,
+ sizeof(hdr.flags));
+ if (ret != sizeof(hdr.flags))
+ {
+ ret = -EIO;
+ goto errout;
+ }
}
/* Test if the new length is zero. If it is, then we are
@@ -1494,9 +1500,16 @@ static int mtdconfig_deleteconfig(FAR struct
mtdconfig_struct_s *dev,
/* Entry found. Mark this entry as released */
hdr.flags = (uint8_t)~MTD_ERASED_FLAGS(dev);
- mtdconfig_writebytes(dev, offset, &hdr.flags, sizeof(hdr.flags));
-
- ret = OK;
+ ret = mtdconfig_writebytes(dev, offset, &hdr.flags,
+ sizeof(hdr.flags));
+ if (ret != sizeof(hdr.flags))
+ {
+ ret = -EIO;
+ }
+ else
+ {
+ ret = OK;
+ }
}
/* Free the buffer */