More MISRA.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7726 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2015-03-07 09:25:13 +00:00
parent 4de7257482
commit 57585301af
9 changed files with 53 additions and 30 deletions

View File

@ -775,7 +775,7 @@ static inline void chSchPreemption(void) {
tprio_t p2 = currp->p_prio; tprio_t p2 = currp->p_prio;
#if CH_CFG_TIME_QUANTUM > 0 #if CH_CFG_TIME_QUANTUM > 0
if (currp->p_preempt) { if (currp->p_preempt > 0U) {
if (p1 > p2) { if (p1 > p2) {
chSchDoRescheduleAhead(); chSchDoRescheduleAhead();
} }

View File

@ -447,14 +447,19 @@ static inline void chVTDoTickI(void) {
#if CH_CFG_ST_TIMEDELTA == 0 #if CH_CFG_ST_TIMEDELTA == 0
ch.vtlist.vt_systime++; ch.vtlist.vt_systime++;
/*lint -save -e9087 -e740 [11.3, 1.3] Cast required by list handling.*/
if (&ch.vtlist != (virtual_timers_list_t *)ch.vtlist.vt_next) { if (&ch.vtlist != (virtual_timers_list_t *)ch.vtlist.vt_next) {
/*lint -restore*/
virtual_timer_t *vtp; virtual_timer_t *vtp;
--ch.vtlist.vt_next->vt_delta; --ch.vtlist.vt_next->vt_delta;
while (!(vtp = ch.vtlist.vt_next)->vt_delta) { vtp = ch.vtlist.vt_next;
while (vtp->vt_delta == 0U) {
vtfunc_t fn = vtp->vt_func; vtfunc_t fn = vtp->vt_func;
vtp->vt_func = (vtfunc_t)NULL; vtp->vt_func = NULL;
/*lint -save -e9087 -e740 [11.3, 1.3] Cast required by list handling.*/
vtp->vt_next->vt_prev = (virtual_timer_t *)&ch.vtlist; vtp->vt_next->vt_prev = (virtual_timer_t *)&ch.vtlist;
/*lint -restore*/
ch.vtlist.vt_next = vtp->vt_next; ch.vtlist.vt_next = vtp->vt_next;
chSysUnlockFromISR(); chSysUnlockFromISR();
fn(vtp->vt_par); fn(vtp->vt_par);

View File

@ -154,13 +154,17 @@ struct context {
/* Module macros. */ /* Module macros. */
/*===========================================================================*/ /*===========================================================================*/
#define APUSH(p, a) (p) -= sizeof(void *), *(void **)(p) = (void*)(a) #define APUSH(p, a) do { \
(p) -= sizeof(void *); \
*(void **)(p) = (void*)(a); \
} while (false)
/* Darwin requires the stack to be aligned to a 16-byte boundary at /* Darwin requires the stack to be aligned to a 16-byte boundary at
* the time of a call instruction (in case the called function needs * the time of a call instruction (in case the called function needs
* to save MMX registers). This aligns to 'mod' module 16, so that we'll end * to save MMX registers). This aligns to 'mod' module 16, so that we'll end
* up with the right alignment after pushing the args. */ * up with the right alignment after pushing the args. */
#define AALIGN(p, mask, mod) p = (void *)((((uintptr_t)(p) - mod) & ~mask) + mod) #define AALIGN(p, mask, mod) \
p = (void *)((((uint32_t)(p) - (uint32_t)(mod)) & ~(uint32_t)(mask)) + (uint32_t)(mod)) \
/** /**
* @brief Platform dependent part of the @p chThdCreateI() API. * @brief Platform dependent part of the @p chThdCreateI() API.
@ -168,6 +172,7 @@ struct context {
* 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 -e611 -e9033 -e9074 -e9087 [10.8, 11.1, 11.3] Valid casts.*/ \
uint8_t *esp = (uint8_t *)workspace + wsize; \ uint8_t *esp = (uint8_t *)workspace + wsize; \
APUSH(esp, 0); \ APUSH(esp, 0); \
uint8_t *savebp = esp; \ uint8_t *savebp = esp; \
@ -177,20 +182,20 @@ struct context {
APUSH(esp, 0); \ APUSH(esp, 0); \
esp -= sizeof(struct port_intctx); \ esp -= sizeof(struct port_intctx); \
((struct port_intctx *)esp)->eip = (void *)_port_thread_start; \ ((struct port_intctx *)esp)->eip = (void *)_port_thread_start; \
((struct port_intctx *)esp)->ebx = 0; \ ((struct port_intctx *)esp)->ebx = NULL; \
((struct port_intctx *)esp)->edi = 0; \ ((struct port_intctx *)esp)->edi = NULL; \
((struct port_intctx *)esp)->esi = 0; \ ((struct port_intctx *)esp)->esi = NULL; \
((struct port_intctx *)esp)->ebp = (void *)savebp; \ ((struct port_intctx *)esp)->ebp = (void *)savebp; \
(tp)->p_ctx.esp = (struct port_intctx *)esp; \ (tp)->p_ctx.esp = (struct port_intctx *)esp; \
/*lint -restore*/ \
} }
/** /**
* @brief Computes the thread working area global size. * @brief Computes the thread working area global size.
* @note There is no need to perform alignments in this macro. * @note There is no need to perform alignments in this macro.
*/ */
#define PORT_WA_SIZE(n) (sizeof(void *) * 4 + \ #define PORT_WA_SIZE(n) ((sizeof(void *) * 4U) + \
sizeof(struct port_intctx) + \ sizeof(struct port_intctx) + \
sizeof(struct port_extctx) + \
((size_t)(n)) + \ ((size_t)(n)) + \
((size_t)(PORT_INT_REQUIRED_STACK))) ((size_t)(PORT_INT_REQUIRED_STACK)))
@ -229,9 +234,11 @@ struct context {
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/*lint -save -e950 [Dir-2.1] Non-ANSI keywords are fine in the port layer.*/
__attribute__((fastcall)) void port_switch(thread_t *ntp, thread_t *otp); __attribute__((fastcall)) void port_switch(thread_t *ntp, thread_t *otp);
__attribute__((cdecl, noreturn)) void _port_thread_start(msg_t (*pf)(void *), __attribute__((cdecl, noreturn)) void _port_thread_start(msg_t (*pf)(void *p),
void *p); void *p);
/*lint -restore*/
void _sim_check_for_interrupts(void); void _sim_check_for_interrupts(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
@ -269,7 +276,7 @@ static inline syssts_t port_get_irq_status(void) {
*/ */
static inline bool port_irq_enabled(syssts_t sts) { static inline bool port_irq_enabled(syssts_t sts) {
return (sts & 1) == 0; return (sts & 1U) == 0U;
} }
/** /**
@ -290,7 +297,7 @@ static inline bool port_is_isr_context(void) {
*/ */
static inline void port_lock(void) { static inline void port_lock(void) {
asm volatile("nop"); __asm volatile ("nop");
} }
/** /**
@ -299,7 +306,7 @@ static inline void port_lock(void) {
*/ */
static inline void port_unlock(void) { static inline void port_unlock(void) {
asm volatile("nop"); __asm volatile ("nop");
} }
/** /**
@ -309,7 +316,7 @@ static inline void port_unlock(void) {
*/ */
static inline void port_lock_from_isr(void) { static inline void port_lock_from_isr(void) {
asm volatile("nop"); __asm volatile ("nop");
} }
/** /**
@ -319,7 +326,7 @@ static inline void port_lock_from_isr(void) {
*/ */
static inline void port_unlock_from_isr(void) { static inline void port_unlock_from_isr(void) {
asm volatile("nop"); __asm volatile ("nop");
} }
/** /**
@ -327,7 +334,7 @@ static inline void port_unlock_from_isr(void) {
*/ */
static inline void port_disable(void) { static inline void port_disable(void) {
asm volatile("nop"); __asm volatile ("nop");
} }
/** /**
@ -335,7 +342,7 @@ static inline void port_disable(void) {
*/ */
static inline void port_suspend(void) { static inline void port_suspend(void) {
asm volatile("nop"); __asm volatile ("nop");
} }
/** /**
@ -343,7 +350,7 @@ static inline void port_suspend(void) {
*/ */
static inline void port_enable(void) { static inline void port_enable(void) {
asm volatile("nop"); __asm volatile ("nop");
} }
/** /**

View File

@ -134,8 +134,8 @@ void *chCoreAllocI(size_t size) {
chDbgCheckClassI(); chDbgCheckClassI();
size = MEM_ALIGN_NEXT(size); size = MEM_ALIGN_NEXT(size);
/*lint -save -e946 -e947 [18.2, 18.3] Normal pointers arithmetic, it /*lint -save -e9033 -e946 -e947 [10.8, 18.2, 18.3] Normal pointers
is safe.*/ arithmetic, it is safe.*/
if ((size_t)(endmem - nextmem) < size) { if ((size_t)(endmem - nextmem) < size) {
/*lint -restore*/ /*lint -restore*/
return NULL; return NULL;
@ -155,8 +155,8 @@ void *chCoreAllocI(size_t size) {
*/ */
size_t chCoreGetStatusX(void) { size_t chCoreGetStatusX(void) {
/*lint -save -e946 -e947 [18.2, 18.3] Normal pointers arithmetic, it /*lint -save -e9033 -e946 -e947 [10.8, 18.2, 18.3] Normal pointers
is safe.*/ arithmetic, it is safe.*/
return (size_t)(endmem - nextmem); return (size_t)(endmem - nextmem);
/*lint -restore*/ /*lint -restore*/
} }

View File

@ -65,8 +65,8 @@
/*===========================================================================*/ /*===========================================================================*/
#define _offsetof(st, m) \ #define _offsetof(st, m) \
/*lint -save -e946 -e947 -e9033 -e413 [18.2, 18.3, 10.8 1.3] Normal /*lint -save -e9005 -e946 -e947 -e9033 -e413 [11.8, 18.2, 18.3, 10.8 1.3]
pointers arithmetic, it is safe.*/ \ Normal pointers arithmetic, it is safe.*/ \
((size_t)((char *)&((st *)0)->m - (char *)0)) \ ((size_t)((char *)&((st *)0)->m - (char *)0)) \
/*lint -restore*/ /*lint -restore*/

View File

@ -436,7 +436,7 @@ bool chSchIsPreemptionRequired(void) {
if the first thread on the ready queue has a higher priority. if the first thread on the ready queue has a higher priority.
Otherwise, if the running thread has used up its time quantum, reschedule Otherwise, if the running thread has used up its time quantum, reschedule
if the first thread on the ready queue has equal or higher priority.*/ if the first thread on the ready queue has equal or higher priority.*/
return currp->p_preempt ? p1 > p2 : p1 >= p2; return (currp->p_preempt > 0U) ? (p1 > p2) : (p1 >= p2);
#else #else
/* If the round robin preemption feature is not enabled then performs a /* If the round robin preemption feature is not enabled then performs a
simpler comparison.*/ simpler comparison.*/
@ -526,7 +526,7 @@ void chSchDoReschedule(void) {
#if CH_CFG_TIME_QUANTUM > 0 #if CH_CFG_TIME_QUANTUM > 0
/* If CH_CFG_TIME_QUANTUM is enabled then there are two different scenarios /* If CH_CFG_TIME_QUANTUM is enabled then there are two different scenarios
to handle on preemption: time quantum elapsed or not.*/ to handle on preemption: time quantum elapsed or not.*/
if (currp->p_preempt == 0) { if (currp->p_preempt == 0U) {
/* The thread consumed its time quantum so it is enqueued behind threads /* The thread consumed its time quantum so it is enqueued behind threads
with same priority level, however, it acquires a new time quantum.*/ with same priority level, however, it acquires a new time quantum.*/
chSchDoRescheduleBehind(); chSchDoRescheduleBehind();

View File

@ -191,9 +191,10 @@ void chSysTimerHandlerI(void) {
#if CH_CFG_TIME_QUANTUM > 0 #if CH_CFG_TIME_QUANTUM > 0
/* Running thread has not used up quantum yet? */ /* Running thread has not used up quantum yet? */
if (currp->p_preempt > 0) if (currp->p_preempt > 0U) {
/* Decrement remaining quantum.*/ /* Decrement remaining quantum.*/
currp->p_preempt--; currp->p_preempt--;
}
#endif #endif
#if CH_DBG_THREADS_PROFILING == TRUE #if CH_DBG_THREADS_PROFILING == TRUE
currp->p_time++; currp->p_time++;

View File

@ -128,7 +128,7 @@ clean:
-rm -fR .dep -rm -fR .dep
misra: misra:
lint-nt -w1 pclint/co-gcc.lnt pclint/au-misra3.lnt pclint/waivers.lnt $(INCDIR) $(KERNSRC) > misra.txt lint-nt -w3 pclint/co-gcc.lnt pclint/au-misra3.lnt pclint/waivers.lnt $(INCDIR) $(KERNSRC) > misra.txt
# #
# Include the dependency files, should be the last of the makefile # Include the dependency files, should be the last of the makefile

View File

@ -9,7 +9,9 @@
/* Silencing common non-MISRA info generated by PCLint in -w3 mode. All of /* Silencing common non-MISRA info generated by PCLint in -w3 mode. All of
them have been controlled. Other infos have been fixed in the code.*/ them have been controlled. Other infos have been fixed in the code.*/
-e526 -e537 -e714 -e716 -e757 -e759 -e768 -e773 -e826 -e835 -e845 -e526 -e537
-e714 -e716 -e717 -e757 -e758 -e759 -e768 -e773
-e826 -e830 -e835 -e845
/* Removing *advisory* directives and rules that would negatively impact /* Removing *advisory* directives and rules that would negatively impact
code readability or not avoidable.*/ code readability or not avoidable.*/
@ -30,10 +32,18 @@
-e9018 /* Rule-19.2 */ -e9018 /* Rule-19.2 */
-e9024 /* Rule-20.10 */ -e9024 /* Rule-20.10 */
/* Waiver Directive 2.1, Rule 1.1, Rule 1.2, assembler is allowed in some
modules.*/
-e950
/* Waiver Directive 4.10, PCLint is confused by the guard used in the CMSIS /* Waiver Directive 4.10, PCLint is confused by the guard used in the CMSIS
header files, the guard is present, suppressing the noise.*/ header files, the guard is present, suppressing the noise.*/
-e451 -e451
/* Waiver Rule 2.2, PCLint marks as pure functions that contain just arm
code, this does not mean that those functions do nothing.*/
-e522
/* Waiver Rule 3.1, the sequence "//" is mandated by standard license /* Waiver Rule 3.1, the sequence "//" is mandated by standard license
headers included on top of all source files. The sequence is part of the headers included on top of all source files. The sequence is part of the
license URL and cannot be removed.*/ license URL and cannot be removed.*/