This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 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 2c7c1b466bc mtd: config: propagate consolidation errors from SET
2c7c1b466bc is described below
commit 2c7c1b466bc45502f13119b88c362b7d2c88d79e
Author: Honghao Xiang <[email protected]>
AuthorDate: Thu Nov 26 08:09:39 2026 +0000
mtd: config: propagate consolidation errors from SET
mtdconfig_ramconsolidate() and mtdconfig_consolidate() return an offset
on success and returned 0 on every error path. mtdconfig_setconfig()
ignores that value, retries the free-entry search and can then report
-ENOMEM even though the real failure was an I/O error during
consolidation.
Return the negative error from both helpers (and -ENOMEM when the
temporary buffer cannot be allocated), and check the off_t result at the
two call sites before narrowing it, so a failed consolidation reaches the
caller with its original error.
Signed-off-by: Honghao Xiang <[email protected]>
---
drivers/mtd/mtd_config.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/mtd_config.c b/drivers/mtd/mtd_config.c
index 2a30fd49817..da88ac3b21c 100644
--- a/drivers/mtd/mtd_config.c
+++ b/drivers/mtd/mtd_config.c
@@ -581,7 +581,7 @@ static off_t mtdconfig_ramconsolidate(FAR struct
mtdconfig_struct_s *dev)
{
/* Unable to allocate buffer, can't consolidate! */
- return 0;
+ return -ENOMEM;
}
/* Loop for all blocks and consolidate them */
@@ -730,7 +730,7 @@ static off_t mtdconfig_ramconsolidate(FAR struct
mtdconfig_struct_s *dev)
errout:
kmm_free(pbuf);
ferr("ERROR: fail ram consolidate: %d\n", ret);
- return 0;
+ return (off_t)ret;
}
/****************************************************************************
@@ -779,7 +779,7 @@ static off_t mtdconfig_consolidate(FAR struct
mtdconfig_struct_s *dev)
pbuf = kmm_malloc(dev->blocksize);
if (pbuf == NULL)
{
- return 0;
+ return -ENOMEM;
}
/* Now copy block zero to last block */
@@ -1000,7 +1000,7 @@ retry_relocate:
errout:
kmm_free(pbuf);
ferr("ERROR: fail consolidate: %d\n", ret);
- return 0;
+ return (off_t)ret;
}
#endif /* CONFIG_MTD_CONFIG_RAM_CONSOLIDATE */
@@ -1316,7 +1316,13 @@ retry_find:
goto errout;
}
- mtdconfig_ramconsolidate(dev);
+ offset = mtdconfig_ramconsolidate(dev);
+ if (offset < 0)
+ {
+ ret = (int)offset;
+ goto errout;
+ }
+
retrycount++;
goto retry_find;
}
@@ -1331,7 +1337,13 @@ retry_find:
goto errout;
}
- mtdconfig_consolidate(dev);
+ offset = mtdconfig_consolidate(dev);
+ if (offset < 0)
+ {
+ ret = (int)offset;
+ goto errout;
+ }
+
retrycount++;
goto retry_find;
}