[Cbe-oss-dev] [PATCH 08/10]MARS: Fix error handling

Yuji Mano yuji.mano at am.sony.com
Fri Oct 3 04:31:41 EST 2008


This removes the mars_debug.h and mars_timer.h headers and removes usage of all
debug macros.

The error handling is fixed to not use any macros.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>

---
 include/common/mars/mars_debug.h       |  295 ---------------------------
 include/common/mars/mars_task_types.h  |    4 
 include/host/mars/mars_timer.h         |  121 -----------
 include/mpu/mars/mars_dma.h            |   98 +++------
 include/mpu/mars/mars_kernel.h         |    2 
 include/mpu/mars/mars_timer.h          |  123 -----------
 src/host/lib/Makefile.am               |    2 
 src/host/lib/mars_context.c            |  140 +++++++------
 src/host/lib/mars_mutex.c              |   24 +-
 src/host/lib/mars_task.c               |  166 +++++++++------
 src/host/lib/mars_task_barrier.c       |   23 +-
 src/host/lib/mars_task_event_flag.c    |   86 +++++---
 src/host/lib/mars_task_queue.c         |   89 +++++---
 src/host/lib/mars_task_semaphore.c     |   22 +-
 src/host/lib/mars_task_signal.c        |   19 +
 src/host/lib/mars_workload_queue.c     |  348 +++++++++++++++++++++------------
 src/mpu/kernel/mars_kernel.c           |    8 
 src/mpu/kernel/mars_kernel_scheduler.c |   32 +--
 src/mpu/kernel/mars_kernel_task.c      |   26 --
 src/mpu/kernel/mars_kernel_workload.c  |  176 ++++++++++------
 src/mpu/lib/Makefile.am                |    3 
 src/mpu/lib/mars_mutex.c               |   36 +--
 src/mpu/lib/mars_task.c                |   39 ++-
 src/mpu/lib/mars_task_barrier.c        |   66 +++---
 src/mpu/lib/mars_task_event_flag.c     |   92 ++++----
 src/mpu/lib/mars_task_queue.c          |  112 ++++++----
 src/mpu/lib/mars_task_semaphore.c      |   32 +--
 src/mpu/lib/mars_task_signal.c         |   10 
 28 files changed, 973 insertions(+), 1221 deletions(-)

--- a/include/common/mars/mars_debug.h
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * Copyright 2008 Sony Corporation of America
- *
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this Library and associated documentation files (the
- * "Library"), to deal in the Library without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Library, and to
- * permit persons to whom the Library is furnished to do so, subject to
- * the following conditions:
- *
- *  The above copyright notice and this permission notice shall be
- *  included in all copies or substantial portions of the Library.
- *
- *  If you modify the Library, you may copy and distribute your modified
- *  version of the Library in object code or as an executable provided
- *  that you also do one of the following:
- *
- *   Accompany the modified version of the Library with the complete
- *   corresponding machine-readable source code for the modified version
- *   of the Library; or,
- *
- *   Accompany the modified version of the Library with a written offer
- *   for a complete machine-readable copy of the corresponding source
- *   code of the modified version of the Library.
- *
- *
- * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
- */
-
-#ifndef MARS_DEBUG_H
-#define MARS_DEBUG_H
-
-/*
- * \brief MARS Debug Macros
- */
-
-#include <stdio.h>
-
-#define MARS_DEBUG_ENABLE_PRINT		0
-#define MARS_DEBUG_ENABLE_ASSERTS	0
-#define MARS_DEBUG_ENABLE_VERBOSE	0
-#define MARS_DEBUG_ENABLE_TIMER		0
-#define MARS_DEBUG_ENABLE_DMA_ASSERTS	0
-#define MARS_DEBUG_ENABLE_DMA_VERBOSE	0
-
-#if __SPU__
-#define __CONTEXT__		"MPU"
-#define __BREAKPOINT__		__asm__ volatile ("stopd 0,1,1")
-#else
-#define __CONTEXT__		"HOST"
-#define __BREAKPOINT__		__asm__ volatile ("tw 31,1,1")
-#endif
-
-#define __PRINT__(msg, ...) {\
-	fprintf(stdout, "MARS("__CONTEXT__"): "msg, ##__VA_ARGS__);\
-	fflush(stdout);\
-}
-
-#define MARS_PRINTF(msg, ...) {\
-	__PRINT__("%s: "msg, __PRETTY_FUNCTION__, ##__VA_ARGS__);\
-}
-
-#if MARS_DEBUG_ENABLE_PRINT
-#if __SPU__
-#define MARS_PRINT(msg, ...) {\
-	__PRINT__("KERNEL(%d): "msg, kernel_params.id, ##__VA_ARGS__);\
-}
-#else
-#define MARS_PRINT(msg, ...) {\
-	__PRINT__(msg, ##__VA_ARGS__);\
-}
-#endif
-
-#define MARS_PRINT_16BYTE_ADDR(addr) {\
-	int i;\
-	printf("reg(%p) = 0x", (addr));\
-	for (i = 0; i < 16; i++) {\
-		printf("%02x", ((char *)(addr))[i]);\
-	}\
-	printf("\n");\
-}
-
-#define MARS_PRINT_REG(num) {\
-	register volatile vector unsigned int *reg asm(#num);\
-	MARS_PRINT_16BYTE_ADDR(reg);\
-}
-
-#define MARS_PRINT_STACK(stack_top, stack_pointer) {\
-	char *sp = (char *)(stack_top);\
-	while (sp >= (char *)(stack_pointer)) {\
-		printf("[%p] ",sp);\
-		int i;\
-		for (i = 0; i < 4; i++)\
-			printf("%02x",sp[i]);\
-		printf("%s\n",sp==(char *)(stack_pointer)?" <-- $sp":"");\
-		sp-=16;\
-	} \
-}
-#else
-#define MARS_PRINT(msg, ...)
-#define MARS_PRINT_16BYTE_ADDR(addr)
-#define MARS_PRINT_REG(num)
-#define MARS_PRINT_STACK(stack_top, stack_pointer)
-#endif
-
-#if MARS_DEBUG_ENABLE_ASSERTS
-
-#define MARS_BREAK() {\
-	__PRINT__("%s[line %d]:%s():BREAK\n",\
-		__FILE__, __LINE__, __PRETTY_FUNCTION__);\
-	__BREAKPOINT__;\
-}
-
-#define MARS_ASSERT(exp) {\
-	if(!(exp)) {\
-		__PRINT__("%s(line %d):%s() - ASSERT("#exp") FAILED\n",\
-			__FILE__, __LINE__, __PRETTY_FUNCTION__);\
-		__BREAKPOINT__;\
-	}\
-}
-
-#define MARS_CHECK(exp) {\
-	MARS_ASSERT(exp);\
-	if(!(exp)) return;\
-}
-
-#define MARS_CHECK_RET(exp, ret) {\
-	MARS_ASSERT(exp);\
-	if(!(exp)) return ret;\
-}
-
-#define MARS_CHECK_CLEANUP(exp, clean) {\
-	MARS_ASSERT(exp);\
-	if(!(exp)) {\
-		clean;\
-		return;\
-	}\
-}
-
-#define MARS_CHECK_CLEANUP_RET(exp, clean, ret) {\
-	MARS_ASSERT(exp);\
-	if(!(exp)) {\
-		clean;\
-		return ret;\
-	}\
-}
-
-#else
-#define MARS_BREAK()
-#define MARS_ASSERT(exp)
-#define MARS_CHECK(exp)				{if(!(exp))return;}
-#define MARS_CHECK_RET(exp, ret)		{if(!(exp))return ret;}
-#define MARS_CHECK_CLEANUP(exp, clean)		{if(!(exp)){clean;return;}}
-#define MARS_CHECK_CLEANUP_RET(exp, clean, ret)	{if(!(exp)){clean;return ret;}}
-#endif
-
-#if MARS_DEBUG_ENABLE_VERBOSE
-
-#define MARS_PRINT_TASK_CONTEXT(task_context) {\
-	__PRINT__("===\n");\
-	__PRINT__("- Task Context (%p)\n", (task_context));\
-	__PRINT__("-  exec:      %#llx\n", (task_context)->exec);\
-	__PRINT__("-  exec_size: %d bytes\n", (task_context)->exec_size);\
-	__PRINT__("-  bss_size:  %d bytes\n", (task_context)->bss_size);\
-	__PRINT__("-  vaddr:     %#x\n", (task_context)->vaddr);\
-	__PRINT__("-  entry:     %#x\n", (task_context)->entry);\
-	__PRINT__("-  stack:     %#x\n", (task_context)->stack);\
-	__PRINT__("===\n");\
-}
-
-#define MARS_PRINT_WORKLOAD_QUEUE_HEADER(queue_header) {\
-	__PRINT__("===\n");\
-	__PRINT__("- Workload Queue Header (%p)\n", (queue_header));\
-	__PRINT__("-  queue_ea:   %#llx\n",(queue_header)->queue_ea);\
-	__PRINT__("-  context_ea: %#llx\n",(queue_header)->context_ea);\
-	__PRINT__("-  flag:       %#x\n",(queue_header)->flag);\
-	__PRINT__("-  count:      %d\n",(queue_header)->count);\
-	unsigned int i;\
-	__PRINT__("-  state:      ");\
-	for (i = 0; i < MARS_WORKLOAD_MAX; i++)\
-		fprintf(stdout, "%d,", (queue_header)->state[i]);\
-	fprintf(stdout, "\n");\
-	__PRINT__("-  priority:   ");\
-	for (i = 0; i < MARS_WORKLOAD_MAX; i++)\
-		fprintf(stdout, "%d,", (queue_header)->priority[i]);\
-	fprintf(stdout, "\n");\
-	__PRINT__("-  wait_count: ");\
-	for (i = 0; i < MARS_WORKLOAD_MAX; i++)\
-		fprintf(stdout, "%d,", (queue_header)->wait_count[i]);\
-	fprintf(stdout, "\n");\
-	__PRINT__("===\n");\
-}
-
-#define MARS_PRINT_KERNEL_PARAMS(kernel_params) {\
-	__PRINT__("===\n");\
-	__PRINT__("- Kernel Params (%p)\n", (kernel_params));\
-	__PRINT__("-  workload_queue_ea: %#llx\n",\
-			(kernel_params)->workload_queue_ea);\
-	__PRINT__("===\n");\
-}
-
-#define MARS_PRINT_SPE_PROGRAM_HANDLE(spe_program_handle) {\
-	__PRINT__("===\n");\
-	__PRINT__("- SPE Program Handle (%p)\n", (spe_program_handle));\
-	__PRINT__("-  handle_size: %d\n", (spe_program_handle)->handle_size);\
-	__PRINT__("-  elf_image:   %p\n", (spe_program_handle)->elf_image);\
-	__PRINT__("-  toe_shadow:  %p\n", (spe_program_handle)->toe_shadow);\
-	__PRINT__("===\n");\
-}
-
-#define MARS_PRINT_ELF(elf) {\
-	Elf32_Shdr *shdr = (Elf32_Shdr *)((char *)(elf) + ehdr->e_shoff);\
-	char *str_table = (elf) + shdr[ehdr->e_shstrndx].sh_offset;\
-	unsigned int i;\
-	__PRINT__("===\n");\
-	__PRINT__("- ELF Header (%p)\n", ehdr);\
-	__PRINT__("-  e_type:      %#x\n", ehdr->e_type);\
-	__PRINT__("-  e_machine:   %#x\n", ehdr->e_machine);\
-	__PRINT__("-  e_version:   %#x\n", ehdr->e_version);\
-	__PRINT__("-  e_entry:     %#x\n", ehdr->e_entry);\
-	__PRINT__("-  e_phoff:     %#x\n", ehdr->e_phoff);\
-	__PRINT__("-  e_shoff:     %#x\n", ehdr->e_shoff);\
-	__PRINT__("-  e_flags:     %#x\n", ehdr->e_flags);\
-	__PRINT__("-  e_ehsize:    %#x\n", ehdr->e_ehsize);\
-	__PRINT__("-  e_phentsize: %#x\n", ehdr->e_phentsize);\
-	__PRINT__("-  e_phnum:     %#x\n", ehdr->e_phnum);\
-	__PRINT__("-  e_shentsize: %#x\n", ehdr->e_shentsize);\
-	__PRINT__("-  e_shnum:     %#x\n", ehdr->e_shnum);\
-	__PRINT__("-  e_shstrndx:  %#x\n", ehdr->e_shstrndx);\
-	for (i = 0; i < ehdr->e_phnum; i++) {\
-		__PRINT__("- ELF Program Header %d\n", i);\
-		__PRINT__("-  p_type:       %#x\n", phdr[i].p_type);\
-		__PRINT__("-  p_offset:     %#x\n", phdr[i].p_offset);\
-		__PRINT__("-  p_vaddr:      %#x\n", phdr[i].p_vaddr);\
-		__PRINT__("-  p_paddr:      %#x\n", phdr[i].p_paddr);\
-		__PRINT__("-  p_filesz:     %d bytes\n", phdr[i].p_filesz);\
-		__PRINT__("-  p_memsz:      %d bytes\n", phdr[i].p_memsz);\
-		__PRINT__("-  p_flags:      %#x\n", phdr[i].p_flags);\
-		__PRINT__("-  p_align:      %#x\n", phdr[i].p_align);\
-	}\
-	Elf32_Shdr *sh;\
-	for (sh = shdr; sh < &shdr[ehdr->e_shnum]; ++sh) {\
-		__PRINT__("- ELF Section Header %d\n", i);\
-		__PRINT__("-  sh_name:      %s\n", str_table+sh->sh_name);\
-	}\
-	for (i = 0; i < ehdr->e_shnum; i++) {\
-		__PRINT__("- ELF Section Header %d\n", i);\
-		__PRINT__("-  sh_name:      %s\n", str_table+shdr[i].sh_name);\
-		__PRINT__("-  sh_type:      %#x\n", shdr[i].sh_type);\
-		__PRINT__("-  sh_flags:     %#x\n", shdr[i].sh_flags);\
-		__PRINT__("-  sh_addr:      %#x\n", shdr[i].sh_addr);\
-		__PRINT__("-  sh_offset:    %#x\n", shdr[i].sh_offset);\
-		__PRINT__("-  sh_size:      %d bytes\n", shdr[i].sh_size);\
-		__PRINT__("-  sh_link:      %#x\n", shdr[i].sh_link);\
-		__PRINT__("-  sh_info:      %#x\n", shdr[i].sh_info);\
-		__PRINT__("-  sh_addralign: %#x\n", shdr[i].sh_addralign);\
-		__PRINT__("-  sh_entsize:   %d bytes\n", shdr[i].sh_entsize);\
-	}\
-	__PRINT__("===\n");\
-}
-
-#else
-#define MARS_PRINT_TASK_CONTEXT(task_context)
-#define MARS_PRINT_WORKLOAD_CONTEXT(workload_context)
-#define MARS_PRINT_WORKLOAD_QUEUE_HEADER(queue_header)
-#define MARS_PRINT_KERNEL_PARAMS(kernel_params)
-#define MARS_PRINT_SPE_PROGRAM_HANDLE(spe_program_handle)
-#define MARS_PRINT_ELF(elf)
-#endif
-
-#if MARS_DEBUG_ENABLE_TIMER
-#define MARS_TIMER_START(tag)\
-	{\
-		struct mars_timer tag ## _timer;\
-		mars_timer_start(&tag ## _timer);
-
-#define MARS_TIMER_STOP(tag)\
-		mars_timer_stop(&tag ## _timer);\
-		__PRINT__("KERNEL(%d): " #tag " - %.0f us\n",\
-			kernel_params.id, tag ## _timer.us);\
-	}
-#else
-#define MARS_TIMER_START(id)
-#define MARS_TIMER_STOP(id)
-#endif
-
-#endif
--- a/include/common/mars/mars_task_types.h
+++ b/include/common/mars/mars_task_types.h
@@ -99,7 +99,7 @@
  * \ingroup group_mars_task
  * \brief Max length of task name
  */
-#define MARS_TASK_NAME_LEN_MAX			22
+#define MARS_TASK_NAME_LEN_MAX			21
 
 /**
  * \ingroup group_mars_task
@@ -144,7 +144,7 @@ struct mars_task_args {
 struct mars_task_id {
 	uint64_t mars_context_ea;
 	uint16_t workload_id;
-	uint8_t name[MARS_TASK_NAME_LEN_MAX];
+	uint8_t name[MARS_TASK_NAME_LEN_MAX + 1];
 } __attribute__((aligned(MARS_TASK_ID_ALIGN)));
 
 struct mars_task_context {
--- a/include/host/mars/mars_timer.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright 2008 Sony Corporation of America
- *
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this Library and associated documentation files (the
- * "Library"), to deal in the Library without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Library, and to
- * permit persons to whom the Library is furnished to do so, subject to
- * the following conditions:
- *
- *  The above copyright notice and this permission notice shall be
- *  included in all copies or substantial portions of the Library.
- *
- *  If you modify the Library, you may copy and distribute your modified
- *  version of the Library in object code or as an executable provided
- *  that you also do one of the following:
- *
- *   Accompany the modified version of the Library with the complete
- *   corresponding machine-readable source code for the modified version
- *   of the Library; or,
- *
- *   Accompany the modified version of the Library with a written offer
- *   for a complete machine-readable copy of the corresponding source
- *   code of the modified version of the Library.
- *
- *
- * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
- */
-
-#ifndef MARS_TIMER_H
-#define MARS_TIMER_H
-
-/*
- * \ingroup group_mars_timer
- * \brief [host] MARS Timer API
- */
-
-#include <sys/time.h>
-#include "mars/mars_debug.h"
-
-/*
- * \ingroup group_mars_timer
- * \brief MARS timer structure
- *
- * This structure is used for storing timer information.
- * When passed into \ref mars_timer_start() and \ref mars_timer_stop(),
- * the us, ms, and s members will hold the time elapsed between the start
- * and stop calls in microseconds, milliseconds, and seconds, respectively.
- * \note This structure should not be directly modified by the user.
- */
-struct mars_timer {
-	float us;			/**< microseconds elapsed */
-	float ms;			/**< milliseconds elapsed */
-	float s;			/**< seconds elapsed */
-
-	unsigned long long start;	/**< internal - start time */
-	unsigned long long end;		/**< internal - stop time */
-};
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/*
- * \ingroup group_mars_timer
- * \brief Starts the timer
- *
- * \param[in] timer	- pointer to the timer instance
- *
- * This should be called in pair with \ref mars_timer_stop.
- * After the timer is stopped, the us, ms, and s members of the timer instance
- * will hold the time elapsed between the start and stop calls in microseconds,
- * milliseconds, and seconds, respectively.
- */
-static inline void mars_timer_start(struct mars_timer *timer)
-{
-	MARS_CHECK(timer);
-
-	struct timeval tv;
-	gettimeofday(&tv, NULL);
-	timer->start = tv.tv_sec * 1000000 + tv.tv_usec;
-	timer->end = timer->start;
-
-	timer->us = 0;
-	timer->ms = 0;
-	timer->s  = 0;
-}
-
-/*
- * \ingroup group_mars_timer
- * \brief Stops the timer
- *
- * \param[in,out] timer	- pointer to the timer instance
- *
- * This should be called after a previous call to \ref mars_timer_start.
- * After the timer is stopped, the us, ms, and s members of the timer instance
- * will hold the time elapsed between the start and stop calls in microseconds,
- * milliseconds, and seconds, respectively.
- */
-static inline void mars_timer_stop(struct mars_timer *timer)
-{
-	MARS_CHECK(timer);
-
-	struct timeval tv;
-	gettimeofday(&tv, NULL);
-	timer->end = tv.tv_sec * 1000000 + tv.tv_usec;
-
-	timer->us = (float)(timer->end - timer->start);
-	timer->ms = timer->us * 1.0e-3;
-	timer->s  = timer->us * 1.0e-6;
-}
-
-#endif
--- a/include/mpu/mars/mars_dma.h
+++ b/include/mpu/mars/mars_dma.h
@@ -44,8 +44,8 @@
  * \brief [MPU] MARS DMA API
  */
 
+#include <assert.h>
 #include <spu_mfcio.h>
-#include "mars/mars_debug.h"
 
 #define MARS_DMA_TAG		31	/* dma tag reserved for MARS */
 #define MARS_DMA_TAG_MAX	31	/* dma tag 0~31 */
@@ -113,12 +113,8 @@ static inline void _mars_dma_large_put(c
  */
 static inline void mars_dma_wait(uint32_t tag)
 {
-#if MARS_DEBUG_ENABLE_DMA_VERBOSE
-	MARS_PRINTF("tag=%d\n", tag);
-#endif
-#if MARS_DEBUG_ENABLE_DMA_ASSERTS
-	MARS_ASSERT(tag <= MARS_DMA_TAG_MAX);
-#endif
+	assert(tag <= MARS_DMA_TAG_MAX);
+
 	mfc_write_tag_mask(1 << tag);
 	mfc_write_tag_update_all();
 	mfc_read_tag_status();
@@ -149,16 +145,12 @@ static inline void mars_dma_wait(uint32_
 static inline void mars_dma_get(void *ls, uint64_t ea,
 					uint32_t size, uint32_t tag)
 {
-#if MARS_DEBUG_ENABLE_DMA_VERBOSE
-	MARS_PRINTF("ls=%p ea=%#llx size=%d tag=%d\n", ls, ea, size, tag);
-#endif
-#if MARS_DEBUG_ENABLE_DMA_ASSERTS
-	MARS_ASSERT(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT((size & MARS_DMA_SIZE_MASK) == 0);
-	MARS_ASSERT(size && size <= MARS_DMA_SIZE_MAX);
-	MARS_ASSERT(tag <= MARS_DMA_TAG_MAX);
-#endif
+	assert(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
+	assert(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
+	assert((size & MARS_DMA_SIZE_MASK) == 0);
+	assert(size && size <= MARS_DMA_SIZE_MAX);
+	assert(tag <= MARS_DMA_TAG_MAX);
+
 	mfc_get((volatile void *)ls, ea, size, tag, 0, 0);
 }
 
@@ -208,16 +200,12 @@ static inline void mars_dma_get_and_wait
 static inline void mars_dma_put(const void *ls, uint64_t ea,
 					uint32_t size, uint32_t tag)
 {
-#if MARS_DEBUG_ENABLE_DMA_VERBOSE
-	MARS_PRINTF("ls=%p ea=%#llx size=%d tag=%d\n", ls, ea, size, tag);
-#endif
-#if MARS_DEBUG_ENABLE_DMA_ASSERTS
-	MARS_ASSERT(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT((size & MARS_DMA_SIZE_MASK) == 0);
-	MARS_ASSERT(size && size <= MARS_DMA_SIZE_MAX);
-	MARS_ASSERT(tag <= MARS_DMA_TAG_MAX);
-#endif
+	assert(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
+	assert(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
+	assert((size & MARS_DMA_SIZE_MASK) == 0);
+	assert(size && size <= MARS_DMA_SIZE_MAX);
+	assert(tag <= MARS_DMA_TAG_MAX);
+
 	spu_dsync();
 	mfc_put((volatile void *)ls, ea, size, tag, 0, 0);
 }
@@ -267,15 +255,11 @@ static inline void mars_dma_put_and_wait
 static inline void mars_dma_small_get(void *ls, uint64_t ea,
 					uint32_t size, uint32_t tag)
 {
-#if MARS_DEBUG_ENABLE_DMA_VERBOSE
-	MARS_PRINTF("ls=%p ea=%#llx size=%d tag=%d\n", ls, ea, size, tag);
-#endif
-#if MARS_DEBUG_ENABLE_DMA_ASSERTS
-	MARS_ASSERT(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT(size == 1 || size == 2 || size == 4 || size == 8);
-	MARS_ASSERT(tag <= MARS_DMA_TAG_MAX);
-#endif
+	assert(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
+	assert(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
+	assert(size == 1 || size == 2 || size == 4 || size == 8);
+	assert(tag <= MARS_DMA_TAG_MAX);
+
 	mfc_get(ls, ea, size, tag, 0, 0);
 }
 
@@ -324,15 +308,11 @@ static inline void mars_dma_small_get_an
 static inline void mars_dma_small_put(const void *ls, uint64_t ea,
 					uint32_t size, uint32_t tag)
 {
-#if MARS_DEBUG_ENABLE_DMA_VERBOSE
-	MARS_PRINTF("ls=%p ea=%#llx size=%d tag=%d\n", ls, ea, size, tag);
-#endif
-#if MARS_DEBUG_ENABLE_DMA_ASSERTS
-	MARS_ASSERT(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT(size == 1 || size == 2 || size == 4 || size == 8);
-	MARS_ASSERT(tag <= MARS_DMA_TAG_MAX);
-#endif
+	assert(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
+	assert(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
+	assert(size == 1 || size == 2 || size == 4 || size == 8);
+	assert(tag <= MARS_DMA_TAG_MAX);
+
 	spu_dsync();
 	mfc_put((volatile void *)ls, ea, size, tag, 0, 0);
 }
@@ -383,15 +363,11 @@ static inline void mars_dma_small_put_an
 static inline void mars_dma_large_get(void *ls, uint64_t ea,
 					uint32_t size, uint32_t tag)
 {
-#if MARS_DEBUG_ENABLE_DMA_VERBOSE
-	MARS_PRINTF("ls=%p ea=%#llx size=%d tag=%d\n", ls, ea, size, tag);
-#endif
-#if MARS_DEBUG_ENABLE_DMA_ASSERTS
-	MARS_ASSERT(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT(size);
-	MARS_ASSERT(tag <= MARS_DMA_TAG_MAX);
-#endif
+	assert(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
+	assert(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
+	assert(size);
+	assert(tag <= MARS_DMA_TAG_MAX);
+
 	_mars_dma_large_get(ls, ea, size, tag);
 }
 
@@ -441,15 +417,11 @@ static inline void mars_dma_large_get_an
 static inline void mars_dma_large_put(const void *ls, uint64_t ea,
 					uint32_t size, uint32_t tag)
 {
-#if MARS_DEBUG_ENABLE_DMA_VERBOSE
-	MARS_PRINTF("ls=%p ea=%#llx size=%d tag=%d\n", ls, ea, size, tag);
-#endif
-#if MARS_DEBUG_ENABLE_DMA_ASSERTS
-	MARS_ASSERT(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
-	MARS_ASSERT(size);
-	MARS_ASSERT(tag <= MARS_DMA_TAG_MAX);
-#endif
+	assert(((uintptr_t)ls & MARS_DMA_ALIGN_MASK) == 0);
+	assert(((uintptr_t)ea & MARS_DMA_ALIGN_MASK) == 0);
+	assert(size);
+	assert(tag <= MARS_DMA_TAG_MAX);
+
 	_mars_dma_large_put(ls, ea, size, tag);
 }
 
--- a/include/mpu/mars/mars_kernel.h
+++ b/include/mpu/mars/mars_kernel.h
@@ -39,10 +39,10 @@
 #define MARS_KERNEL_H
 
 #include <stdint.h>
+#include <stddef.h>
 
 #include "mars/mars_dma.h"
 #include "mars/mars_mutex.h"
-#include "mars/mars_timer.h"
 #include "mars/mars_error.h"
 #include "mars/mars_kernel_types.h"
 #include "mars/mars_workload_types.h"
--- a/include/mpu/mars/mars_timer.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright 2008 Sony Corporation of America
- *
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this Library and associated documentation files (the
- * "Library"), to deal in the Library without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Library, and to
- * permit persons to whom the Library is furnished to do so, subject to
- * the following conditions:
- *
- *  The above copyright notice and this permission notice shall be
- *  included in all copies or substantial portions of the Library.
- *
- *  If you modify the Library, you may copy and distribute your modified
- *  version of the Library in object code or as an executable provided
- *  that you also do one of the following:
- *
- *   Accompany the modified version of the Library with the complete
- *   corresponding machine-readable source code for the modified version
- *   of the Library; or,
- *
- *   Accompany the modified version of the Library with a written offer
- *   for a complete machine-readable copy of the corresponding source
- *   code of the modified version of the Library.
- *
- *
- * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
- */
-
-#ifndef MARS_TIMER_H
-#define MARS_TIMER_H
-
-/*
- * \ingroup group_mars_timer
- * \brief MARS Timer API [MPU]
- */
-
-#include <spu_intrinsics.h>
-#include "mars/mars_debug.h"
-
-/*
- * \ingroup group_mars_timer
- * \brief MARS timer structure
- *
- * This structure is used for storing timer information.
- * When passed into \ref mars_timer_start() and \ref mars_timer_stop(),
- * the us, ms, and s members will hold the time elapsed between the start
- * and stop calls in microseconds, milliseconds, and seconds, respectively.
- * \note This structure should not be directly modified by the user.
- */
-struct mars_timer {
-	float us;		/**< microseconds elapsed */
-	float ms;		/**< milliseconds elapsed */
-	float s;		/**< seconds elapsed */
-
-	unsigned int start;	/**< internal - start time */
-	unsigned int end;	/**< internal - stop time */
-};
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-static const unsigned int mars_timebase = 79800000;
-
-/*
- * \ingroup group_mars_timer
- * \brief Starts the timer
- *
- * This should be called in pair with \ref mars_timer_stop.
- * After the timer is stopped, the us, ms, and s members of the timer instance
- * will hold the time elapsed between the start and stop calls in microseconds,
- * milliseconds, and seconds, respectively.
- *
- * \param[in] timer	- pointer to the timer instance
- */
-static inline void mars_timer_start(struct mars_timer *timer)
-{
-	MARS_CHECK(timer);
-
-	spu_writech(SPU_WrDec, 0xffffffff);
-	timer->start = spu_readch(SPU_RdDec);
-
-	timer->us = 0;
-	timer->ms = 0;
-	timer->s  = 0;
-}
-
-/*
- * \ingroup group_mars_timer
- * \brief [MPU] Stops the timer
- *
- * This should be called after a previous call to \ref mars_timer_start.
- * After the timer is stopped, the us, ms, and s members of the timer instance
- * will hold the time elapsed between the start and stop calls in microseconds,
- * milliseconds, and seconds, respectively.
- *
- * \param[in,out] timer	- pointer to the timer instance
- */
-static inline void mars_timer_stop(struct mars_timer *timer)
-{
-	MARS_CHECK(timer);
-
-	timer->end = spu_readch(SPU_RdDec);
-
-	timer->s  = (float)(timer->start - timer->end) / mars_timebase;
-	timer->ms = timer->s * 1.0e3;
-	timer->us = timer->s * 1.0e6;
-}
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif
--- a/src/host/lib/Makefile.am
+++ b/src/host/lib/Makefile.am
@@ -77,9 +77,7 @@ pkginclude_HEADERS = \
 	$(srcdir)/../../../include/host/mars/mars_task_signal.h
 
 EXTRA_DIST += \
-	$(srcdir)/../../../include/host/mars/mars_timer.h \
 	$(srcdir)/../../../include/host/mars/mars_workload_queue.h \
-	$(srcdir)/../../../include/common/mars/mars_debug.h \
 	$(srcdir)/../../../include/common/mars/mars_kernel_types.h \
 	$(srcdir)/../../../include/common/mars/mars_workload_types.h
 
--- a/src/host/lib/mars_context.c
+++ b/src/host/lib/mars_context.c
@@ -44,7 +44,6 @@
 #include "mars/mars_workload_queue.h"
 #include "mars/mars_kernel_types.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 extern struct spe_program_handle mars_kernel_entry;
 static struct mars_context *mars_shared_context;
@@ -52,32 +51,36 @@ static pthread_mutex_t mars_mutex = PTHR
 
 static void *mpu_context_thread(void *arg)
 {
-	MARS_ASSERT(arg);
-
 	int ret;
 	unsigned int entry = SPE_DEFAULT_ENTRY;
 	struct mars_kernel_params *params = (struct mars_kernel_params *)arg;
 	struct spe_context *spe;
 
 	spe = spe_context_create(0, NULL);
-	MARS_CHECK_RET(spe, (void *)MARS_ERROR_INTERNAL);
+	if (!spe)
+		return (void *)MARS_ERROR_INTERNAL;
 
 	ret = spe_program_load(spe, &mars_kernel_entry);
-	MARS_CHECK_RET(!ret, (void *)MARS_ERROR_INTERNAL);
+	if (ret) {
+		spe_context_destroy(spe);
+		return (void *)MARS_ERROR_INTERNAL;
+	}
 
 	ret = spe_context_run(spe, &entry, 0, params, NULL, NULL);
-	MARS_CHECK_RET(!ret, (void *)MARS_ERROR_INTERNAL);
+	if (ret) {
+		spe_context_destroy(spe);
+		return (void *)MARS_ERROR_INTERNAL;
+	}
 
 	ret = spe_context_destroy(spe);
-	MARS_CHECK_RET(!ret, (void *)MARS_ERROR_INTERNAL);
+	if (ret)
+		return (void *)MARS_ERROR_INTERNAL;
 
 	return (void *)MARS_SUCCESS;
 }
 
 static int mpu_contexts_create(struct mars_context *mars, uint32_t num_mpus)
 {
-	MARS_ASSERT(mars);
-
 	int ret;
 	unsigned int i;
 
@@ -87,13 +90,14 @@ static int mpu_contexts_create(struct ma
 
 		params->id = i;
 		params->mars_context_ea =
-				mars_ptr_to_ea(mars);
+			mars_ptr_to_ea(mars);
 		params->workload_queue_ea =
-				mars_ptr_to_ea(mars->workload_queue);
+			mars_ptr_to_ea(mars->workload_queue);
 
 		ret = pthread_create(&mars->mpu_context_threads[i], NULL,
-				mpu_context_thread, params);
-		MARS_CHECK_RET(!ret, MARS_ERROR_INTERNAL);
+			mpu_context_thread, params);
+		if (ret)
+			return MARS_ERROR_INTERNAL;
 
 		mars->mpu_context_count++;
 	}
@@ -103,20 +107,20 @@ static int mpu_contexts_create(struct ma
 
 static int mpu_contexts_destroy(struct mars_context *mars)
 {
-	MARS_ASSERT(mars);
-
 	int ret;
 	void *p_ret;
 	unsigned int i;
 
 	/* shutdown the workload queue so mpu context threads exit */
 	ret = workload_queue_exit(mars->workload_queue);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	/* join all mpu context threads */
 	for (i = 0; i < mars->mpu_context_count; i++) {
 		ret = pthread_join(mars->mpu_context_threads[i], &p_ret);
-		MARS_CHECK_RET(!ret && !p_ret, MARS_ERROR_INTERNAL);
+		if (ret || p_ret)
+			return MARS_ERROR_INTERNAL;
 	}
 
 	return MARS_SUCCESS;
@@ -125,32 +129,34 @@ static int mpu_contexts_destroy(struct m
 int mars_context_create(struct mars_context **mars_ret, uint32_t num_mpus,
 			uint8_t shared)
 {
-	MARS_CHECK_RET(mars_ret, MARS_ERROR_NULL);
-
-	MARS_PRINT("Created MARS Context (%p)\n", mars);
-
 	int ret;
 	int num_mpus_max;
 	struct mars_context *mars;
 
-	/* check max available mpus */
-	num_mpus_max = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
-	MARS_CHECK_RET(num_mpus_max > 0, MARS_ERROR_INTERNAL);
-	MARS_CHECK_RET(num_mpus_max >= (int)num_mpus, MARS_ERROR_PARAMS);
+	/* check function params */
+	if (!mars_ret)
+		return MARS_ERROR_NULL;
 
-	/* num mpus specified is default max */
+	/* check number of mpus to use */
+	num_mpus_max = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
+	if (num_mpus_max <= 0)
+		return MARS_ERROR_INTERNAL;
+	if (num_mpus_max < (int)num_mpus)
+		return MARS_ERROR_PARAMS;
 	if (!num_mpus)
 		num_mpus = num_mpus_max;
 
 	/* lock mutex */
 	ret = pthread_mutex_lock(&mars_mutex);
-	MARS_CHECK_RET(ret == 0, MARS_ERROR_INTERNAL);
+	if (ret)
+		return MARS_ERROR_INTERNAL;
 
 	/* shared context requested */
 	if (shared && mars_shared_context) {
 		/* create any extra mpu contexts necessary */
 		ret = mpu_contexts_create(mars_shared_context, num_mpus);
-		MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+		if (ret != MARS_SUCCESS)
+			return ret;
 
 		/* increment shared context reference count */
 		mars_shared_context->reference_count++;
@@ -160,16 +166,18 @@ int mars_context_create(struct mars_cont
 
 		/* unlock mutex */
 		ret = pthread_mutex_unlock(&mars_mutex);
-		MARS_CHECK_RET(ret == 0, MARS_ERROR_INTERNAL);
+		if (ret)
+			return MARS_ERROR_INTERNAL;
 
 		return MARS_SUCCESS;
 	}
 
 	/* allocate */
 	mars = malloc(sizeof(struct mars_context));
-	MARS_CHECK_CLEANUP_RET(mars,
-				pthread_mutex_unlock(&mars_mutex),
-				MARS_ERROR_MEMORY);
+	if (!mars) {
+		goto ERROR_malloc_mars;
+		ret = MARS_ERROR_MEMORY;
+	}
 
 	/* zero context */
 	memset(mars, 0, sizeof(struct mars_context));
@@ -181,32 +189,28 @@ int mars_context_create(struct mars_cont
 	mars->kernel_params = (struct mars_kernel_params *)
 		memalign(MARS_KERNEL_PARAMS_ALIGN,
 			sizeof(struct mars_kernel_params) * num_mpus_max);
-	MARS_CHECK_CLEANUP_RET(mars->kernel_params,
-				pthread_mutex_unlock(&mars_mutex);
-				mars_context_destroy(mars),
-				MARS_ERROR_MEMORY);
+	if (!mars->kernel_params) {
+		goto ERROR_malloc_kernel_params;
+		ret = MARS_ERROR_MEMORY;
+	}
 
 	/* allocate mpu context thread array */
 	mars->mpu_context_threads = (pthread_t *)
 		malloc(sizeof(pthread_t) * num_mpus_max);
-	MARS_CHECK_CLEANUP_RET(mars->mpu_context_threads,
-				pthread_mutex_unlock(&mars_mutex);
-				mars_context_destroy(mars),
-				MARS_ERROR_MEMORY);
+	if (!mars->mpu_context_threads) {
+		goto ERROR_malloc_mpu_context_threads;
+		ret = MARS_ERROR_MEMORY;
+	}
 
 	/* create workload queue */
 	ret = workload_queue_create(&mars->workload_queue);
-	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS,
-				pthread_mutex_unlock(&mars_mutex);
-				mars_context_destroy(mars),
-				ret);
+	if (ret != MARS_SUCCESS)
+		goto ERROR_workload_queue_create;
 
 	/* create mpu contexts */
 	ret = mpu_contexts_create(mars, num_mpus);
-	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS,
-				pthread_mutex_unlock(&mars_mutex);
-				mars_context_destroy(mars),
-				ret);
+	if (ret != MARS_SUCCESS)
+		goto ERROR_mpu_contexts_create;
 
 	/* set the shared context pointer */
 	if (shared)
@@ -217,20 +221,41 @@ int mars_context_create(struct mars_cont
 
 	/* unlock mutex */
 	ret = pthread_mutex_unlock(&mars_mutex);
-	MARS_CHECK_RET(ret == 0, MARS_ERROR_INTERNAL);
+	if (ret) {
+		goto ERROR_pthread_mutex_unlock;
+		ret = MARS_ERROR_INTERNAL;
+	}
 
 	return MARS_SUCCESS;
+
+ERROR_pthread_mutex_unlock:
+	mpu_contexts_destroy(mars);
+ERROR_mpu_contexts_create:
+	workload_queue_destroy(mars->workload_queue);
+ERROR_workload_queue_create:
+	free(mars->mpu_context_threads);
+ERROR_malloc_mpu_context_threads:
+	free(mars->kernel_params);
+ERROR_malloc_kernel_params:
+	free(mars);
+ERROR_malloc_mars:
+	pthread_mutex_unlock(&mars_mutex);
+
+	return ret;
 }
 
 int mars_context_destroy(struct mars_context *mars)
 {
-	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-
 	int ret;
 
+	/* check function params */
+	if (!mars)
+		return MARS_ERROR_NULL;
+
 	/* lock mutex */
 	ret = pthread_mutex_lock(&mars_mutex);
-	MARS_CHECK_RET(ret == 0, MARS_ERROR_INTERNAL);
+	if (ret)
+		return MARS_ERROR_INTERNAL;
 
 	/* decrement reference count */
 	mars->reference_count--;
@@ -242,13 +267,15 @@ int mars_context_destroy(struct mars_con
 	/* destroy mpu contexts */
 	if (mars->mpu_context_count) {
 		ret = mpu_contexts_destroy(mars);
-		MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+		if (ret != MARS_SUCCESS)
+			return ret;
 	}
 
 	/* destroy workload queue */
 	if (mars->workload_queue) {
 		ret = workload_queue_destroy(mars->workload_queue);
-		MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+		if (ret != MARS_SUCCESS)
+			return ret;
 	}
 
 	/* free allocated memory */
@@ -262,9 +289,8 @@ int mars_context_destroy(struct mars_con
 
 	/* unlock mutex */
 	ret = pthread_mutex_unlock(&mars_mutex);
-	MARS_CHECK_RET(ret == 0, MARS_ERROR_INTERNAL);
-
-	MARS_PRINT("Destroyed MARS Context (%p)\n", mars);
+	if (ret)
+		return MARS_ERROR_INTERNAL;
 
 	return MARS_SUCCESS;
 }
--- a/src/host/lib/mars_mutex.c
+++ b/src/host/lib/mars_mutex.c
@@ -40,17 +40,18 @@
 
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 int mars_mutex_create(struct mars_mutex **mutex_ret)
 {
-	MARS_CHECK_RET(mutex_ret, MARS_ERROR_NULL);
-
 	struct mars_mutex *mutex;
 
+	if (!mutex_ret)
+		return MARS_ERROR_NULL;
+
 	mutex = (struct mars_mutex *)
 		memalign(MARS_MUTEX_ALIGN, sizeof(struct mars_mutex));
-	MARS_CHECK_RET(mutex, MARS_ERROR_MEMORY);
+	if (!mutex)
+		return MARS_ERROR_MEMORY;
 
 	mutex->lock = MARS_MUTEX_UNLOCKED;
 	__lwsync();
@@ -62,7 +63,8 @@ int mars_mutex_create(struct mars_mutex 
 
 int mars_mutex_destroy(struct mars_mutex *mutex)
 {
-	MARS_CHECK_RET(mutex, MARS_ERROR_NULL);
+	if (!mutex)
+		return MARS_ERROR_NULL;
 
 	free(mutex);
 
@@ -71,7 +73,8 @@ int mars_mutex_destroy(struct mars_mutex
 
 int mars_mutex_reset(struct mars_mutex *mutex)
 {
-	MARS_CHECK_RET(mutex, MARS_ERROR_NULL);
+	if (!mutex)
+		return MARS_ERROR_NULL;
 
 	mutex->lock = MARS_MUTEX_UNLOCKED;
 	__lwsync();
@@ -81,7 +84,8 @@ int mars_mutex_reset(struct mars_mutex *
 
 int mars_mutex_lock(struct mars_mutex *mutex)
 {
-	MARS_CHECK_RET(mutex, MARS_ERROR_NULL);
+	if (!mutex)
+		return MARS_ERROR_NULL;
 
 	do {
 		do {
@@ -95,8 +99,10 @@ int mars_mutex_lock(struct mars_mutex *m
 
 int mars_mutex_unlock(struct mars_mutex *mutex)
 {
-	MARS_CHECK_RET(mutex, MARS_ERROR_NULL);
-	MARS_CHECK_RET(mutex->lock == MARS_MUTEX_LOCKED, MARS_ERROR_STATE);
+	if (!mutex)
+		return MARS_ERROR_NULL;
+	if (mutex->lock != MARS_MUTEX_LOCKED)
+		return MARS_ERROR_STATE;
 
 	__lwsync();
 	mutex->lock = MARS_MUTEX_UNLOCKED;
--- a/src/host/lib/mars_task.c
+++ b/src/host/lib/mars_task.c
@@ -43,38 +43,45 @@
 #include "mars/mars_workload_queue.h"
 #include "mars/mars_context.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 int mars_task_create(struct mars_context *mars,
 			struct mars_task_id *id_ret,
-			const char *name,
-			const void *elf_image,
+			const char *name, const void *elf_image,
 			uint32_t context_save_size)
 {
-	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id_ret, MARS_ERROR_NULL);
-	MARS_CHECK_RET(elf_image, MARS_ERROR_NULL);
-	MARS_CHECK_RET(!name || strlen(name) < MARS_TASK_NAME_LEN_MAX,
-			MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(context_save_size <= MARS_TASK_CONTEXT_SAVE_SIZE_MAX,
-			MARS_ERROR_PARAMS);
-
 	int ret;
 	uint16_t workload_id;
 	struct mars_task_context *task;
 	struct mars_workload_context *workload;
-	Elf32_Ehdr *ehdr = (Elf32_Ehdr *)elf_image;
-	Elf32_Phdr *phdr = (Elf32_Phdr *)((void *)ehdr + ehdr->e_phoff);
+	Elf32_Ehdr *ehdr;
+	Elf32_Phdr *phdr;
 
-	//MARS_CHECK_RET(ehdr->e_phnum == 1, MARS_ERROR_FORMAT);
-	MARS_CHECK_RET(phdr->p_type == PT_LOAD, MARS_ERROR_FORMAT);
-	MARS_CHECK_RET(phdr->p_vaddr == MARS_TASK_ELF_VADDR,
-			MARS_ERROR_FORMAT);
+	/* check function params */
+	if (!mars)
+		return MARS_ERROR_NULL;
+	if (!id_ret)
+		return MARS_ERROR_NULL;
+	if (!elf_image)
+		return MARS_ERROR_NULL;
+	if (name && strlen(name) > MARS_TASK_NAME_LEN_MAX)
+		return MARS_ERROR_PARAMS;
+	if (context_save_size > MARS_TASK_CONTEXT_SAVE_SIZE_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* process elf header information */
+	ehdr = (Elf32_Ehdr *)elf_image;
+	phdr = (Elf32_Phdr *)((void *)ehdr + ehdr->e_phoff);
+
+	if (phdr->p_type != PT_LOAD)
+		return MARS_ERROR_FORMAT;
+	if (phdr->p_vaddr != MARS_TASK_ELF_VADDR)
+		return MARS_ERROR_FORMAT;
 
 	/* begin process to add the task to the workload queue */
 	ret = workload_queue_add_begin(mars->workload_queue, &workload_id,
-				MARS_WORKLOAD_TYPE_TASK, &workload);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+		MARS_WORKLOAD_TYPE_TASK, &workload);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	/* cast workload context to task context */
 	task = (struct mars_task_context *)workload;
@@ -97,11 +104,11 @@ int mars_task_create(struct mars_context
 		task->context_save_size = context_save_size;
 		task->context_save_ea = mars_ptr_to_ea(memalign(
 			MARS_TASK_CONTEXT_SAVE_ALIGN, task->context_save_size));
-
-		MARS_CHECK_CLEANUP_RET(task->context_save_ea,
+		if (!task->context_save_ea) {
 			workload_queue_add_cancel(mars->workload_queue,
-				workload_id),
-			MARS_ERROR_MEMORY);
+				workload_id);
+			return MARS_ERROR_MEMORY;
+		}
 	} else {
 		task->context_save_size = 0;
 		task->context_save_ea = 0;
@@ -109,35 +116,42 @@ int mars_task_create(struct mars_context
 
 	/* end process to add the task to the workload queue */
 	ret = workload_queue_add_end(mars->workload_queue, workload_id);
-	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS,
-			workload_queue_add_cancel(mars->workload_queue,
-				workload_id),
-			ret);
+	if (ret != MARS_SUCCESS) {
+		workload_queue_add_cancel(mars->workload_queue, workload_id);
+		if (context_save_size)
+			free(mars_ea_to_ptr(task->context_save_ea));
+		return ret;
+	}
 
 	/* return id to caller */
 	*id_ret = task->id;
 
-	MARS_PRINT("Initialize Task Context %d\n", workload_id);
-	MARS_PRINT_TASK_CONTEXT(&task);
-
 	return MARS_SUCCESS;
 }
 
 int mars_task_destroy(struct mars_task_id *id)
 {
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id->mars_context_ea, MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(id->workload_id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
-
 	int ret;
+	struct mars_context *mars;
 	struct mars_task_context *task;
 	struct mars_workload_context *workload;
-	struct mars_context *mars = mars_ea_to_ptr(id->mars_context_ea);
+
+	/* check function params */
+	if (!id)
+		return MARS_ERROR_NULL;
+	if (!id->mars_context_ea)
+		return MARS_ERROR_PARAMS;
+	if (!id->workload_id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* get mars context pointer from task id */
+	mars = mars_ea_to_ptr(id->mars_context_ea);
 
 	/* begin process to remove the task from the workload queue */
 	ret = workload_queue_remove_begin(mars->workload_queue,
-				id->workload_id, &workload);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+		id->workload_id, &workload);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	/* cast workload context to task context */
 	task = (struct mars_task_context *)workload;
@@ -148,9 +162,8 @@ int mars_task_destroy(struct mars_task_i
 
 	/* end process to remove the task from the workload queue */
 	ret = workload_queue_remove_end(mars->workload_queue, id->workload_id);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
-
-	MARS_PRINT("Finalize Task Context %d\n", id->workload_id);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	return MARS_SUCCESS;
 }
@@ -158,19 +171,27 @@ int mars_task_destroy(struct mars_task_i
 int mars_task_schedule(struct mars_task_id *id, struct mars_task_args *args,
 			uint8_t priority)
 {
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id->mars_context_ea, MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(id->workload_id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
-
 	int ret;
+	struct mars_context *mars;
 	struct mars_task_context *task;
 	struct mars_workload_context *workload;
-	struct mars_context *mars = mars_ea_to_ptr(id->mars_context_ea);
+
+	/* check function params */
+	if (!id)
+		return MARS_ERROR_NULL;
+	if (!id->mars_context_ea)
+		return MARS_ERROR_PARAMS;
+	if (!id->workload_id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* get mars context pointer from task id */
+	mars = mars_ea_to_ptr(id->mars_context_ea);
 
 	/* begin process to schedule the workload in the workload queue */
 	ret = workload_queue_schedule_begin(mars->workload_queue,
-				id->workload_id, priority, &workload);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+		id->workload_id, priority, &workload);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	/* cast workload context to task context */
 	task = (struct mars_task_context *)workload;
@@ -182,29 +203,36 @@ int mars_task_schedule(struct mars_task_
 
 	/* end process to schedule the workload in the workload queue */
 	ret = workload_queue_schedule_end(mars->workload_queue,
-					id->workload_id);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
-
-	MARS_PRINT("Schedule Task Context %d\n", id->workload_id);
+		id->workload_id);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	return MARS_SUCCESS;
 }
 
 int mars_task_wait(struct mars_task_id *id, int32_t *exit_code)
 {
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id->mars_context_ea, MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(id->workload_id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
-
 	int ret;
+	struct mars_context *mars;
 	struct mars_task_context *task;
 	struct mars_workload_context *workload;
-	struct mars_context *mars = mars_ea_to_ptr(id->mars_context_ea);
+
+	/* check function params */
+	if (!id)
+		return MARS_ERROR_NULL;
+	if (!id->mars_context_ea)
+		return MARS_ERROR_PARAMS;
+	if (!id->workload_id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* get mars context pointer from task id */
+	mars = mars_ea_to_ptr(id->mars_context_ea);
 
 	/* blocking wait for workload completion */
 	ret = workload_queue_wait(mars->workload_queue, id->workload_id,
-				&workload);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+		&workload);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	/* cast workload context to task context */
 	task = (struct mars_task_context *)workload;
@@ -218,19 +246,27 @@ int mars_task_wait(struct mars_task_id *
 
 int mars_task_try_wait(struct mars_task_id *id, int32_t *exit_code)
 {
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id->mars_context_ea, MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(id->workload_id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
-
 	int ret;
+	struct mars_context *mars;
 	struct mars_task_context *task;
 	struct mars_workload_context *workload;
-	struct mars_context *mars = mars_ea_to_ptr(id->mars_context_ea);
+
+	/* check function params */
+	if (!id)
+		return MARS_ERROR_NULL;
+	if (!id->mars_context_ea)
+		return MARS_ERROR_PARAMS;
+	if (!id->workload_id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* get mars context pointer from task id */
+	mars = mars_ea_to_ptr(id->mars_context_ea);
 
 	/* non-blocking wait for workload completion */
 	ret = workload_queue_try_wait(mars->workload_queue, id->workload_id,
-				&workload);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+		&workload);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	/* cast workload context to task context */
 	task = (struct mars_task_context *)workload;
--- a/src/host/lib/mars_task_barrier.c
+++ b/src/host/lib/mars_task_barrier.c
@@ -41,24 +41,30 @@
 #include "mars/mars_context.h"
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 int mars_task_barrier_create(struct mars_context *mars,
 				struct mars_task_barrier **barrier_ret,
 				uint32_t total)
 {
-	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-	MARS_CHECK_RET(barrier_ret, MARS_ERROR_NULL);
-	MARS_CHECK_RET(total <= MARS_TASK_BARRIER_WAIT_MAX, MARS_ERROR_PARAMS);
-
 	struct mars_task_barrier *barrier;
 
+	/* check function params */
+	if (!mars)
+		return MARS_ERROR_NULL;
+	if (!barrier_ret)
+		return MARS_ERROR_NULL;
+	if (total > MARS_TASK_BARRIER_WAIT_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* allocate barrier instance */
 	barrier = (struct mars_task_barrier *)
 		memalign(MARS_TASK_BARRIER_ALIGN, MARS_TASK_BARRIER_SIZE);
-	MARS_CHECK_RET(barrier, MARS_ERROR_MEMORY);
+	if (!barrier)
+		return MARS_ERROR_MEMORY;
 
 	mars_mutex_reset((struct mars_mutex *)barrier);
 
+	/* initialize barrier instance */
 	barrier->mars_context_ea = mars_ptr_to_ea(mars);
 	barrier->total = total;
 	barrier->notified_count = 0;
@@ -66,6 +72,7 @@ int mars_task_barrier_create(struct mars
 	barrier->notify_wait_count = 0;
 	barrier->wait_count = 0;
 
+	/* return barrier instance pointer */
 	*barrier_ret = barrier;
 
 	return MARS_SUCCESS;
@@ -73,7 +80,9 @@ int mars_task_barrier_create(struct mars
 
 int mars_task_barrier_destroy(struct mars_task_barrier *barrier)
 {
-	MARS_CHECK_RET(barrier, MARS_ERROR_NULL);
+	/* check function params */
+	if (!barrier)
+		return MARS_ERROR_NULL;
 
 	free(barrier);
 
--- a/src/host/lib/mars_task_event_flag.c
+++ b/src/host/lib/mars_task_event_flag.c
@@ -44,37 +44,43 @@
 #include "mars/mars_context.h"
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 int mars_task_event_flag_create(struct mars_context *mars,
 				struct mars_task_event_flag **event_flag_ret,
 				uint8_t direction,
 				uint8_t clear_mode)
 {
-	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-	MARS_CHECK_RET(event_flag_ret, MARS_ERROR_NULL);
-	MARS_CHECK_RET(direction == MARS_TASK_EVENT_FLAG_HOST_TO_MPU ||
-			direction == MARS_TASK_EVENT_FLAG_MPU_TO_HOST ||
-			direction == MARS_TASK_EVENT_FLAG_MPU_TO_MPU,
-			MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(clear_mode == MARS_TASK_EVENT_FLAG_CLEAR_AUTO ||
-			clear_mode == MARS_TASK_EVENT_FLAG_CLEAR_MANUAL,
-			MARS_ERROR_PARAMS);
-
 	struct mars_task_event_flag *event_flag;
 
+	/* check function params */
+	if (!mars)
+		return MARS_ERROR_NULL;
+	if (!event_flag_ret)
+		return MARS_ERROR_NULL;
+	if (direction != MARS_TASK_EVENT_FLAG_HOST_TO_MPU &&
+		direction != MARS_TASK_EVENT_FLAG_MPU_TO_HOST &&
+		direction != MARS_TASK_EVENT_FLAG_MPU_TO_MPU)
+		return MARS_ERROR_PARAMS;
+	if (clear_mode != MARS_TASK_EVENT_FLAG_CLEAR_AUTO &&
+		clear_mode != MARS_TASK_EVENT_FLAG_CLEAR_MANUAL)
+		return MARS_ERROR_PARAMS;
+
+	/* allocate event flag instance */
 	event_flag = (struct mars_task_event_flag *)
 		memalign(MARS_TASK_EVENT_FLAG_ALIGN, MARS_TASK_EVENT_FLAG_SIZE);
-	MARS_CHECK_RET(event_flag, MARS_ERROR_MEMORY);
+	if (!event_flag)
+		return MARS_ERROR_MEMORY;
 
 	mars_mutex_reset((struct mars_mutex *)event_flag);
 
+	/* intialize event flag instance */
 	event_flag->mars_context_ea = mars_ptr_to_ea(mars);
 	event_flag->bits = 0;
 	event_flag->direction = direction;
 	event_flag->clear_mode = clear_mode;
 	event_flag->wait_count = 0;
 
+	/* return event flag instance pointer */
 	*event_flag_ret = event_flag;
 
 	return MARS_SUCCESS;
@@ -82,7 +88,9 @@ int mars_task_event_flag_create(struct m
 
 int mars_task_event_flag_destroy(struct mars_task_event_flag *event_flag)
 {
-	MARS_CHECK_RET(event_flag, MARS_ERROR_NULL);
+	/* check function params */
+	if (!event_flag)
+		return MARS_ERROR_NULL;
 
 	free(event_flag);
 
@@ -92,7 +100,8 @@ int mars_task_event_flag_destroy(struct 
 int mars_task_event_flag_clear(struct mars_task_event_flag *event_flag,
 				uint32_t bits)
 {
-	MARS_CHECK_RET(event_flag, MARS_ERROR_NULL);
+	if (!event_flag)
+		return MARS_ERROR_NULL;
 
 	mars_mutex_lock((struct mars_mutex *)event_flag);
 
@@ -107,17 +116,23 @@ int mars_task_event_flag_clear(struct ma
 int mars_task_event_flag_set(struct mars_task_event_flag *event_flag,
 				uint32_t bits)
 {
-	MARS_CHECK_RET(event_flag, MARS_ERROR_NULL);
-	MARS_CHECK_RET(event_flag->mars_context_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET(event_flag->direction ==
-			MARS_TASK_EVENT_FLAG_HOST_TO_MPU, MARS_ERROR_STATE);
-
 	int ret;
 	int i;
-	struct mars_context *mars = mars_ea_to_ptr(event_flag->mars_context_ea);
+	struct mars_context *mars;
+
+	/* check function params */
+	if (!event_flag)
+		return MARS_ERROR_NULL;
+	if (!event_flag->mars_context_ea)
+		return MARS_ERROR_NULL;
+	if (event_flag->direction != MARS_TASK_EVENT_FLAG_HOST_TO_MPU)
+		return MARS_ERROR_STATE;
 
 	mars_mutex_lock((struct mars_mutex *)event_flag);
 
+	/* get mars context pointer */
+	mars = mars_ea_to_ptr(event_flag->mars_context_ea);
+
 	/* set the necessary bits */
 	event_flag->bits |= bits;
 
@@ -142,7 +157,8 @@ int mars_task_event_flag_set(struct mars
 		/* signal the task to go to ready state */
 		ret = workload_queue_signal_send(mars->workload_queue,
 			event_flag->wait_id[i]);
-		MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+		if (ret != MARS_SUCCESS)
+			return ret;
 
 		/* flush id from wait list */
 		event_flag->wait_count--;
@@ -167,12 +183,14 @@ int mars_task_event_flag_wait(struct mar
 				uint32_t mask, uint8_t mask_mode,
 				uint32_t *bits)
 {
-	MARS_CHECK_RET(event_flag, MARS_ERROR_NULL);
-	MARS_CHECK_RET(event_flag->direction ==
-			MARS_TASK_EVENT_FLAG_MPU_TO_HOST, MARS_ERROR_STATE);
-	MARS_CHECK_RET(mask_mode == MARS_TASK_EVENT_FLAG_MASK_OR ||
-			mask_mode == MARS_TASK_EVENT_FLAG_MASK_AND,
-			MARS_ERROR_PARAMS);
+	/* check function params */
+	if (!event_flag)
+		return MARS_ERROR_NULL;
+	if (event_flag->direction != MARS_TASK_EVENT_FLAG_MPU_TO_HOST)
+		return MARS_ERROR_STATE;
+	if (mask_mode != MARS_TASK_EVENT_FLAG_MASK_OR &&
+		mask_mode != MARS_TASK_EVENT_FLAG_MASK_AND)
+		return MARS_ERROR_PARAMS;
 
 	mars_mutex_lock((struct mars_mutex *)event_flag);
 
@@ -213,12 +231,14 @@ int mars_task_event_flag_try_wait(struct
 				uint32_t mask, uint8_t mask_mode,
 				uint32_t *bits)
 {
-	MARS_CHECK_RET(event_flag, MARS_ERROR_NULL);
-	MARS_CHECK_RET(event_flag->direction ==
-			MARS_TASK_EVENT_FLAG_MPU_TO_HOST, MARS_ERROR_STATE);
-	MARS_CHECK_RET(mask_mode == MARS_TASK_EVENT_FLAG_MASK_OR ||
-			mask_mode == MARS_TASK_EVENT_FLAG_MASK_AND,
-			MARS_ERROR_PARAMS);
+	/* check function params */
+	if (!event_flag)
+		return MARS_ERROR_NULL;
+	if (event_flag->direction != MARS_TASK_EVENT_FLAG_MPU_TO_HOST)
+		return MARS_ERROR_STATE;
+	if (mask_mode != MARS_TASK_EVENT_FLAG_MASK_OR &&
+		mask_mode != MARS_TASK_EVENT_FLAG_MASK_AND)
+		return MARS_ERROR_PARAMS;
 
 	mars_mutex_lock((struct mars_mutex *)event_flag);
 
--- a/src/host/lib/mars_task_queue.c
+++ b/src/host/lib/mars_task_queue.c
@@ -44,7 +44,6 @@
 #include "mars/mars_context.h"
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 int mars_task_queue_create(struct mars_context *mars,
 				struct mars_task_queue **queue_ret,
@@ -52,28 +51,37 @@ int mars_task_queue_create(struct mars_c
 				uint32_t depth,
 				uint8_t direction)
 {
-	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-	MARS_CHECK_RET(queue_ret, MARS_ERROR_NULL);
-	MARS_CHECK_RET((size & MARS_TASK_QUEUE_ENTRY_SIZE_MASK) == 0 &&
-			size <= MARS_TASK_QUEUE_ENTRY_SIZE_MAX,
-			MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(direction == MARS_TASK_QUEUE_HOST_TO_MPU ||
-			direction == MARS_TASK_QUEUE_MPU_TO_HOST ||
-			direction == MARS_TASK_QUEUE_MPU_TO_MPU,
-			MARS_ERROR_PARAMS);
-
 	struct mars_task_queue *queue;
 	void *buffer;
 
+	/* check function params */
+	if (!mars)
+		return MARS_ERROR_NULL;
+	if (!queue_ret)
+		return MARS_ERROR_NULL;
+	if (size & MARS_TASK_QUEUE_ENTRY_SIZE_MASK)
+		return MARS_ERROR_PARAMS;
+	if (size > MARS_TASK_QUEUE_ENTRY_SIZE_MAX)
+		return MARS_ERROR_PARAMS;
+	if (direction != MARS_TASK_QUEUE_HOST_TO_MPU &&
+		direction != MARS_TASK_QUEUE_MPU_TO_HOST &&
+		direction != MARS_TASK_QUEUE_MPU_TO_MPU)
+		return MARS_ERROR_PARAMS;
+
+	/* allocate queue instance */
 	queue = (struct mars_task_queue *)
 		memalign(MARS_TASK_QUEUE_ALIGN, MARS_TASK_QUEUE_SIZE);
-	MARS_CHECK_RET(queue, MARS_ERROR_MEMORY);
+	if (!queue)
+		return MARS_ERROR_MEMORY;
 
+	/* allocate queue buffer instance */
 	buffer = memalign(MARS_TASK_QUEUE_BUFFER_ALIGN, size * depth);
-	MARS_CHECK_CLEANUP_RET(buffer, free(queue), MARS_ERROR_MEMORY);
+	if (!buffer)
+		return MARS_ERROR_MEMORY;
 
 	mars_mutex_reset((struct mars_mutex *)queue);
 
+	/* initialize queue instance */
 	queue->mars_context_ea = mars_ptr_to_ea(mars);
 	queue->buffer_ea = mars_ptr_to_ea(buffer);
 	queue->push_ea = mars_ptr_to_ea(buffer);
@@ -85,6 +93,7 @@ int mars_task_queue_create(struct mars_c
 	queue->push_wait_count = 0;
 	queue->pop_wait_count = 0;
 
+	/* return queue instance pointer */
 	*queue_ret = queue;
 
 	return MARS_SUCCESS;
@@ -92,7 +101,9 @@ int mars_task_queue_create(struct mars_c
 
 int mars_task_queue_destroy(struct mars_task_queue *queue)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
 
 	free(queue);
 
@@ -101,10 +112,13 @@ int mars_task_queue_destroy(struct mars_
 
 int mars_task_queue_count(struct mars_task_queue *queue, uint32_t *count)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(count, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (!count)
+		return MARS_ERROR_NULL;
+	if ((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
 
 	mars_mutex_lock((struct mars_mutex *)queue);
 
@@ -118,15 +132,20 @@ int mars_task_queue_count(struct mars_ta
 
 int mars_task_queue_clear(struct mars_task_queue *queue)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
 	int i;
-	struct mars_context *mars = mars_ea_to_ptr(queue->mars_context_ea);
+	struct mars_context *mars;
+
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if ((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
 
 	mars_mutex_lock((struct mars_mutex *)queue);
 
+	/* get mars context pointer */
+	mars = mars_ea_to_ptr(queue->mars_context_ea);
+
 	/* signal all waiting tasks that queue is ready for push */
 	for (i = 0; i < queue->push_wait_count; i++)
 		workload_queue_signal_send(
@@ -174,11 +193,13 @@ static void push_update(struct mars_task
 
 static int push(struct mars_task_queue *queue, const void *data, int try)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(queue->direction == MARS_TASK_QUEUE_HOST_TO_MPU,
-			MARS_ERROR_STATE);
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if ((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if (queue->direction != MARS_TASK_QUEUE_HOST_TO_MPU)
+		return MARS_ERROR_STATE;
 
 	mars_mutex_lock((struct mars_mutex *)queue);
 
@@ -246,11 +267,13 @@ static void pop_update(struct mars_task_
 
 static int pop(struct mars_task_queue *queue, void *data, int peek, int try)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(queue->direction == MARS_TASK_QUEUE_MPU_TO_HOST,
-			MARS_ERROR_STATE);
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if ((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if (queue->direction != MARS_TASK_QUEUE_MPU_TO_HOST)
+		return MARS_ERROR_STATE;
 
 	mars_mutex_lock((struct mars_mutex *)queue);
 
--- a/src/host/lib/mars_task_semaphore.c
+++ b/src/host/lib/mars_task_semaphore.c
@@ -42,29 +42,33 @@
 #include "mars/mars_context.h"
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 int mars_task_semaphore_create(struct mars_context *mars,
 				struct mars_task_semaphore **semaphore_ret,
 				int32_t count)
 {
-	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-	MARS_CHECK_RET(semaphore_ret, MARS_ERROR_NULL);
-	MARS_CHECK_RET(abs(count) < MARS_TASK_SEMAPHORE_WAIT_MAX,
-			MARS_ERROR_PARAMS);
-
 	struct mars_task_semaphore *semaphore;
 
+	/* check function params */
+	if (!mars)
+		return MARS_ERROR_NULL;
+	if (!semaphore_ret)
+		return MARS_ERROR_NULL;
+
+	/* allocate semaphore instance */
 	semaphore = (struct mars_task_semaphore *)
 		memalign(MARS_TASK_SEMAPHORE_ALIGN, MARS_TASK_SEMAPHORE_SIZE);
-	MARS_CHECK_RET(semaphore, MARS_ERROR_MEMORY);
+	if (!semaphore)
+		return MARS_ERROR_MEMORY;
 
 	mars_mutex_reset((struct mars_mutex *)semaphore);
 
+	/* initialize semaphore instance */
 	semaphore->mars_context_ea = mars_ptr_to_ea(mars);
 	semaphore->count = count;
 	semaphore->wait_count = 0;
 
+	/* return semaphore instance */
 	*semaphore_ret = semaphore;
 
 	return MARS_SUCCESS;
@@ -72,7 +76,9 @@ int mars_task_semaphore_create(struct ma
 
 int mars_task_semaphore_destroy(struct mars_task_semaphore *semaphore)
 {
-	MARS_CHECK_RET(semaphore, MARS_ERROR_NULL);
+	/* check function params */
+	if (!semaphore)
+		return MARS_ERROR_NULL;
 
 	free(semaphore);
 
--- a/src/host/lib/mars_task_signal.c
+++ b/src/host/lib/mars_task_signal.c
@@ -39,18 +39,25 @@
 #include "mars/mars_workload_queue.h"
 #include "mars/mars_context.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 int mars_task_signal_send(struct mars_task_id *id)
 {
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id->mars_context_ea, MARS_ERROR_PARAMS);
-
 	int ret;
-	struct mars_context *mars = mars_ea_to_ptr(id->mars_context_ea);
+	struct mars_context *mars;
+
+	/* check function params */
+	if (!id)
+		return MARS_ERROR_NULL;
+
+	/* get mars context pointer */
+	mars = mars_ea_to_ptr(id->mars_context_ea);
+	if (!mars)
+		return MARS_ERROR_PARAMS;
 
+	/* send signal to workload */
 	ret = workload_queue_signal_send(mars->workload_queue, id->workload_id);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	return MARS_SUCCESS;
 }
--- a/src/host/lib/mars_workload_queue.c
+++ b/src/host/lib/mars_workload_queue.c
@@ -45,21 +45,22 @@
 #include "mars/mars_context.h"
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 int workload_queue_create(struct mars_workload_queue **queue_ret)
 {
-	MARS_CHECK_RET(queue_ret, MARS_ERROR_NULL);
-
 	int block;
 	int index;
-
 	struct mars_workload_queue *queue;
 
-	/* allocate */
+	/* check function params */
+	if (!queue_ret)
+		return MARS_ERROR_NULL;
+
+	/* allocate workload instance */
 	queue = (struct mars_workload_queue *)memalign(
 		MARS_WORKLOAD_QUEUE_ALIGN, sizeof(struct mars_workload_queue));
-	MARS_CHECK_RET(queue, MARS_ERROR_MEMORY);
+	if (!queue)
+		return MARS_ERROR_MEMORY;
 
 	/* initialize workload queue header */
 	queue->header.flag = MARS_WORKLOAD_QUEUE_FLAG_NONE;
@@ -88,6 +89,7 @@ int workload_queue_create(struct mars_wo
 		}
 	}
 
+	/* return workload queue instance */
 	*queue_ret = queue;
 
 	return MARS_SUCCESS;
@@ -95,13 +97,14 @@ int workload_queue_create(struct mars_wo
 
 int workload_queue_destroy(struct mars_workload_queue *queue)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-
 	int block;
 	int index;
-
 	uint16_t id = 0;
 
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+
 	/* check for any tasks left in workload queue */
 	while (id < MARS_WORKLOAD_MAX) {
 		block = id / MARS_WORKLOAD_PER_BLOCK;
@@ -115,9 +118,10 @@ int workload_queue_destroy(struct mars_w
 	}
 
 	/* found some task left in workload queue */
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_STATE);
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_STATE;
 
-	/* free allocated memory */
+	/* free workload queue instance */
 	free(queue);
 
 	return MARS_SUCCESS;
@@ -125,7 +129,9 @@ int workload_queue_destroy(struct mars_w
 
 int workload_queue_exit(struct mars_workload_queue *queue)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
 
 	queue->header.flag = MARS_WORKLOAD_QUEUE_FLAG_EXIT;
 
@@ -136,19 +142,26 @@ int workload_queue_add_begin(struct mars
 				uint8_t type,
 				struct mars_workload_context **workload)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
-	MARS_CHECK_RET(type == MARS_WORKLOAD_TYPE_TASK, MARS_ERROR_PARAMS);
-
 	int block = 0;
 	int index = 0;
+	uint64_t *bits;
 
-	uint64_t *bits = &queue->block[block].bits[index];
-
-	*id = 0;
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (!id)
+		return MARS_ERROR_NULL;
+	if (type != MARS_WORKLOAD_TYPE_TASK)
+		return MARS_ERROR_PARAMS;
 
 	mars_mutex_lock((struct mars_mutex *)&queue->block[block]);
 
+	/* get bits from workload queue block */
+	bits = &queue->block[block].bits[index];
+
+	/* initialize return id to 0 */
+	*id = 0;
+
 	while (MARS_BITS_GET(bits, STATE) != MARS_WORKLOAD_STATE_NONE) {
 		(*id)++;
 		index++;
@@ -167,10 +180,11 @@ int workload_queue_add_begin(struct mars
 		bits = &queue->block[block].bits[index];
 	}
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(bits, STATE) == MARS_WORKLOAD_STATE_NONE,
-		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]),
-		MARS_ERROR_STATE);
+	/* check for valid state */
+	if (MARS_BITS_GET(bits, STATE) != MARS_WORKLOAD_STATE_NONE) {
+		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]);
+		return MARS_ERROR_STATE;
+	}
 
 	/* set type and set state to adding */
 	MARS_BITS_SET(bits, TYPE, type);
@@ -187,20 +201,30 @@ int workload_queue_add_begin(struct mars
 
 int workload_queue_add_end(struct mars_workload_queue *queue, uint16_t id)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
-
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	int block;
+	int index;
+	uint64_t *bits;
 
-	uint64_t *bits = &queue->block[block].bits[index];
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
 
 	mars_mutex_lock((struct mars_mutex *)&queue->block[block]);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(bits, STATE) == MARS_WORKLOAD_STATE_ADDING,
-		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]),
-		MARS_ERROR_STATE);
+	/* get bits from workload queue block */
+	bits = &queue->block[block].bits[index];
+
+	/* check for valid state */
+	if (MARS_BITS_GET(bits, STATE) != MARS_WORKLOAD_STATE_ADDING) {
+		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]);
+		return MARS_ERROR_STATE;
+	}
 
 	/* reset workload queue bits and set state to finished state */
 	MARS_BITS_SET(bits, STATE, MARS_WORKLOAD_STATE_FINISHED);
@@ -212,19 +236,27 @@ int workload_queue_add_end(struct mars_w
 
 int workload_queue_add_cancel(struct mars_workload_queue *queue, uint16_t id)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
+	int block;
+	int index;
 
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
 
 	mars_mutex_lock((struct mars_mutex *)&queue->block[block]);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(&queue->block[block].bits[index], STATE) ==
-			MARS_WORKLOAD_STATE_ADDING,
-		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]),
-		MARS_ERROR_STATE);
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
+		MARS_WORKLOAD_STATE_ADDING) {
+		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]);
+		return MARS_ERROR_STATE;
+	}
 
 	/* set state back to none state */
 	MARS_BITS_SET(&queue->block[block].bits[index], STATE,
@@ -238,19 +270,27 @@ int workload_queue_add_cancel(struct mar
 int workload_queue_remove_begin(struct mars_workload_queue *queue, uint16_t id,
 				struct mars_workload_context **workload)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
+	int block;
+	int index;
 
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
 
 	mars_mutex_lock((struct mars_mutex *)&queue->block[block]);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(&queue->block[block].bits[index], STATE) ==
-			MARS_WORKLOAD_STATE_FINISHED,
-		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]),
-		MARS_ERROR_STATE);
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
+		MARS_WORKLOAD_STATE_FINISHED) {
+		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]);
+		return MARS_ERROR_STATE;
+	}
 
 	/* set state to removing */
 	MARS_BITS_SET(&queue->block[block].bits[index], STATE,
@@ -267,19 +307,27 @@ int workload_queue_remove_begin(struct m
 
 int workload_queue_remove_end(struct mars_workload_queue *queue, uint16_t id)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
+	int block;
+	int index;
 
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
 
 	mars_mutex_lock((struct mars_mutex *)&queue->block[block]);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(&queue->block[block].bits[index], STATE) ==
-			MARS_WORKLOAD_STATE_REMOVING,
-		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]),
-		MARS_ERROR_STATE);
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
+		MARS_WORKLOAD_STATE_REMOVING) {
+		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]);
+		return MARS_ERROR_STATE;
+	}
 
 	/* set state to none */
 	MARS_BITS_SET(&queue->block[block].bits[index], TYPE,
@@ -292,19 +340,27 @@ int workload_queue_remove_end(struct mar
 
 int workload_queue_remove_cancel(struct mars_workload_queue *queue, uint16_t id)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
+	int block;
+	int index;
 
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
 
 	mars_mutex_lock((struct mars_mutex *)&queue->block[block]);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(&queue->block[block].bits[index], STATE) ==
-			MARS_WORKLOAD_STATE_REMOVING,
-		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]),
-		MARS_ERROR_STATE);
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
+		MARS_WORKLOAD_STATE_REMOVING) {
+		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]);
+		return MARS_ERROR_STATE;
+	}
 
 	/* set state back to finished */
 	MARS_BITS_SET(&queue->block[block].bits[index], TYPE,
@@ -319,19 +375,27 @@ int workload_queue_schedule_begin(struct
 				uint16_t id, uint8_t priority,
 				struct mars_workload_context **workload)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
+	int block;
+	int index;
 
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
 
 	mars_mutex_lock((struct mars_mutex *)&queue->block[block]);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(&queue->block[block].bits[index], STATE) ==
-			MARS_WORKLOAD_STATE_FINISHED,
-		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]),
-		MARS_ERROR_STATE);
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
+		MARS_WORKLOAD_STATE_FINISHED) {
+		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]);
+		return MARS_ERROR_STATE;
+	}
 
 	/* reset workload queue bits and set state to scheduling */
 	MARS_BITS_SET(&queue->block[block].bits[index], STATE,
@@ -356,19 +420,27 @@ int workload_queue_schedule_begin(struct
 
 int workload_queue_schedule_end(struct mars_workload_queue *queue, uint16_t id)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
+	int block;
+	int index;
 
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
 
 	mars_mutex_lock((struct mars_mutex *)&queue->block[block]);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(&queue->block[block].bits[index], STATE) ==
-			MARS_WORKLOAD_STATE_SCHEDULING,
-		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]),
-		MARS_ERROR_STATE);
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
+		MARS_WORKLOAD_STATE_SCHEDULING) {
+		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]);
+		return MARS_ERROR_STATE;
+	}
 
 	/* set state to ready */
 	MARS_BITS_SET(&queue->block[block].bits[index], STATE,
@@ -382,19 +454,27 @@ int workload_queue_schedule_end(struct m
 int workload_queue_schedule_cancel(struct mars_workload_queue *queue,
 				uint16_t id)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
+	int block;
+	int index;
 
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
 
 	mars_mutex_lock((struct mars_mutex *)&queue->block[block]);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(&queue->block[block].bits[index], STATE) ==
-			MARS_WORKLOAD_STATE_SCHEDULING,
-		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]),
-		MARS_ERROR_STATE);
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
+		MARS_WORKLOAD_STATE_SCHEDULING) {
+		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]);
+		return MARS_ERROR_STATE;
+	}
 
 	/* set state back to finished */
 	MARS_BITS_SET(&queue->block[block].bits[index], STATE,
@@ -408,18 +488,25 @@ int workload_queue_schedule_cancel(struc
 int workload_queue_wait(struct mars_workload_queue *queue, uint16_t id,
 			struct mars_workload_context **workload)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
+	int block;
+	int index;
 
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
 
+	/* loop until workload state is finished */
 	while (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
 		MARS_WORKLOAD_STATE_FINISHED) {
-		MARS_CHECK_RET(
-			MARS_BITS_GET(&queue->block[block].bits[index], STATE)
-				!= MARS_WORKLOAD_STATE_NONE,
-			MARS_ERROR_STATE);
+		if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) ==
+			MARS_WORKLOAD_STATE_NONE)
+			return MARS_ERROR_STATE;
 		sched_yield();
 	}
 
@@ -433,17 +520,25 @@ int workload_queue_wait(struct mars_work
 int workload_queue_try_wait(struct mars_workload_queue *queue, uint16_t id,
 			struct mars_workload_context **workload)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
-
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	int block;
+	int index;
 
-	MARS_CHECK_RET(
-		MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
-			MARS_WORKLOAD_STATE_NONE,
-		MARS_ERROR_STATE);
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
+
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) ==
+		MARS_WORKLOAD_STATE_NONE)
+		return MARS_ERROR_STATE;
 
+	/* check if workload is finished */
 	if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
 		MARS_WORKLOAD_STATE_FINISHED)
 		return MARS_ERROR_BUSY;
@@ -457,20 +552,29 @@ int workload_queue_try_wait(struct mars_
 
 int workload_queue_signal_send(struct mars_workload_queue *queue, uint16_t id)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
+	int block;
+	int index;
 
-	int block = id / MARS_WORKLOAD_PER_BLOCK;
-	int index = id % MARS_WORKLOAD_PER_BLOCK;
+	/* check function params */
+	if (!queue)
+		return MARS_ERROR_NULL;
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
 
 	mars_mutex_lock((struct mars_mutex *)&queue->block[block]);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=
-			MARS_WORKLOAD_STATE_NONE,
-		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]),
-		MARS_ERROR_STATE);
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue->block[block].bits[index], STATE) ==
+		MARS_WORKLOAD_STATE_NONE) {
+		mars_mutex_unlock((struct mars_mutex *)&queue->block[block]);
+		return MARS_ERROR_STATE;
+	}
 
+	/* set signal bit on */
 	MARS_BITS_SET(&queue->block[block].bits[index], SIGNAL,
 		MARS_WORKLOAD_SIGNAL_ON);
 
--- a/src/mpu/kernel/mars_kernel.c
+++ b/src/mpu/kernel/mars_kernel.c
@@ -40,7 +40,6 @@
 #include "mars/mars_kernel.h"
 #include "mars/mars_dma.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 struct mars_kernel_params kernel_params;
 
@@ -53,10 +52,7 @@ int main(unsigned long long mpu_context_
 	syscall_setup();
 
 	mars_dma_get_and_wait(&kernel_params, kernel_params_ea,
-			sizeof(struct mars_kernel_params), MARS_DMA_TAG);
-
-	MARS_PRINT_KERNEL_PARAMS(&kernel_params);
-	MARS_PRINT("Kernel Started\n");
+		sizeof(struct mars_kernel_params), MARS_DMA_TAG);
 
 	while (!exit_flag) {
 		int status = scheduler();
@@ -72,7 +68,5 @@ int main(unsigned long long mpu_context_
 		}
 	}
 
-	MARS_PRINT("Kernel Finished\n");
-
 	return MARS_SUCCESS;
 }
--- a/src/mpu/kernel/mars_kernel_scheduler.c
+++ b/src/mpu/kernel/mars_kernel_scheduler.c
@@ -54,11 +54,11 @@ void release_workload(void);
 static inline void get_block(int block, struct mars_workload_queue_block *dst)
 {
 	mars_dma_get_and_wait(dst,
-			queue_header.queue_ea +
-			offsetof(struct mars_workload_queue, block) +
-			sizeof(struct mars_workload_queue_block) * block,
-			sizeof(struct mars_workload_queue_block),
-			MARS_DMA_TAG);
+		queue_header.queue_ea +
+		offsetof(struct mars_workload_queue, block) +
+		sizeof(struct mars_workload_queue_block) * block,
+		sizeof(struct mars_workload_queue_block),
+		MARS_DMA_TAG);
 }
 
 static int search_block(int block)
@@ -147,8 +147,8 @@ static int reserve_block(int block)
 {
 	int index;
 	uint64_t block_ea = queue_header.queue_ea +
-			offsetof(struct mars_workload_queue, block) +
-			sizeof(struct mars_workload_queue_block) * block;
+		offsetof(struct mars_workload_queue, block) +
+		sizeof(struct mars_workload_queue_block) * block;
 
 	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
 
@@ -172,8 +172,8 @@ static int reserve_block(int block)
 static void release_block(int block, int index)
 {
 	uint64_t block_ea = queue_header.queue_ea +
-			offsetof(struct mars_workload_queue, block) +
-			sizeof(struct mars_workload_queue_block) * block;
+		offsetof(struct mars_workload_queue, block) +
+		sizeof(struct mars_workload_queue_block) * block;
 
 	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
 
@@ -203,11 +203,11 @@ int reserve_workload(void)
 	workload_index = MARS_WORKLOAD_PER_BLOCK * block + index;
 	workload_type = MARS_BITS_GET(&queue_block.bits[index], TYPE);
 	workload_ea = queue_header.context_ea +
-			workload_index * sizeof(struct mars_workload_context);
+		workload_index * sizeof(struct mars_workload_context);
 
 	/* dma the workload context code into LS from main memory */
 	mars_dma_get_and_wait(&workload, workload_ea,
-			sizeof(struct mars_workload_context), MARS_DMA_TAG);
+		sizeof(struct mars_workload_context), MARS_DMA_TAG);
 
 	return MARS_WORKLOAD_RESERVED;
 }
@@ -218,7 +218,7 @@ void release_workload(void)
 	int index = workload_index % MARS_WORKLOAD_PER_BLOCK;
 
 	mars_dma_put_and_wait(&workload, workload_ea,
-			sizeof(struct mars_workload_context), MARS_DMA_TAG);
+		sizeof(struct mars_workload_context), MARS_DMA_TAG);
 
 	/* release block reservation */
 	release_block(block, index);
@@ -230,10 +230,10 @@ int scheduler(void)
 
 	/* dma in queue header */
 	mars_dma_get_and_wait(&queue_header,
-			kernel_params.workload_queue_ea +
-			offsetof(struct mars_workload_queue, header),
-			sizeof(struct mars_workload_queue_header),
-			MARS_DMA_TAG);
+		kernel_params.workload_queue_ea +
+		offsetof(struct mars_workload_queue, header),
+		sizeof(struct mars_workload_queue_header),
+		MARS_DMA_TAG);
 
 	/* return exit status if exit flag is set from host */
 	if (queue_header.flag == MARS_WORKLOAD_QUEUE_FLAG_EXIT)
--- a/src/mpu/kernel/mars_kernel_task.c
+++ b/src/mpu/kernel/mars_kernel_task.c
@@ -42,14 +42,10 @@ extern void *workload_stack;
 
 void task_exec(struct mars_task_context *task)
 {
-	MARS_ASSERT(task);
-
 	if (!task->stack) {
 		/* dma the exec code into mpu storage from host storage */
 		mars_dma_large_get_and_wait((void *)task->vaddr,
-					task->exec_ea,
-					task->exec_size,
-					MARS_DMA_TAG);
+			task->exec_ea, task->exec_size, MARS_DMA_TAG);
 
 		/* 0 the bss section */
 		memset((void *)task->vaddr + task->exec_size, 0,
@@ -65,46 +61,30 @@ void task_exec(struct mars_task_context 
 void task_exit(struct mars_task_context *task)
 {
 	(void)task;
-
-	MARS_ASSERT(task);
 }
 
 void task_yield(struct mars_task_context *task)
 {
-	MARS_ASSERT(task);
-	MARS_ASSERT(task->context_save_ea);
-	MARS_ASSERT(task->context_save_size);
-
 	/* save workload stack pointer */
 	task->stack = (uint32_t)workload_stack;
 
 	/* dma context into context save area in host storage */
 	mars_dma_large_put_and_wait((void *)task->vaddr,
-					task->context_save_ea,
-					task->context_save_size,
-					MARS_DMA_TAG);
+		task->context_save_ea, task->context_save_size, MARS_DMA_TAG);
 }
 
 void task_resume(struct mars_task_context *task)
 {
-	MARS_ASSERT(task);
-	MARS_ASSERT(task->context_save_ea);
-	MARS_ASSERT(task->context_save_size);
-
 	/* restore workload stack pointer */
 	workload_stack = (void *)task->stack;
 
 	/* dma context to mpu storage from context save area in host storage */
 	mars_dma_large_get_and_wait((void *)task->vaddr,
-					task->context_save_ea,
-					task->context_save_size,
-					MARS_DMA_TAG);
+		task->context_save_ea, task->context_save_size, MARS_DMA_TAG);
 }
 
 void task_schedule(struct mars_task_context *task, struct mars_task_args *args)
 {
-	MARS_ASSERT(task);
-
 	/* initialize task specific context variables */
 	task->stack = 0;
 	if (args)
--- a/src/mpu/kernel/mars_kernel_workload.c
+++ b/src/mpu/kernel/mars_kernel_workload.c
@@ -62,24 +62,25 @@ struct mars_workload_context *workload_g
 
 struct mars_workload_context *workload_get_by_id(uint16_t workload_id)
 {
-	MARS_CHECK_RET(workload_id < MARS_WORKLOAD_MAX, NULL);
-
 	static struct mars_workload_context requested_workload;
 	uint64_t requested_workload_ea;
 
+	/* check function params */
+	if (workload_id >= MARS_WORKLOAD_MAX)
+		return NULL;
+
 	/* workload id is same as current workload so return local copy */
 	if (workload_id == workload_index)
 		return &workload;
 
 	/* get ea of workload to get */
 	requested_workload_ea = queue_header.context_ea +
-			workload_id * sizeof(struct mars_workload_context);
+		workload_id * sizeof(struct mars_workload_context);
 
 	/* dma the workload context code into LS from main memory */
 	mars_dma_get_and_wait((void *)&requested_workload,
-				requested_workload_ea,
-				sizeof(struct mars_workload_context),
-				MARS_DMA_TAG);
+		requested_workload_ea, sizeof(struct mars_workload_context),
+		MARS_DMA_TAG);
 
 	return &requested_workload;
 }
@@ -146,19 +147,27 @@ void workload_resume(void)
 
 int workload_schedule(uint16_t workload_id, void *args, uint8_t priority)
 {
-	MARS_CHECK_RET(workload_id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(workload_id != workload_index, MARS_ERROR_PARAMS);
-
 	struct mars_workload_context schedule_workload;
 	uint8_t schedule_workload_type;
 	uint64_t schedule_workload_ea;
+	uint64_t block_ea;
+	int block;
+	int index;
+
+	/* check function params */
+	if (workload_id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+	if (workload_id == workload_index)
+		return MARS_ERROR_PARAMS;
 
-	int block = workload_id / MARS_WORKLOAD_PER_BLOCK;
-	int index = workload_id % MARS_WORKLOAD_PER_BLOCK;
-
-	uint64_t block_ea = queue_header.queue_ea +
-			offsetof(struct mars_workload_queue, block) +
-			sizeof(struct mars_workload_queue_block) * block;
+	/* calculate block/index from id */
+	block = workload_id / MARS_WORKLOAD_PER_BLOCK;
+	index = workload_id % MARS_WORKLOAD_PER_BLOCK;
+
+	/* calculate block ea */
+	block_ea = queue_header.queue_ea +
+		offsetof(struct mars_workload_queue, block) +
+		sizeof(struct mars_workload_queue_block) * block;
 
 	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
 
@@ -173,28 +182,27 @@ int workload_schedule(uint16_t workload_
 	/* get information of workload to schedule */
 	schedule_workload_type = MARS_BITS_GET(&queue_block.bits[index], TYPE);
 	schedule_workload_ea = queue_header.context_ea +
-			workload_id * sizeof(struct mars_workload_context);
+		workload_id * sizeof(struct mars_workload_context);
 
 	/* dma the workload context code into LS from main memory */
 	mars_dma_get_and_wait((void *)&schedule_workload,
-				schedule_workload_ea,
-				sizeof(struct mars_workload_context),
-				MARS_DMA_TAG);
+		schedule_workload_ea, sizeof(struct mars_workload_context),
+		MARS_DMA_TAG);
 
 	/* workload type specific handling */
 	switch (schedule_workload_type) {
 	case MARS_WORKLOAD_TYPE_TASK:
 		task_schedule((struct mars_task_context *)&schedule_workload,
-				(struct mars_task_args *)args);
+			(struct mars_task_args *)args);
 		break;
 	}
 
 	/* dma the workload context code into main memory from LS */
 	mars_dma_put_and_wait((void *)&schedule_workload,
-				schedule_workload_ea,
-				sizeof(struct mars_workload_context),
-				MARS_DMA_TAG);
+		schedule_workload_ea, sizeof(struct mars_workload_context),
+		MARS_DMA_TAG);
 
+	/* initialize queue block bits */
 	MARS_BITS_SET(&queue_block.bits[index], STATE,
 		MARS_WORKLOAD_STATE_READY);
 	MARS_BITS_SET(&queue_block.bits[index], PRIORITY,
@@ -213,15 +221,24 @@ int workload_schedule(uint16_t workload_
 
 int workload_wait(uint16_t workload_id)
 {
-	MARS_CHECK_RET(workload_id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(workload_id != workload_index, MARS_ERROR_PARAMS);
-
-	int block = workload_index / MARS_WORKLOAD_PER_BLOCK;
-	int index = workload_index % MARS_WORKLOAD_PER_BLOCK;
+	uint64_t block_ea;
+	int block;
+	int index;
+
+	/* check function params */
+	if (workload_id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+	if (workload_id == workload_index)
+		return MARS_ERROR_PARAMS;
 
-	uint64_t block_ea = queue_header.queue_ea +
-			offsetof(struct mars_workload_queue, block) +
-			sizeof(struct mars_workload_queue_block) * block;
+	/* calculate block/index from id */
+	block = workload_index / MARS_WORKLOAD_PER_BLOCK;
+	index = workload_index % MARS_WORKLOAD_PER_BLOCK;
+
+	/* calculate block ea */
+	block_ea = queue_header.queue_ea +
+		offsetof(struct mars_workload_queue, block) +
+		sizeof(struct mars_workload_queue_block) * block;
 
 	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
 
@@ -243,27 +260,38 @@ int workload_wait(uint16_t workload_id)
 
 int workload_try_wait(uint16_t workload_id)
 {
-	MARS_CHECK_RET(workload_id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(workload_id != workload_index, MARS_ERROR_PARAMS);
-
-	int block = workload_id / MARS_WORKLOAD_PER_BLOCK;
-	int index = workload_id % MARS_WORKLOAD_PER_BLOCK;
+	uint64_t block_ea;
+	int block;
+	int index;
+
+	/* check function params */
+	if (workload_id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+	if (workload_id == workload_index)
+		return MARS_ERROR_PARAMS;
 
-	uint64_t block_ea = queue_header.queue_ea +
-			offsetof(struct mars_workload_queue, block) +
-			sizeof(struct mars_workload_queue_block) * block;
+	/* calculate block/index from id */
+	block = workload_id / MARS_WORKLOAD_PER_BLOCK;
+	index = workload_id % MARS_WORKLOAD_PER_BLOCK;
+
+	/* calculate block ea */
+	block_ea = queue_header.queue_ea +
+		offsetof(struct mars_workload_queue, block) +
+		sizeof(struct mars_workload_queue_block) * block;
 
 	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(&queue_block.bits[index], STATE) !=
-			MARS_WORKLOAD_STATE_NONE,
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue_block.bits[index], STATE) ==
+		MARS_WORKLOAD_STATE_NONE) {
 		mars_mutex_unlock_put(block_ea,
-			(struct mars_mutex *)&queue_block),
-		MARS_ERROR_STATE);
+			(struct mars_mutex *)&queue_block);
+		return MARS_ERROR_STATE;
+	}
 
 	mars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);
 
+	/* check if workload is finished */
 	if (MARS_BITS_GET(&queue_block.bits[index], STATE) !=
 		MARS_WORKLOAD_STATE_FINISHED)
 		return MARS_ERROR_BUSY;
@@ -273,15 +301,24 @@ int workload_try_wait(uint16_t workload_
 
 int workload_signal_send(uint16_t workload_id)
 {
-	MARS_CHECK_RET(workload_id < MARS_WORKLOAD_MAX, MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(workload_id != workload_index, MARS_ERROR_PARAMS);
-
-	int block = workload_id / MARS_WORKLOAD_PER_BLOCK;
-	int index = workload_id % MARS_WORKLOAD_PER_BLOCK;
+	uint64_t block_ea;
+	int block;
+	int index;
+
+	/* check function params */
+	if (workload_id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+	if (workload_id == workload_index)
+		return MARS_ERROR_PARAMS;
 
-	uint64_t block_ea = queue_header.queue_ea +
-			offsetof(struct mars_workload_queue, block) +
-			sizeof(struct mars_workload_queue_block) * block;
+	/* calculate block/index from id */
+	block = workload_id / MARS_WORKLOAD_PER_BLOCK;
+	index = workload_id % MARS_WORKLOAD_PER_BLOCK;
+
+	/* calculate block ea */
+	block_ea = queue_header.queue_ea +
+		offsetof(struct mars_workload_queue, block) +
+		sizeof(struct mars_workload_queue_block) * block;
 
 	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
 
@@ -321,21 +358,34 @@ void workload_signal_wait(void)
 
 int workload_signal_try_wait(void)
 {
-	int block = workload_index / MARS_WORKLOAD_PER_BLOCK;
-	int index = workload_index % MARS_WORKLOAD_PER_BLOCK;
-
-	uint64_t block_ea = queue_header.queue_ea +
-			offsetof(struct mars_workload_queue, block) +
-			sizeof(struct mars_workload_queue_block) * block;
+	uint64_t block_ea;
+	int block;
+	int index;
+
+	/* check function params */
+	if (workload_index >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+	if (workload_index == workload_index)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = workload_index / MARS_WORKLOAD_PER_BLOCK;
+	index = workload_index % MARS_WORKLOAD_PER_BLOCK;
+
+	/* calculate block ea */
+	block_ea = queue_header.queue_ea +
+		offsetof(struct mars_workload_queue, block) +
+		sizeof(struct mars_workload_queue_block) * block;
 
 	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
 
-	MARS_CHECK_CLEANUP_RET(
-		MARS_BITS_GET(&queue_block.bits[index], STATE) !=
-			MARS_WORKLOAD_STATE_NONE,
+	/* check for valid state */
+	if (MARS_BITS_GET(&queue_block.bits[index], STATE) ==
+		MARS_WORKLOAD_STATE_NONE) {
 		mars_mutex_unlock_put(block_ea,
-			(struct mars_mutex *)&queue_block),
-		MARS_ERROR_STATE);
+			(struct mars_mutex *)&queue_block);
+		return MARS_ERROR_STATE;
+	}
 
 	mars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);
 
--- a/src/mpu/lib/Makefile.am
+++ b/src/mpu/lib/Makefile.am
@@ -72,8 +72,7 @@ pkginclude_HEADERS = \
 	$(srcdir)/../../../include/mpu/mars/mars_task_signal.h
 
 EXTRA_DIST = \
-	$(srcdir)/../../../include/mpu/mars/mars_dma.h \
-	$(srcdir)/../../../include/mpu/mars/mars_timer.h
+	$(srcdir)/../../../include/mpu/mars/mars_dma.h
 
 AM_CPPFLAGS = \
 	$(extra_cppflags) \
--- a/src/mpu/lib/mars_mutex.c
+++ b/src/mpu/lib/mars_mutex.c
@@ -40,7 +40,6 @@
 #include "mars/mars_mutex.h"
 #include "mars/mars_dma.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 static struct mars_mutex mutex;
 
@@ -56,15 +55,18 @@ int mars_mutex_unlock(uint64_t mutex_ea)
 
 int mars_mutex_lock_get(uint64_t mutex_ea, struct mars_mutex *mutex)
 {
-	MARS_CHECK_RET(mutex_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET(mutex, MARS_ERROR_NULL);
-	MARS_CHECK_RET((mutex_ea & MARS_MUTEX_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
 	int status, mask;
 
+	/* check function params */
+	if (!mutex_ea)
+		return MARS_ERROR_NULL;
+	if (!mutex)
+		return MARS_ERROR_NULL;
+	if (mutex_ea & MARS_MUTEX_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if ((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+
 	/* save event mask */
 	mask = spu_read_event_mask();
 
@@ -97,13 +99,17 @@ int mars_mutex_lock_get(uint64_t mutex_e
 
 int mars_mutex_unlock_put(uint64_t mutex_ea, struct mars_mutex *mutex)
 {
-	MARS_CHECK_RET(mutex_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET(mutex, MARS_ERROR_NULL);
-	MARS_CHECK_RET((mutex_ea & MARS_MUTEX_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(mutex->lock == MARS_MUTEX_LOCKED, MARS_ERROR_STATE);
+	/* check function params */
+	if (!mutex_ea)
+		return MARS_ERROR_NULL;
+	if (!mutex)
+		return MARS_ERROR_NULL;
+	if (mutex_ea & MARS_MUTEX_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if ((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if (mutex->lock != MARS_MUTEX_LOCKED)
+		return MARS_ERROR_STATE;
 
 	mutex->lock = MARS_MUTEX_UNLOCKED;
 
--- a/src/mpu/lib/mars_task.c
+++ b/src/mpu/lib/mars_task.c
@@ -39,7 +39,6 @@
 #include "mars/mars_task_types.h"
 #include "mars/mars_syscalls.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 void mars_task_exit(int32_t exit_code)
 {
@@ -57,11 +56,12 @@ int mars_task_yield(void)
 {
 	struct mars_task_context *task;
 
+	/* get task context */
 	task = (struct mars_task_context *)mars_get_workload();
 
 	/* make sure task context has a context save area */
-	MARS_CHECK_RET(task->context_save_size && task->context_save_ea,
-			MARS_ERROR_FORMAT);
+	if (!task->context_save_size || !task->context_save_ea)
+		return MARS_ERROR_FORMAT;
 
 	mars_yield();
 
@@ -71,26 +71,32 @@ int mars_task_yield(void)
 int mars_task_schedule(struct mars_task_id *id, struct mars_task_args *args,
 			uint8_t priority)
 {
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
+	/* check function params */
+	if (!id)
+		return MARS_ERROR_NULL;
 
 	return mars_schedule(id->workload_id, args, priority);
 }
 
 int mars_task_wait(struct mars_task_id *id, int32_t *exit_code)
 {
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
-
 	int ret;
 	struct mars_task_context *task;
 
+	/* check function params */
+	if (!id)
+		return MARS_ERROR_NULL;
+
+	/* get task context */
 	task = (struct mars_task_context *)mars_get_workload();
 
 	/* make sure task context has a context save area */
-	MARS_CHECK_RET(task->context_save_size && task->context_save_ea,
-			MARS_ERROR_FORMAT);
+	if (!task->context_save_size || !task->context_save_ea)
+		return MARS_ERROR_FORMAT;
 
 	ret = mars_wait(id->workload_id);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	mars_signal_wait();
 
@@ -98,7 +104,8 @@ int mars_task_wait(struct mars_task_id *
 	if (exit_code) {
 		task = (struct mars_task_context *)
 			mars_get_workload_by_id(id->workload_id);
-		MARS_CHECK_RET(task, MARS_ERROR_INTERNAL);
+		if (!task)
+			return MARS_ERROR_INTERNAL;
 
 		*exit_code = task->exit_code;
 	}
@@ -108,19 +115,23 @@ int mars_task_wait(struct mars_task_id *
 
 int mars_task_try_wait(struct mars_task_id *id, int32_t *exit_code)
 {
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
-
 	int ret;
 	struct mars_task_context *task;
 
+	/* check function params */
+	if (!id)
+		return MARS_ERROR_NULL;
+
 	ret = mars_try_wait(id->workload_id);
-	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+	if (ret != MARS_SUCCESS)
+		return ret;
 
 	/* exit code requested so get it from the task context and return it */
 	if (exit_code) {
 		task = (struct mars_task_context *)
 			mars_get_workload_by_id(id->workload_id);
-		MARS_CHECK_RET(task, MARS_ERROR_INTERNAL);
+		if (!task)
+			return MARS_ERROR_INTERNAL;
 
 		*exit_code = task->exit_code;
 	}
--- a/src/mpu/lib/mars_task_barrier.c
+++ b/src/mpu/lib/mars_task_barrier.c
@@ -40,24 +40,26 @@
 #include "mars/mars_syscalls.h"
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 static struct mars_task_barrier barrier;
 
 int mars_task_barrier_notify(uint64_t barrier_ea)
 {
-	MARS_CHECK_RET(barrier_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((barrier_ea & MARS_TASK_BARRIER_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
 	int i;
 	struct mars_task_context *task;
 
+	/* check function params */
+	if (!barrier_ea)
+		return MARS_ERROR_NULL;
+	if (barrier_ea & MARS_TASK_BARRIER_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+
+	/* get task context */
 	task = (struct mars_task_context *)mars_get_workload();
 
 	/* make sure task context has a context save area */
-	MARS_CHECK_RET(task->context_save_size && task->context_save_ea,
-			MARS_ERROR_FORMAT);
+	if (!task->context_save_size || !task->context_save_ea)
+		return MARS_ERROR_FORMAT;
 
 	mars_mutex_lock_get(barrier_ea, (struct mars_mutex *)&barrier);
 
@@ -69,7 +71,7 @@ int mars_task_barrier_notify(uint64_t ba
 		barrier.notify_wait_count++;
 
 		mars_mutex_unlock_put(barrier_ea,
-				(struct mars_mutex *)&barrier);
+			(struct mars_mutex *)&barrier);
 
 		/* wait for signal */
 		mars_signal_wait();
@@ -95,18 +97,20 @@ int mars_task_barrier_notify(uint64_t ba
 
 int mars_task_barrier_try_notify(uint64_t barrier_ea)
 {
-	MARS_CHECK_RET(barrier_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((barrier_ea & MARS_TASK_BARRIER_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
 	int i;
 
+	/* check function params */
+	if (!barrier_ea)
+		return MARS_ERROR_NULL;
+	if (barrier_ea & MARS_TASK_BARRIER_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+
 	mars_mutex_lock_get(barrier_ea, (struct mars_mutex *)&barrier);
 
 	/* previous barrier wait not complete so return busy */
 	if (barrier.notified_count == barrier.total) {
 		mars_mutex_unlock_put(barrier_ea,
-				(struct mars_mutex *)&barrier);
+			(struct mars_mutex *)&barrier);
 		return MARS_ERROR_BUSY;
 	}
 
@@ -128,26 +132,30 @@ int mars_task_barrier_try_notify(uint64_
 
 int mars_task_barrier_wait(uint64_t barrier_ea)
 {
-	MARS_CHECK_RET(barrier_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((barrier_ea & MARS_TASK_BARRIER_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
 	int i;
 	struct mars_task_context *task;
 
+	/* check function params */
+	if (!barrier_ea)
+		return MARS_ERROR_NULL;
+	if (barrier_ea & MARS_TASK_BARRIER_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+
+	/* get task context */
 	task = (struct mars_task_context *)mars_get_workload();
 
 	/* make sure task context has a context save area */
-	MARS_CHECK_RET(task->context_save_size && task->context_save_ea,
-			MARS_ERROR_FORMAT);
+	if (!task->context_save_size || !task->context_save_ea)
+		return MARS_ERROR_FORMAT;
 
 	mars_mutex_lock_get(barrier_ea, (struct mars_mutex *)&barrier);
 
 	/* check if barrier wait limit reached */
-	MARS_CHECK_CLEANUP_RET(barrier.wait_count < barrier.total,
+	if (barrier.wait_count == barrier.total) {
 		mars_mutex_unlock_put(barrier_ea,
-				(struct mars_mutex *)&barrier),
-		MARS_ERROR_LIMIT);
+			(struct mars_mutex *)&barrier);
+		return MARS_ERROR_LIMIT;
+	}
 
 	/* not all tasks notified barrier so need to wait */
 	if (barrier.notified_count != barrier.total) {
@@ -156,7 +164,7 @@ int mars_task_barrier_wait(uint64_t barr
 		barrier.wait_count++;
 
 		mars_mutex_unlock_put(barrier_ea,
-				(struct mars_mutex *)&barrier);
+			(struct mars_mutex *)&barrier);
 
 		/* wait for signal */
 		mars_signal_wait();
@@ -185,18 +193,20 @@ int mars_task_barrier_wait(uint64_t barr
 
 int mars_task_barrier_try_wait(uint64_t barrier_ea)
 {
-	MARS_CHECK_RET(barrier_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((barrier_ea & MARS_TASK_BARRIER_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
 	int i;
 
+	/* check function params */
+	if (!barrier_ea)
+		return MARS_ERROR_NULL;
+	if (barrier_ea & MARS_TASK_BARRIER_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+
 	mars_mutex_lock_get(barrier_ea, (struct mars_mutex *)&barrier);
 
 	/* not all tasks notified barrier so return busy */
 	if (barrier.notified_count != barrier.total) {
 		mars_mutex_unlock_put(barrier_ea,
-				(struct mars_mutex *)&barrier);
+			(struct mars_mutex *)&barrier);
 		return MARS_ERROR_BUSY;
 	}
 
--- a/src/mpu/lib/mars_task_event_flag.c
+++ b/src/mpu/lib/mars_task_event_flag.c
@@ -42,15 +42,16 @@
 #include "mars/mars_syscalls.h"
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 static struct mars_task_event_flag event_flag;
 
 int mars_task_event_flag_clear(uint64_t event_flag_ea, uint32_t bits)
 {
-	MARS_CHECK_RET(event_flag_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((event_flag_ea & MARS_TASK_EVENT_FLAG_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
+	/* check function params */
+	if (!event_flag_ea)
+		return MARS_ERROR_NULL;
+	if (event_flag_ea & MARS_TASK_EVENT_FLAG_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
 
 	mars_mutex_lock_get(event_flag_ea, (struct mars_mutex *)&event_flag);
 
@@ -64,21 +65,23 @@ int mars_task_event_flag_clear(uint64_t 
 
 int mars_task_event_flag_set(uint64_t event_flag_ea, uint32_t bits)
 {
-	MARS_CHECK_RET(event_flag_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((event_flag_ea & MARS_TASK_EVENT_FLAG_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
 	int i;
 
+	/* check function params */
+	if (!event_flag_ea)
+		return MARS_ERROR_NULL;
+	if (event_flag_ea & MARS_TASK_EVENT_FLAG_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+
 	mars_mutex_lock_get(event_flag_ea, (struct mars_mutex *)&event_flag);
 
 	/* check for valid direction */
-	MARS_CHECK_CLEANUP_RET(
-		event_flag.direction == MARS_TASK_EVENT_FLAG_MPU_TO_HOST ||
-		event_flag.direction == MARS_TASK_EVENT_FLAG_MPU_TO_MPU,
+	if (event_flag.direction != MARS_TASK_EVENT_FLAG_MPU_TO_HOST &&
+		event_flag.direction != MARS_TASK_EVENT_FLAG_MPU_TO_MPU) {
 		mars_mutex_unlock_put(event_flag_ea,
-				(struct mars_mutex *)&event_flag),
-		MARS_ERROR_STATE);
+			(struct mars_mutex *)&event_flag);
+		return MARS_ERROR_STATE;
+	}
 
 	/* set the necessary bits */
 	event_flag.bits |= bits;
@@ -127,38 +130,41 @@ int mars_task_event_flag_wait(uint64_t e
 				uint32_t mask, uint8_t mask_mode,
 				uint32_t *bits)
 {
-	MARS_CHECK_RET(event_flag_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET(mask_mode == MARS_TASK_EVENT_FLAG_MASK_OR ||
-			mask_mode == MARS_TASK_EVENT_FLAG_MASK_AND,
-			MARS_ERROR_PARAMS);
-	MARS_CHECK_RET((event_flag_ea & MARS_TASK_EVENT_FLAG_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
 	int wait = 0;
 	struct mars_task_context *task;
 
+	/* check function params */
+	if (!event_flag_ea)
+		return MARS_ERROR_NULL;
+	if (event_flag_ea & MARS_TASK_EVENT_FLAG_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if (mask_mode != MARS_TASK_EVENT_FLAG_MASK_OR &&
+		mask_mode != MARS_TASK_EVENT_FLAG_MASK_AND)
+		return MARS_ERROR_PARAMS;
+
+	/* get task context */
 	task = (struct mars_task_context *)mars_get_workload();
 
 	/* make sure task context has a context save area */
-	MARS_CHECK_RET(task->context_save_size && task->context_save_ea,
-			MARS_ERROR_FORMAT);
+	if (!task->context_save_size || !task->context_save_ea)
+		return MARS_ERROR_FORMAT;
 
 	mars_mutex_lock_get(event_flag_ea, (struct mars_mutex *)&event_flag);
 
 	/* check if event flag wait limit reached */
-	MARS_CHECK_CLEANUP_RET(
-		event_flag.wait_count < MARS_TASK_EVENT_FLAG_WAIT_MAX,
+	if (event_flag.wait_count == MARS_TASK_EVENT_FLAG_WAIT_MAX) {
 		mars_mutex_unlock_put(event_flag_ea,
-				(struct mars_mutex *)&event_flag),
-		MARS_ERROR_LIMIT);
+			(struct mars_mutex *)&event_flag);
+		return MARS_ERROR_LIMIT;
+	}
 
 	/* check for valid direction */
-	MARS_CHECK_CLEANUP_RET(
-		event_flag.direction == MARS_TASK_EVENT_FLAG_HOST_TO_MPU ||
-		event_flag.direction == MARS_TASK_EVENT_FLAG_MPU_TO_MPU,
+	if (event_flag.direction != MARS_TASK_EVENT_FLAG_HOST_TO_MPU &&
+		event_flag.direction != MARS_TASK_EVENT_FLAG_MPU_TO_MPU) {
 		mars_mutex_unlock_put(event_flag_ea,
-				(struct mars_mutex *)&event_flag),
-		MARS_ERROR_STATE);
+			(struct mars_mutex *)&event_flag);
+		return MARS_ERROR_STATE;
+	}
 
 	/* check condition based on wait mode */
 	switch (mask_mode) {
@@ -209,22 +215,24 @@ int mars_task_event_flag_try_wait(uint64
 				uint32_t mask, uint8_t mask_mode,
 				uint32_t *bits)
 {
-	MARS_CHECK_RET(event_flag_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET(mask_mode == MARS_TASK_EVENT_FLAG_MASK_OR ||
-			mask_mode == MARS_TASK_EVENT_FLAG_MASK_AND,
-			MARS_ERROR_PARAMS);
-	MARS_CHECK_RET((event_flag_ea & MARS_TASK_EVENT_FLAG_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
+	/* check function params */
+	if (!event_flag_ea)
+		return MARS_ERROR_NULL;
+	if (event_flag_ea & MARS_TASK_EVENT_FLAG_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if (mask_mode != MARS_TASK_EVENT_FLAG_MASK_OR &&
+		mask_mode != MARS_TASK_EVENT_FLAG_MASK_AND)
+		return MARS_ERROR_PARAMS;
 
 	mars_mutex_lock_get(event_flag_ea, (struct mars_mutex *)&event_flag);
 
 	/* check for valid direction */
-	MARS_CHECK_CLEANUP_RET(
-		event_flag.direction == MARS_TASK_EVENT_FLAG_HOST_TO_MPU ||
-		event_flag.direction == MARS_TASK_EVENT_FLAG_MPU_TO_MPU,
+	if (event_flag.direction != MARS_TASK_EVENT_FLAG_HOST_TO_MPU &&
+		event_flag.direction != MARS_TASK_EVENT_FLAG_MPU_TO_MPU) {
 		mars_mutex_unlock_put(event_flag_ea,
-				(struct mars_mutex *)&event_flag),
-		MARS_ERROR_STATE);
+			(struct mars_mutex *)&event_flag);
+		return MARS_ERROR_STATE;
+	}
 
 	/* check condition based on wait mode */
 	switch (mask_mode) {
--- a/src/mpu/lib/mars_task_queue.c
+++ b/src/mpu/lib/mars_task_queue.c
@@ -43,16 +43,18 @@
 #include "mars/mars_dma.h"
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 static struct mars_task_queue queue;
 
 int mars_task_queue_count(uint64_t queue_ea, uint32_t *count)
 {
-	MARS_CHECK_RET(queue_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET(count, MARS_ERROR_NULL);
-	MARS_CHECK_RET((queue_ea & MARS_TASK_QUEUE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
+	/* check function params */
+	if (!queue_ea)
+		return MARS_ERROR_NULL;
+	if (!count)
+		return MARS_ERROR_NULL;
+	if (queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
 
 	mars_mutex_lock_get(queue_ea, (struct mars_mutex *)&queue);
 
@@ -66,12 +68,14 @@ int mars_task_queue_count(uint64_t queue
 
 int mars_task_queue_clear(uint64_t queue_ea)
 {
-	MARS_CHECK_RET(queue_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((queue_ea & MARS_TASK_QUEUE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
 	int i;
 
+	/* check function params */
+	if (!queue_ea)
+		return MARS_ERROR_NULL;
+	if (queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+
 	mars_mutex_lock_get(queue_ea, (struct mars_mutex *)&queue);
 
 	/* signal all waiting tasks that queue is ready for push */
@@ -118,21 +122,24 @@ static void push_update(void)
 static int push(uint64_t queue_ea, const void *data,
 		int try, int begin, uint32_t tag)
 {
-	MARS_CHECK_RET(queue_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(((uintptr_t)data & MARS_TASK_QUEUE_ENTRY_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(tag <= MARS_DMA_TAG_MAX, MARS_ERROR_PARAMS);
+	/* check function params */
+	if (!queue_ea)
+		return MARS_ERROR_NULL;
+	if (queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if ((uintptr_t)data & MARS_TASK_QUEUE_ENTRY_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if (tag > MARS_DMA_TAG_MAX)
+		return MARS_ERROR_PARAMS;
 
 	mars_mutex_lock_get(queue_ea, (struct mars_mutex *)&queue);
 
 	/* check for valid direction */
-	MARS_CHECK_CLEANUP_RET(
-		queue.direction == MARS_TASK_QUEUE_MPU_TO_HOST ||
-		queue.direction == MARS_TASK_QUEUE_MPU_TO_MPU,
-		mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue),
-		MARS_ERROR_STATE);
+	if (queue.direction != MARS_TASK_QUEUE_MPU_TO_HOST &&
+		queue.direction != MARS_TASK_QUEUE_MPU_TO_MPU) {
+		mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
+		return MARS_ERROR_STATE;
+	}
 
 	/* queue is full so wait */
 	while (queue.count == queue.depth) {
@@ -194,10 +201,13 @@ int mars_task_queue_push_begin(uint64_t 
 
 int mars_task_queue_push_end(uint64_t queue_ea, uint32_t tag)
 {
-	MARS_CHECK_RET(queue_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(tag <= MARS_DMA_TAG_MAX, MARS_ERROR_PARAMS);
+	/* check function params */
+	if (!queue_ea)
+		return MARS_ERROR_NULL;
+	if (queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if (tag > MARS_DMA_TAG_MAX)
+		return MARS_ERROR_PARAMS;
 
 	/* wait for dma completion */
 	mars_dma_wait(tag);
@@ -248,29 +258,33 @@ static void pop_update(void)
 static int pop(uint64_t queue_ea, void *data,
 		int peek, int try, int begin, uint32_t tag)
 {
-	MARS_CHECK_RET(queue_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(((uintptr_t)data & MARS_TASK_QUEUE_ENTRY_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(tag <= MARS_DMA_TAG_MAX, MARS_ERROR_PARAMS);
-
 	struct mars_task_context *task;
 
+	/* check function params */
+	if (!queue_ea)
+		return MARS_ERROR_NULL;
+	if (queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if ((uintptr_t)data & MARS_TASK_QUEUE_ENTRY_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if (tag > MARS_DMA_TAG_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* get task context */
 	task = (struct mars_task_context *)mars_get_workload();
 
 	/* make sure task context has a context save area */
-	MARS_CHECK_RET(task->context_save_size && task->context_save_ea,
-			MARS_ERROR_FORMAT);
+	if (!task->context_save_size || !task->context_save_ea)
+		return MARS_ERROR_FORMAT;
 
 	mars_mutex_lock_get(queue_ea, (struct mars_mutex *)&queue);
 
 	/* check for valid direction */
-	MARS_CHECK_CLEANUP_RET(
-		queue.direction == MARS_TASK_QUEUE_HOST_TO_MPU ||
-		queue.direction == MARS_TASK_QUEUE_MPU_TO_MPU,
-		mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue),
-		MARS_ERROR_STATE);
+	if (queue.direction != MARS_TASK_QUEUE_HOST_TO_MPU &&
+		queue.direction != MARS_TASK_QUEUE_MPU_TO_MPU) {
+		mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
+		return MARS_ERROR_STATE;
+	}
 
 	/* queue is empty so wait */
 	while (!queue.count) {
@@ -332,10 +346,13 @@ int mars_task_queue_pop_begin(uint64_t q
 
 int mars_task_queue_pop_end(uint64_t queue_ea, uint32_t tag)
 {
-	MARS_CHECK_RET(queue_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(tag <= MARS_DMA_TAG_MAX, MARS_ERROR_PARAMS);
+	/* check function params */
+	if (!queue_ea)
+		return MARS_ERROR_NULL;
+	if (queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if (tag > MARS_DMA_TAG_MAX)
+		return MARS_ERROR_PARAMS;
 
 	/* wait for dma completion */
 	mars_dma_wait(tag);
@@ -370,10 +387,13 @@ int mars_task_queue_peek_begin(uint64_t 
 
 int mars_task_queue_peek_end(uint64_t queue_ea, uint32_t tag)
 {
-	MARS_CHECK_RET(queue_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(tag <= MARS_DMA_TAG_MAX, MARS_ERROR_PARAMS);
+	/* check function params */
+	if (!queue_ea)
+		return MARS_ERROR_NULL;
+	if (queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+	if (tag > MARS_DMA_TAG_MAX)
+		return MARS_ERROR_PARAMS;
 
 	/* wait for dma completion */
 	mars_dma_wait(tag);
--- a/src/mpu/lib/mars_task_semaphore.c
+++ b/src/mpu/lib/mars_task_semaphore.c
@@ -43,32 +43,34 @@
 #include "mars/mars_syscalls.h"
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 static struct mars_task_semaphore semaphore;
 
 int mars_task_semaphore_acquire(uint64_t semaphore_ea)
 {
-	MARS_CHECK_RET(semaphore_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((semaphore_ea & MARS_TASK_SEMAPHORE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
 	struct mars_task_context *task;
 
+	/* check function params */
+	if (!semaphore_ea)
+		return MARS_ERROR_NULL;
+	if (semaphore_ea & MARS_TASK_SEMAPHORE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
+
+	/* get task context */
 	task = (struct mars_task_context *)mars_get_workload();
 
 	/* make sure task context has a context save area */
-	MARS_CHECK_RET(task->context_save_size && task->context_save_ea,
-			MARS_ERROR_FORMAT);
+	if (!task->context_save_size || !task->context_save_ea)
+		return MARS_ERROR_FORMAT;
 
 	mars_mutex_lock_get(semaphore_ea, (struct mars_mutex *)&semaphore);
 
 	/* check if semaphore wait limit reached */
-	MARS_CHECK_CLEANUP_RET(
-		semaphore.wait_count < MARS_TASK_SEMAPHORE_WAIT_MAX,
+	if (semaphore.wait_count == MARS_TASK_SEMAPHORE_WAIT_MAX) {
 		mars_mutex_unlock_put(semaphore_ea,
-				(struct mars_mutex *)&semaphore),
-		MARS_ERROR_LIMIT);
+			(struct mars_mutex *)&semaphore);
+		return MARS_ERROR_LIMIT;
+	}
 
 	if (semaphore.count <= 0) {
 		/* add id to wait list */
@@ -95,9 +97,11 @@ int mars_task_semaphore_acquire(uint64_t
 
 int mars_task_semaphore_release(uint64_t semaphore_ea)
 {
-	MARS_CHECK_RET(semaphore_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((semaphore_ea & MARS_TASK_SEMAPHORE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
+	/* check function params */
+	if (!semaphore_ea)
+		return MARS_ERROR_NULL;
+	if (semaphore_ea & MARS_TASK_SEMAPHORE_ALIGN_MASK)
+		return MARS_ERROR_ALIGN;
 
 	mars_mutex_lock_get(semaphore_ea, (struct mars_mutex *)&semaphore);
 
--- a/src/mpu/lib/mars_task_signal.c
+++ b/src/mpu/lib/mars_task_signal.c
@@ -39,11 +39,12 @@
 #include "mars/mars_task_types.h"
 #include "mars/mars_syscalls.h"
 #include "mars/mars_error.h"
-#include "mars/mars_debug.h"
 
 int mars_task_signal_send(struct mars_task_id *id)
 {
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
+	/* check function params */
+	if (!id)
+		return MARS_ERROR_NULL;
 
 	return mars_signal_send(id->workload_id);
 }
@@ -52,11 +53,12 @@ int mars_task_signal_wait(void)
 {
 	struct mars_task_context *task;
 
+	/* get task context */
 	task = (struct mars_task_context *)mars_get_workload();
 
 	/* make sure task context has a context save area */
-	MARS_CHECK_RET(task->context_save_size && task->context_save_ea,
-			MARS_ERROR_FORMAT);
+	if (!task->context_save_size || !task->context_save_ea)
+		return MARS_ERROR_FORMAT;
 
 	mars_signal_wait();
 






More information about the cbe-oss-dev mailing list