WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] libxc: mmap doesn't return NULL on error...

To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] libxc: mmap doesn't return NULL on error...
From: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
Date: Thu, 12 May 2005 11:33:44 +1000
Delivery-date: Thu, 12 May 2005 01:33:39 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Hi, was reading libxc code, and noticed this.  Patch is bigger than
strictly necessary due to indent adjust.

Against latest bk.
Rusty.

diff -urpN --exclude TAGS -X 
/home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal 
base/tools/libxc/xc.h working/tools/libxc/xc.h
--- base/tools/libxc/xc.h       2005-05-12 11:06:44.306151968 +1000
+++ working/tools/libxc/xc.h    2005-05-12 11:10:25.821476520 +1000
@@ -421,7 +421,7 @@ int xc_msr_write(int xc_handle, int cpu_
 /**
  * Memory maps a range within one domain to a local address range.  Mappings
  * should be unmapped with munmap and should follow the same rules as mmap
- * regarding page alignment.
+ * regarding page alignment.  Returns NULL on failure.
  *
  * In Linux, the ring queue for the control channel is accessible by mapping
  * the shared_info_frame (from xc_domain_getinfo()) + 2048.  The structure
diff -urpN --exclude TAGS -X 
/home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal 
base/tools/libxc/xc_private.c working/tools/libxc/xc_private.c
--- base/tools/libxc/xc_private.c       2005-05-12 11:06:44.924058032 +1000
+++ working/tools/libxc/xc_private.c    2005-05-12 11:10:03.195916128 +1000
@@ -13,18 +13,18 @@ void *xc_map_foreign_batch(int xc_handle
     privcmd_mmapbatch_t ioctlx; 
     void *addr;
     addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
-    if ( addr != NULL )
+    if ( addr == MAP_FAILED )
+       return NULL;
+
+    ioctlx.num=num;
+    ioctlx.dom=dom;
+    ioctlx.addr=(unsigned long)addr;
+    ioctlx.arr=arr;
+    if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx ) < 0 )
     {
-        ioctlx.num=num;
-        ioctlx.dom=dom;
-        ioctlx.addr=(unsigned long)addr;
-        ioctlx.arr=arr;
-        if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx ) < 0 )
-        {
-            perror("XXXXXXXX");
-            munmap(addr, num*PAGE_SIZE);
-            return 0;
-        }
+       perror("XXXXXXXX");
+       munmap(addr, num*PAGE_SIZE);
+       return NULL;
     }
     return addr;
 
@@ -40,19 +40,19 @@ void *xc_map_foreign_range(int xc_handle
     privcmd_mmap_entry_t entry; 
     void *addr;
     addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
-    if ( addr != NULL )
+    if ( addr == MAP_FAILED )
+       return NULL;
+
+    ioctlx.num=1;
+    ioctlx.dom=dom;
+    ioctlx.entry=&entry;
+    entry.va=(unsigned long) addr;
+    entry.mfn=mfn;
+    entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
+    if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) < 0 )
     {
-        ioctlx.num=1;
-        ioctlx.dom=dom;
-        ioctlx.entry=&entry;
-        entry.va=(unsigned long) addr;
-        entry.mfn=mfn;
-        entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
-        if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) < 0 )
-        {
-            munmap(addr, size);
-            return 0;
-        }
+       munmap(addr, size);
+       return NULL;
     }
     return addr;
 }

-- 
A bad analogy is like a leaky screwdriver -- Richard Braakman


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] libxc: mmap doesn't return NULL on error..., Rusty Russell <=