From 5ecfffcc52f54ea3471bd35724eb6cbee18f5fc2 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Fri, 3 Feb 2012 23:37:00 +0400 Subject: [PATCH] kvm tools: Fix test for mmap failure On error mmap returns MAP_FAILED so we need a proper test here. Signed-off-by: Cyrill Gorcunov Signed-off-by: Pekka Enberg --- hw/pci-shmem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/pci-shmem.c b/hw/pci-shmem.c index 8bac151..ac2d264 100644 --- a/hw/pci-shmem.c +++ b/hw/pci-shmem.c @@ -207,10 +207,11 @@ static void *setup_shmem(const char *key, size_t len, int creating) } mem = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd, 0); - close(fd); - - if (mem == NULL) + if (mem == MAP_FAILED) { pr_warning("Failed to mmap shared memory file"); + mem = NULL; + } + close(fd); return mem; }