On 04.11.19 12:29, Paolo Bonzini wrote:
On 04/11/19 11:54, Andrew Jones wrote:
diff --git a/lib/alloc.c b/lib/alloc.c
index ecdbbc44dbf9..ed8f5f94c9b0 100644
--- a/lib/alloc.c
+++ b/lib/alloc.c
@@ -46,15 +46,17 @@ void *memalign(size_t alignment, size_t size)
uintptr_t blkalign;
uintptr_t mem;
+ if (!size)
+ return NULL;
+
+ assert(alignment >= sizeof(void *) && is_power_of_2(alignment));
assert(alloc_ops && alloc_ops->memalign);
- if (alignment <= sizeof(uintptr_t))
- alignment = sizeof(uintptr_t);
- else
- size += alignment - 1;
+ size += alignment - 1;
blkalign = MAX(alignment, alloc_ops->align_min);
size = ALIGN(size + METADATA_EXTRA, alloc_ops->align_min);
p = alloc_ops->memalign(blkalign, size);
+ assert(p);
/* Leave room for metadata before aligning the result. */
mem = (uintptr_t)p + METADATA_EXTRA;
Looks good, this is what I am queuing.
Paolo
Please add my
Reviewed-by: David Hildenbrand <david@xxxxxxxxxx>
--
Thanks,
David / dhildenb