From d849edf3841c1c9774c5ce209a2b903415f2370a Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Fri, 20 Dec 2019 18:48:20 -0800 Subject: svm: fix multichunk alloc with not enough space Type: fix Change-Id: Ia89c76b0e897fc3a3ebbc8dcba25e8ac9974b7fa Signed-off-by: Florin Coras --- src/svm/fifo_segment.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c index 61939637434..944bf7cd34a 100644 --- a/src/svm/fifo_segment.c +++ b/src/svm/fifo_segment.c @@ -314,7 +314,10 @@ fs_try_alloc_fifo_freelist_multi_chunk (fifo_segment_header_t * fsh, fss->free_fifos = f->next; } - fl_index = fs_freelist_for_size (data_bytes) - 1; + fl_index = fs_freelist_for_size (data_bytes); + if (fl_index > 0) + fl_index -= 1; + fl_size = fs_freelist_index_to_size (fl_index); while (data_bytes) @@ -333,11 +336,38 @@ fs_try_alloc_fifo_freelist_multi_chunk (fifo_segment_header_t * fsh, } else { - ASSERT (fl_index > 0); + /* Failed to allocate with smaller chunks */ + if (fl_index == 0) + { + /* free all chunks if any allocated */ + c = first; + while (c) + { + fl_index = fs_freelist_for_size (c->length); + fl_size = fs_freelist_index_to_size (fl_index); + c->next = fss->free_chunks[fl_index]; + fss->free_chunks[fl_index] = c; + fss->n_fl_chunk_bytes += fl_size; + data_bytes += fl_size; + } + first = last = 0; + fl_index = fs_freelist_for_size (data_bytes); + if (fss->free_chunks[fl_index + 1]) + { + fl_index += 1; + fl_size = fs_freelist_index_to_size (fl_index); + continue; + } + + f->next = fss->free_fifos; + fss->free_fifos = f; + return 0; + } fl_index -= 1; fl_size = fl_size >> 1; } } + f->start_chunk = first; f->end_chunk = last; last->next = first; -- cgit 1.2.3-korg