Skip to contentSkip to conversation

exec: use macro for alignment

PATCH Superseded Chen Hanxiao 2 participants 2 messages Jul 23, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exec: use macro for alignment

---
 exec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
exec.c +3 -1
index 7d60e15..f84b485 100644
@@ -1153,6 +1153,8 @@ static long gethugepagesize(const char *path, Error **errp)
     return fs.f_bsize;
 }
 
+#define ALIGN(x, y)  (((x)+(y)-1) & ~((y)-1))
+
 static void *file_ram_alloc(RAMBlock *block,
                             ram_addr_t memory,
                             const char *path,
@@ -1207,7 +1209,7 @@ static void *file_ram_alloc(RAMBlock *block,
     unlink(filename);
     g_free(filename);
 
-    memory = (memory+hpagesize-1) & ~(hpagesize-1);
+    memory = ALIGN(memory, hpagesize);
 
     /*
      * ftruncate is not supported by hugetlbfs in older
Signature · 1 line
2.1.0
#1 lore raw

exec.c static void *file_ram_alloc(RAMBlock *block, · line 1213

Quoted 13 lines · Chen Hanxiao
exec.c +3 -1
+#define ALIGN(x, y)  (((x)+(y)-1) & ~((y)-1))
+
 static void *file_ram_alloc(RAMBlock *block,
                             ram_addr_t memory,
                             const char *path,
@@ -1207,7 +1209,7 @@ static void *file_ram_alloc(RAMBlock *block,
     unlink(filename);
     g_free(filename);
 
-    memory = (memory+hpagesize-1) & ~(hpagesize-1);
+    memory = ALIGN(memory, hpagesize);
 

Hi,

the patch is a good idea, but please use ROUND_UP instead of defining your own ALIGN macro.

Thanks!

Paolo