public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm tools: Fix test for mmap failure
@ 2012-02-03 19:15 Cyrill Gorcunov
  2012-02-03 19:37 ` Cyrill Gorcunov
  0 siblings, 1 reply; 3+ messages in thread
From: Cyrill Gorcunov @ 2012-02-03 19:15 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Sasha Levin, Asias He, Ingo Molnar, KVM-ML

On error mmap returns MAP_FAILED so we
need a proper test here.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 tools/kvm/hw/pci-shmem.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Index: linux-2.6.git/tools/kvm/hw/pci-shmem.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/hw/pci-shmem.c
+++ linux-2.6.git/tools/kvm/hw/pci-shmem.c
@@ -209,7 +209,7 @@ static void *setup_shmem(const char *key
 		   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");
 
 	return mem;
@@ -259,8 +259,9 @@ int pci_shmem__init(struct kvm *kvm)
 	/* Open shared memory and plug it into the guest */
 	mem = setup_shmem(shmem_region->handle, shmem_region->size,
 				shmem_region->create);
-	if (mem == NULL)
+	if (mem == MAP_FAILED)
 		return 0;
+
 	kvm__register_mem(kvm, shmem_region->phys_addr, shmem_region->size,
 			  mem);
 	return 1;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kvm tools: Fix test for mmap failure
  2012-02-03 19:15 [PATCH] kvm tools: Fix test for mmap failure Cyrill Gorcunov
@ 2012-02-03 19:37 ` Cyrill Gorcunov
  2012-02-04  7:24   ` Pekka Enberg
  0 siblings, 1 reply; 3+ messages in thread
From: Cyrill Gorcunov @ 2012-02-03 19:37 UTC (permalink / raw)
  To: Pekka Enberg, Sasha Levin, Asias He, Ingo Molnar, KVM-ML

On Fri, Feb 03, 2012 at 11:15:41PM +0400, Cyrill Gorcunov wrote:
> On error mmap returns MAP_FAILED so we
> need a proper test here.
>

Pekka, pick this one instead -- a caller is expecting null/not-null
only.

	Cyrill
---
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 <gorcunov@gmail.com>
---
 tools/kvm/hw/pci-shmem.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Index: linux-2.6.git/tools/kvm/hw/pci-shmem.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/hw/pci-shmem.c
+++ linux-2.6.git/tools/kvm/hw/pci-shmem.c
@@ -207,10 +207,11 @@ static void *setup_shmem(const char *key
 	}
 	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;
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kvm tools: Fix test for mmap failure
  2012-02-03 19:37 ` Cyrill Gorcunov
@ 2012-02-04  7:24   ` Pekka Enberg
  0 siblings, 0 replies; 3+ messages in thread
From: Pekka Enberg @ 2012-02-04  7:24 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: Sasha Levin, Asias He, Ingo Molnar, KVM-ML

On Fri, Feb 03, 2012 at 11:15:41PM +0400, Cyrill Gorcunov wrote:
>> On error mmap returns MAP_FAILED so we
>> need a proper test here.

On Fri, 3 Feb 2012, Cyrill Gorcunov wrote:
> Pekka, pick this one instead -- a caller is expecting null/not-null
> only.

Applied, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-04  7:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-03 19:15 [PATCH] kvm tools: Fix test for mmap failure Cyrill Gorcunov
2012-02-03 19:37 ` Cyrill Gorcunov
2012-02-04  7:24   ` Pekka Enberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox