[PATCH v2] kexec: fix mmap return code handling

Michael Holzheu holzheu at linux.vnet.ibm.com
Thu Nov 26 09:32:31 PST 2015


Hi Simon again,

After a bit more thinking: In theory mmap() could also return NULL.
Therefore the following fix is probably the better one ...
---
Subject: [PATCH] kexec: fix mmap return code handling

When mmap fails, MAP_FAILED (that is, (void *) -1) is returned. Currently
we assume that NULL is returned. Fix this and add the MAP_FAILED check.

Fixes: 95741713e790 ("kexec/s390x: use mmap instead of read for slurp_file")
Signed-off-by: Michael Holzheu <holzheu at linux.vnet.ibm.com>

diff --git a/kexec/kexec.c b/kexec/kexec.c
index cf6e03d..f0bd527 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -573,7 +573,7 @@ static char *slurp_file_generic(const char *filename, off_t *r_size,
 			buf = slurp_fd(fd, filename, size, &nread);
 		}
 	}
-	if (!buf)
+	if ((use_mmap && (buf == MAP_FAILED)) || (!use_mmap && (buf == NULL)))
 		die("Cannot read %s", filename);
 
 	if (nread != size)
-- 
2.3.9




More information about the kexec mailing list