diff mbox

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

Message ID 1331222284-19113-1-git-send-email-anthony.perard@citrix.com
State New
Headers show

Commit Message

Anthony PERARD March 8, 2012, 3:58 p.m. UTC
Because the size of a mapping is wrong when there is an offset and a
size >= bucket_size.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>

---
 xen-mapcache.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

Comments

Stefano Stabellini March 12, 2012, 3:28 p.m. UTC | #1
On Thu, 8 Mar 2012, Anthony PERARD wrote:
> Because the size of a mapping is wrong when there is an offset and a
> size >= bucket_size.

Ack
diff mbox

Patch

diff --git a/xen-mapcache.c b/xen-mapcache.c
index 585b559..db6eb05 100644
--- a/xen-mapcache.c
+++ b/xen-mapcache.c
@@ -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];