Skip to contentSkip to conversation

scripts/sorttable: Handle mmap() failure gracefully

PATCH Superseded Michal Luczaj 1 participant 1 message Jul 26, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/sorttable: Handle mmap() failure gracefully

When mmap() fails, don't propagate MAP_FAILED as the return value. Caller expects NULL on error.

Fixes 3c47b787b651 ("scripts/sortextable: Rewrite error/success handling")

---
...

  LD      vmlinux
  BTFIDS  vmlinux
  NM      System.map

SORTTAB vmlinux
Could not mmap file: vmlinux
scripts/link-vmlinux.sh: line 200: 2688 Segmentation fault (core dumped) ${objtree}/scripts/sorttable ${1}
Failed to sort kernel tables

---
 scripts/sorttable.c | 1 +
 1 file changed, 1 insertion(+)
scripts/sorttable.c +1 -0
index 83cdb843d92f..2ffdf580caa5 100644
@@ -101,6 +101,7 @@ static void *mmap_file(char const *fname, size_t *size)
 	addr = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
 	if (addr == MAP_FAILED) {
 		fprintf(stderr, "Could not mmap file: %s\n", fname);
+		addr = NULL;
 		goto out;
 	}
 

---
base-commit: 1722389b0d863056d78287a120a1d6cadb8d4f7b
change-id: 20240723-sorttable-fix-08b9ce81db32

Best regards,

Signature · 1 line
Michal Luczaj <[email protected]>