From 8a410f6946ff9f4721b74781a91a56256b66a4df Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 6 Mar 2015 19:25:26 +0000 Subject: [PATCH] Even more MISRA. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7722 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/ports/ARMCMx/chcore_v7m.h | 2 +- os/rt/src/chheap.c | 20 ++++++++++++-------- os/rt/src/chmemcore.c | 2 ++ os/rt/src/chmempools.c | 11 +++++++---- os/rt/src/chqueues.c | 4 ---- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/os/rt/ports/ARMCMx/chcore_v7m.h b/os/rt/ports/ARMCMx/chcore_v7m.h index 58f806784..761cffea7 100644 --- a/os/rt/ports/ARMCMx/chcore_v7m.h +++ b/os/rt/ports/ARMCMx/chcore_v7m.h @@ -282,7 +282,7 @@ struct port_intctx { * by an @p port_intctx structure. */ #define PORT_SETUP_CONTEXT(tp, workspace, wsize, pf, arg) { \ - /*lint -save -e9016 -e9087 [18.4, 11.3] Normal pointers arithmetic.*/ \ + /*lint -save -e9087 [11.3] Normal pointers arithmetic.*/ \ (tp)->p_ctx.r13 = (struct port_intctx *)((uint8_t *)(workspace) + \ (size_t)(wsize) - \ sizeof(struct port_intctx)); \ diff --git a/os/rt/src/chheap.c b/os/rt/src/chheap.c index a2ed3ddb0..a2635c72d 100644 --- a/os/rt/src/chheap.c +++ b/os/rt/src/chheap.c @@ -106,12 +106,12 @@ void _heap_init(void) { * @init */ void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size) { - union heap_header *hp; + union heap_header *hp = buf; chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size)); heapp->h_provider = (memgetfunc_t)NULL; - heapp->h_free.h.u.next = hp = buf; + heapp->h_free.h.u.next = hp; heapp->h_free.h.size = 0; hp->h.u.next = NULL; hp->h.size = size - sizeof(union heap_header); @@ -141,8 +141,9 @@ void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size) { void *chHeapAlloc(memory_heap_t *heapp, size_t size) { union heap_header *qp, *hp, *fp; - if (heapp == NULL) + if (heapp == NULL) { heapp = &default_heap; + } size = MEM_ALIGN_NEXT(size); qp = &heapp->h_free; @@ -151,7 +152,7 @@ void *chHeapAlloc(memory_heap_t *heapp, size_t size) { while (qp->h.u.next != NULL) { hp = qp->h.u.next; if (hp->h.size >= size) { - if (hp->h.size < size + sizeof(union heap_header)) { + if (hp->h.size < (size + sizeof(union heap_header))) { /* Gets the whole block even if it is slightly bigger than the requested size because the fragment would be too small to be useful.*/ @@ -176,7 +177,7 @@ void *chHeapAlloc(memory_heap_t *heapp, size_t size) { /* More memory is required, tries to get it from the associated provider else fails.*/ - if (heapp->h_provider) { + if (heapp->h_provider != NULL) { hp = heapp->h_provider(size + sizeof(union heap_header)); if (hp != NULL) { hp->h.u.heap = heapp; @@ -266,10 +267,13 @@ size_t chHeapStatus(memory_heap_t *heapp, size_t *sizep) { H_LOCK(heapp); sz = 0; - for (n = 0, qp = &heapp->h_free; qp->h.u.next; n++, qp = qp->h.u.next) { - sz += qp->h.u.next->h.size; + n = 0; + qp = &heapp->h_free; + while (qp->h.u.next != NULL) { + n++; + qp = qp->h.u.next; } - if (sizep) { + if (sizep != NULL) { *sizep = sz; } H_UNLOCK(heapp); diff --git a/os/rt/src/chmemcore.c b/os/rt/src/chmemcore.c index 1529fc2cf..2932e09f9 100644 --- a/os/rt/src/chmemcore.c +++ b/os/rt/src/chmemcore.c @@ -80,8 +80,10 @@ void _core_init(void) { extern uint8_t __heap_base__[]; extern uint8_t __heap_end__[]; + /*lint -save -e9033 [10.8] Required cast operations.*/ nextmem = (uint8_t *)MEM_ALIGN_NEXT(__heap_base__); endmem = (uint8_t *)MEM_ALIGN_PREV(__heap_end__); + /*lint restore*/ #else static stkalign_t buffer[MEM_ALIGN_NEXT(CH_CFG_MEMCORE_SIZE) / MEM_ALIGN_SIZE]; diff --git a/os/rt/src/chmempools.c b/os/rt/src/chmempools.c index 43b4268b8..e5c656844 100644 --- a/os/rt/src/chmempools.c +++ b/os/rt/src/chmempools.c @@ -37,7 +37,7 @@ #include "ch.h" -#if CH_CFG_USE_MEMPOOLS || defined(__DOXYGEN__) +#if (CH_CFG_USE_MEMPOOLS == TRUE) || defined(__DOXYGEN__) /*===========================================================================*/ /* Module exported variables. */ @@ -98,7 +98,7 @@ void chPoolLoadArray(memory_pool_t *mp, void *p, size_t n) { chDbgCheck((mp != NULL) && (n != 0)); - while (n) { + while (n != 0U) { chPoolAdd(mp, p); p = (void *)(((uint8_t *)p) + mp->mp_object_size); n--; @@ -121,12 +121,15 @@ void *chPoolAllocI(memory_pool_t *mp) { chDbgCheckClassI(); chDbgCheck(mp != NULL); - if ((objp = mp->mp_next) != NULL) { + objp = mp->mp_next; + /*lint -save -e9013 [15.7] There is no else because it is not needed.*/ + if (objp != NULL) { mp->mp_next = mp->mp_next->ph_next; } else if (mp->mp_provider != NULL) { objp = mp->mp_provider(mp->mp_object_size); } + /*lint -restore*/ return objp; } @@ -192,6 +195,6 @@ void chPoolFree(memory_pool_t *mp, void *objp) { chSysUnlock(); } -#endif /* CH_CFG_USE_MEMPOOLS */ +#endif /* CH_CFG_USE_MEMPOOLS == TRUE */ /** @} */ diff --git a/os/rt/src/chqueues.c b/os/rt/src/chqueues.c index fbe05e129..33f0df32c 100644 --- a/os/rt/src/chqueues.c +++ b/os/rt/src/chqueues.c @@ -92,9 +92,7 @@ void chIQObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size, iqp->q_buffer = bp; iqp->q_rdptr = bp; iqp->q_wrptr = bp; - /*lint -save -e9016 [18.4] Normal pointers arithmetic.*/ iqp->q_top = bp + size; - /*lint -restore*/ iqp->q_notify = infy; iqp->q_link = link; } @@ -293,9 +291,7 @@ void chOQObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size, oqp->q_buffer = bp; oqp->q_rdptr = bp; oqp->q_wrptr = bp; - /*lint -save -e9016 [18.4] Normal pointers arithmetic.*/ oqp->q_top = bp + size; - /*lint -restore*/ oqp->q_notify = onfy; oqp->q_link = link; }