Skip to content

Commit cfa5f02

Browse files
lyakhlgirdwood
authored andcommitted
fast-get: don't corrupt entries when failing
When fast_get() fails it shouldn't leave partially overwritten entries behind. Also fix the call to memcpy_s() to use the proper destination size. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 69af9bf commit cfa5f02

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

zephyr/lib/fast-get.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
223223
ret = sof_heap_alloc(heap, alloc_flags, alloc_size, alloc_align);
224224
if (!ret)
225225
goto out;
226-
entry->size = size;
227-
entry->sram_ptr = ret;
228-
memcpy_s(entry->sram_ptr, entry->size, dram_ptr, size);
229-
dcache_writeback_region((__sparse_force void __sparse_cache *)entry->sram_ptr, size);
230226

231227
#if CONFIG_USERSPACE
232228
if (size > FAST_GET_MAX_COPY_SIZE && current_is_userspace) {
@@ -244,6 +240,10 @@ const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
244240
#endif /* CONFIG_USERSPACE */
245241

246242
entry->dram_ptr = dram_ptr;
243+
entry->size = size;
244+
entry->sram_ptr = ret;
245+
memcpy_s(ret, alloc_size, dram_ptr, size);
246+
dcache_writeback_region((__sparse_force void __sparse_cache *)ret, size);
247247
entry->refcount = 1;
248248
out:
249249
k_spin_unlock(&data->lock, key);

0 commit comments

Comments
 (0)