Even more MISRA.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7722 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2015-03-06 19:25:26 +00:00
parent 07aba437fa
commit 8a410f6946
5 changed files with 22 additions and 17 deletions

View File

@ -282,7 +282,7 @@ struct port_intctx {
* by an @p port_intctx structure. * by an @p port_intctx structure.
*/ */
#define PORT_SETUP_CONTEXT(tp, workspace, wsize, pf, arg) { \ #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) + \ (tp)->p_ctx.r13 = (struct port_intctx *)((uint8_t *)(workspace) + \
(size_t)(wsize) - \ (size_t)(wsize) - \
sizeof(struct port_intctx)); \ sizeof(struct port_intctx)); \

View File

@ -106,12 +106,12 @@ void _heap_init(void) {
* @init * @init
*/ */
void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size) { 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)); chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size));
heapp->h_provider = (memgetfunc_t)NULL; 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; heapp->h_free.h.size = 0;
hp->h.u.next = NULL; hp->h.u.next = NULL;
hp->h.size = size - sizeof(union heap_header); 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) { void *chHeapAlloc(memory_heap_t *heapp, size_t size) {
union heap_header *qp, *hp, *fp; union heap_header *qp, *hp, *fp;
if (heapp == NULL) if (heapp == NULL) {
heapp = &default_heap; heapp = &default_heap;
}
size = MEM_ALIGN_NEXT(size); size = MEM_ALIGN_NEXT(size);
qp = &heapp->h_free; qp = &heapp->h_free;
@ -151,7 +152,7 @@ void *chHeapAlloc(memory_heap_t *heapp, size_t size) {
while (qp->h.u.next != NULL) { while (qp->h.u.next != NULL) {
hp = qp->h.u.next; hp = qp->h.u.next;
if (hp->h.size >= size) { 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 /* Gets the whole block even if it is slightly bigger than the
requested size because the fragment would be too small to be requested size because the fragment would be too small to be
useful.*/ 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 /* More memory is required, tries to get it from the associated provider
else fails.*/ else fails.*/
if (heapp->h_provider) { if (heapp->h_provider != NULL) {
hp = heapp->h_provider(size + sizeof(union heap_header)); hp = heapp->h_provider(size + sizeof(union heap_header));
if (hp != NULL) { if (hp != NULL) {
hp->h.u.heap = heapp; hp->h.u.heap = heapp;
@ -266,10 +267,13 @@ size_t chHeapStatus(memory_heap_t *heapp, size_t *sizep) {
H_LOCK(heapp); H_LOCK(heapp);
sz = 0; sz = 0;
for (n = 0, qp = &heapp->h_free; qp->h.u.next; n++, qp = qp->h.u.next) { n = 0;
sz += qp->h.u.next->h.size; qp = &heapp->h_free;
while (qp->h.u.next != NULL) {
n++;
qp = qp->h.u.next;
} }
if (sizep) { if (sizep != NULL) {
*sizep = sz; *sizep = sz;
} }
H_UNLOCK(heapp); H_UNLOCK(heapp);

View File

@ -80,8 +80,10 @@ void _core_init(void) {
extern uint8_t __heap_base__[]; extern uint8_t __heap_base__[];
extern uint8_t __heap_end__[]; extern uint8_t __heap_end__[];
/*lint -save -e9033 [10.8] Required cast operations.*/
nextmem = (uint8_t *)MEM_ALIGN_NEXT(__heap_base__); nextmem = (uint8_t *)MEM_ALIGN_NEXT(__heap_base__);
endmem = (uint8_t *)MEM_ALIGN_PREV(__heap_end__); endmem = (uint8_t *)MEM_ALIGN_PREV(__heap_end__);
/*lint restore*/
#else #else
static stkalign_t buffer[MEM_ALIGN_NEXT(CH_CFG_MEMCORE_SIZE) / static stkalign_t buffer[MEM_ALIGN_NEXT(CH_CFG_MEMCORE_SIZE) /
MEM_ALIGN_SIZE]; MEM_ALIGN_SIZE];

View File

@ -37,7 +37,7 @@
#include "ch.h" #include "ch.h"
#if CH_CFG_USE_MEMPOOLS || defined(__DOXYGEN__) #if (CH_CFG_USE_MEMPOOLS == TRUE) || defined(__DOXYGEN__)
/*===========================================================================*/ /*===========================================================================*/
/* Module exported variables. */ /* Module exported variables. */
@ -98,7 +98,7 @@ void chPoolLoadArray(memory_pool_t *mp, void *p, size_t n) {
chDbgCheck((mp != NULL) && (n != 0)); chDbgCheck((mp != NULL) && (n != 0));
while (n) { while (n != 0U) {
chPoolAdd(mp, p); chPoolAdd(mp, p);
p = (void *)(((uint8_t *)p) + mp->mp_object_size); p = (void *)(((uint8_t *)p) + mp->mp_object_size);
n--; n--;
@ -121,12 +121,15 @@ void *chPoolAllocI(memory_pool_t *mp) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck(mp != NULL); 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; mp->mp_next = mp->mp_next->ph_next;
} }
else if (mp->mp_provider != NULL) { else if (mp->mp_provider != NULL) {
objp = mp->mp_provider(mp->mp_object_size); objp = mp->mp_provider(mp->mp_object_size);
} }
/*lint -restore*/
return objp; return objp;
} }
@ -192,6 +195,6 @@ void chPoolFree(memory_pool_t *mp, void *objp) {
chSysUnlock(); chSysUnlock();
} }
#endif /* CH_CFG_USE_MEMPOOLS */ #endif /* CH_CFG_USE_MEMPOOLS == TRUE */
/** @} */ /** @} */

View File

@ -92,9 +92,7 @@ void chIQObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size,
iqp->q_buffer = bp; iqp->q_buffer = bp;
iqp->q_rdptr = bp; iqp->q_rdptr = bp;
iqp->q_wrptr = bp; iqp->q_wrptr = bp;
/*lint -save -e9016 [18.4] Normal pointers arithmetic.*/
iqp->q_top = bp + size; iqp->q_top = bp + size;
/*lint -restore*/
iqp->q_notify = infy; iqp->q_notify = infy;
iqp->q_link = link; 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_buffer = bp;
oqp->q_rdptr = bp; oqp->q_rdptr = bp;
oqp->q_wrptr = bp; oqp->q_wrptr = bp;
/*lint -save -e9016 [18.4] Normal pointers arithmetic.*/
oqp->q_top = bp + size; oqp->q_top = bp + size;
/*lint -restore*/
oqp->q_notify = onfy; oqp->q_notify = onfy;
oqp->q_link = link; oqp->q_link = link;
} }