From 4c5e91bd540c37869c415f94cc6a896fafb3abf3 Mon Sep 17 00:00:00 2001 From: Marcin Rajwa Date: Wed, 8 May 2019 21:12:02 +0200 Subject: [PATCH 1/2] alloc: fix bug in memory caps for buffers Current implementation accept allocation for specific memory region only if all CAPS supported by that region match requested CAPS. This is wrong we should accept request if at least one CAPS match request. Signed-off-by: Marcin Rajwa --- src/lib/alloc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/alloc.c b/src/lib/alloc.c index 0d74f5c4f72b..3ece6ccd5036 100644 --- a/src/lib/alloc.c +++ b/src/lib/alloc.c @@ -324,13 +324,11 @@ static struct mm_heap *get_heap_from_ptr(void *ptr) static struct mm_heap *get_heap_from_caps(struct mm_heap *heap, int count, uint32_t caps) { - uint32_t mask; int i; /* find first heap that support type */ for (i = 0; i < count; i++) { - mask = heap[i].caps & caps; - if (mask == caps) + if (heap[i].caps & caps) return &heap[i]; } From d360f3fe5ae7c615f312ead9fbb716b8a7cbf743 Mon Sep 17 00:00:00 2001 From: Marcin Rajwa Date: Wed, 8 May 2019 20:59:04 +0200 Subject: [PATCH 2/2] alloc: remove unnecessary check for single block size This check is not needed since at this point we already know there was no sigle block which could fullfill this request. Signed-off-by: Marcin Rajwa --- src/lib/alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/alloc.c b/src/lib/alloc.c index 3ece6ccd5036..f3c39ebdf9e5 100644 --- a/src/lib/alloc.c +++ b/src/lib/alloc.c @@ -645,8 +645,8 @@ static void *alloc_heap_buffer(struct mm_heap *heap, int zone, uint32_t caps, for (i = heap->blocks - 1; i >= 0; i--) { map = &heap->map[i]; - /* allocate if block size is smaller than request */ - if (heap->size >= bytes && map->block_size < bytes) { + /* does whole heap have enough space? */ + if (heap->size >= bytes) { ptr = alloc_cont_blocks(heap, i, caps, bytes); if (ptr) break;