From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cyrill Gorcunov Subject: Re: [PATCH] kvm tools: Fix test for mmap failure Date: Fri, 3 Feb 2012 23:37:00 +0400 Message-ID: <20120203193700.GE3314@moon> References: <20120203191541.GO11834@moon> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: Pekka Enberg , Sasha Levin , Asias He , Ingo Molnar , KVM-ML Return-path: Received: from mail-bk0-f46.google.com ([209.85.214.46]:33678 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754749Ab2BCThF (ORCPT ); Fri, 3 Feb 2012 14:37:05 -0500 Received: by bkcjm19 with SMTP id jm19so3350398bkc.19 for ; Fri, 03 Feb 2012 11:37:03 -0800 (PST) Content-Disposition: inline In-Reply-To: <20120203191541.GO11834@moon> Sender: kvm-owner@vger.kernel.org List-ID: 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 --- 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; }