minios: grant table map (gntdev) bug fixes
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 24 Jul 2008 16:34:50 +0000 (17:34 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 24 Jul 2008 16:34:50 +0000 (17:34 +0100)
 * Uninitialized dev_bus_addr argument to GNTTABOP_unmap_grant_ref
   results in an angry hypervisor.
 * Set errno in libxc and return -1 on error.
 * op.status is a int16_t, so it should be printed with PRId16.
 * Don't print domids[0] or refs[0] if the ptr is NULL. It's more
   polite to crash later, after the message has been printed.

Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
extras/mini-os/gntmap.c
tools/libxc/xc_minios.c

index babb96329ebe5229f2d1c298c0d56fea48f4c77d..abbd91ab3346953f8ad98a86c0be4591f39e0bb1 100644 (file)
@@ -118,7 +118,7 @@ _gntmap_map_grant_ref(struct gntmap_entry *entry,
     rc = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
     if (rc != 0 || op.status != GNTST_okay) {
         printk("GNTTABOP_map_grant_ref failed: "
-               "returned %d, status %d\n",
+               "returned %d, status %" PRId16 "\n",
                rc, op.status);
         return rc != 0 ? rc : op.status;
     }
@@ -135,12 +135,13 @@ _gntmap_unmap_grant_ref(struct gntmap_entry *entry)
     int rc;
 
     op.host_addr    = (uint64_t) entry->host_addr;
+    op.dev_bus_addr = 0;
     op.handle       = entry->handle;
 
     rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
     if (rc != 0 || op.status != GNTST_okay) {
         printk("GNTTABOP_unmap_grant_ref failed: "
-               "returned %d, status %d\n",
+               "returned %d, status %" PRId16 "\n",
                rc, op.status);
         return rc != 0 ? rc : op.status;
     }
@@ -191,8 +192,9 @@ gntmap_map_grant_refs(struct gntmap *map,
     printk("gntmap_map_grant_refs(map=%p, count=%" PRIu32 ", "
            "domids=%p [%" PRIu32 "...], domids_stride=%d, "
            "refs=%p [%" PRIu32 "...], writable=%d)\n",
-           map, count, domids, domids[0], domids_stride,
-           refs, refs[0], writable);
+           map, count,
+           domids, domids == NULL ? 0 : domids[0], domids_stride,
+           refs, refs == NULL ? 0 : refs[0], writable);
 #endif
 
     (void) gntmap_set_max_grants(map, DEFAULT_MAX_GRANTS);
index f0c383bfd8143bad43f1788a2ae9308cdff44528..3781907d15fcd0078a839b53ac0d50c2d51f02e1 100644 (file)
@@ -383,16 +383,28 @@ int xc_gnttab_munmap(int xcg_handle,
                      void *start_address,
                      uint32_t count)
 {
-    return gntmap_munmap(&files[xcg_handle].gntmap,
-                         (unsigned long) start_address,
-                         count);
+    int ret;
+    ret = gntmap_munmap(&files[xcg_handle].gntmap,
+                        (unsigned long) start_address,
+                        count);
+    if (ret < 0) {
+        errno = -ret;
+        return -1;
+    }
+    return ret;
 }
 
 int xc_gnttab_set_max_grants(int xcg_handle,
                              uint32_t count)
 {
-    return gntmap_set_max_grants(&files[xcg_handle].gntmap,
-                                 count);
+    int ret;
+    ret = gntmap_set_max_grants(&files[xcg_handle].gntmap,
+                                count);
+    if (ret < 0) {
+        errno = -ret;
+        return -1;
+    }
+    return ret;
 }
 
 /*