Skip to contentSkip to conversation

Xen, mapcache: Fix the compute of the size of bucket.

Qemu-devel Anthony PERARD 2 participants 2 messages Mar 8, 2012 – Mar 12, 2012

lore
Share & tools
lore
#0 lore raw

Because the size of a mapping is wrong when there is an offset and a size >= bucket_size.

---
 xen-mapcache.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
xen-mapcache.c +7 -5
index 585b559..db6eb05 100644
@@ -205,12 +205,14 @@ uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
     }
 
     /* size is always a multiple of MCACHE_BUCKET_SIZE */
-    if ((address_offset + (__size % MCACHE_BUCKET_SIZE)) > MCACHE_BUCKET_SIZE)
-        __size += MCACHE_BUCKET_SIZE;
-    if (__size % MCACHE_BUCKET_SIZE)
-        __size += MCACHE_BUCKET_SIZE - (__size % MCACHE_BUCKET_SIZE);
-    if (!__size)
+    if (size) {
+        __size = size + address_offset;
+        if (__size % MCACHE_BUCKET_SIZE) {
+            __size += MCACHE_BUCKET_SIZE - (__size % MCACHE_BUCKET_SIZE);
+        }
+    } else {
         __size = MCACHE_BUCKET_SIZE;
+    }
 
     entry = &mapcache->entry[address_index % mapcache->nr_buckets];
 
Signature · 1 line
tg: (2a60546..) mapcache-fix-size (depends on: spice-debian-debug)
#1 lore raw
Quoted 2 lines · Anthony PERARD

Because the size of a mapping is wrong when there is an offset and a size >= bucket_size.

Ack