Skip to content

Commit 0a87dc3

Browse files
lyakhkv2019i
authored andcommitted
fast-get: fix a recent regression: write before mapping RO
A recent commit introduced a regression: it moved writing data to a buffer after the call, mapping the target buffer as read-only. Fix it by moving the copy operation back up. Fixes commit cfa5f02 ("fast-get: don't corrupt entries when failing") Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 3db6d48 commit 0a87dc3

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

zephyr/lib/fast-get.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
224224
if (!ret)
225225
goto out;
226226

227+
memcpy_s(ret, alloc_size, dram_ptr, size);
228+
dcache_writeback_region((__sparse_force void __sparse_cache *)ret, size);
229+
227230
#if CONFIG_USERSPACE
228231
if (size > FAST_GET_MAX_COPY_SIZE && current_is_userspace) {
229232
/* Otherwise we've allocated on thread's heap, so it already has access */
@@ -242,8 +245,6 @@ const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
242245
entry->dram_ptr = dram_ptr;
243246
entry->size = size;
244247
entry->sram_ptr = ret;
245-
memcpy_s(ret, alloc_size, dram_ptr, size);
246-
dcache_writeback_region((__sparse_force void __sparse_cache *)ret, size);
247248
entry->refcount = 1;
248249
out:
249250
k_spin_unlock(&data->lock, key);

0 commit comments

Comments
 (0)