From 43f301b2de7af71c309c55f0f2158a0e0aa3098d Mon Sep 17 00:00:00 2001 From: clemenkl <71892432+clemenkl@users.noreply.github.com> Date: Wed, 5 May 2021 10:41:36 +0200 Subject: [PATCH] fix DMA deadlock size <= 0 When passed a size of 0 or less, spin__memcpy_nonblk will deadlock. Fixed by adding a case distinction over the size. The expectation is, that the if statement nearly always evaluates to 1. --- sw/runtime/include/handler.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sw/runtime/include/handler.h b/sw/runtime/include/handler.h index a8c3d6e..17f463f 100644 --- a/sw/runtime/include/handler.h +++ b/sw/runtime/include/handler.h @@ -88,8 +88,14 @@ typedef struct spin_rw_lock { static inline int spin_dma(void* source, void* dest, size_t size, int direction, int options, spin_dma_t* xfer) { - *xfer = spin__memcpy_nonblk(source, dest, (uint32_t)size); - return SPIN_OK; + if (__builtin_expect(size>0, 1)) + { + *xfer = spin__memcpy_nonblk(source, dest, (uint32_t)size); + return SPIN_OK; + } else + { + return SPIN_FAIL; + } } static inline int spin_dma_wait(spin_dma_t xfer)