[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



ChangeSet 1.1453, 2005/05/12 11:33:58+01:00, rusty@xxxxxxxxxxxxxxx

        [PATCH] [PATCH] libxc: mmap doesn't return NULL on error...
        
        Hi, was reading libxc code, and noticed this.  Patch is bigger than
        strictly necessary due to indent adjust.
        
        Against latest bk.
        Rusty.



 xc.h         |    2 +-
 xc_private.c |   46 +++++++++++++++++++++++-----------------------
 2 files changed, 24 insertions(+), 24 deletions(-)


diff -Nru a/tools/libxc/xc.h b/tools/libxc/xc.h
--- a/tools/libxc/xc.h  2005-05-12 07:03:38 -04:00
+++ b/tools/libxc/xc.h  2005-05-12 07:03:38 -04:00
@@ -421,7 +421,7 @@
 /**
  * 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 -Nru a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c  2005-05-12 07:03:38 -04:00
+++ b/tools/libxc/xc_private.c  2005-05-12 07:03:38 -04:00
@@ -13,18 +13,18 @@
     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 @@
     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;
 }

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.