[Concept,03/17] sandbox: Return -ENOMEM when os_map_file() fails

Message ID 20260316183050.3855921-4-sjg@u-boot.org
State New
Headers
Series Add automatic memory-leak detection to U-Boot tests |

Commit Message

Simon Glass March 16, 2026, 6:30 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

os_map_file() returns -EPERM for all mmap() failures regardless of
the actual errno. When mmap() fails with ENOMEM, return -ENOMEM so
that callers can distinguish out-of-memory from other errors.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/cpu/os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 142b685e031..c1381775b1b 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -299,7 +299,7 @@  int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep)
 	ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, ifd, 0);
 	if (ptr == MAP_FAILED) {
 		printf("Can't map file '%s': %s\n", pathname, strerror(errno));
-		ret = -EPERM;
+		ret = errno == ENOMEM ? -ENOMEM : -EPERM;
 		goto out;
 	}