From dbe3e7f58cc1aa0df7668d73e96e6d46dd3e9d12 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 2 Nov 2019 08:05:48 +0000 Subject: [PATCH] MISRA fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@13153 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/common/ports/ARMCMx/chcore_v7m.h | 2 +- os/nil/include/ch.h | 6 +++--- os/nil/include/chevt.h | 2 +- os/nil/include/chmsg.h | 4 ++-- os/nil/src/ch.c | 7 ++++--- os/nil/src/chevt.c | 12 ++++++------ os/oslib/include/chobjcaches.h | 4 ---- os/oslib/src/chobjcaches.c | 18 +++++++++--------- 8 files changed, 26 insertions(+), 29 deletions(-) diff --git a/os/common/ports/ARMCMx/chcore_v7m.h b/os/common/ports/ARMCMx/chcore_v7m.h index 38861220f..2c39a4f30 100644 --- a/os/common/ports/ARMCMx/chcore_v7m.h +++ b/os/common/ports/ARMCMx/chcore_v7m.h @@ -57,7 +57,7 @@ * @brief Working Areas alignment constant. * @note It is the alignment to be enforced for thread working areas. */ -#define PORT_WORKING_AREA_ALIGN (PORT_ENABLE_GUARD_PAGES == TRUE ? \ +#define PORT_WORKING_AREA_ALIGN ((PORT_ENABLE_GUARD_PAGES == TRUE) ?\ 32U : PORT_STACK_ALIGN) /** @} */ diff --git a/os/nil/include/ch.h b/os/nil/include/ch.h index bd7a2ae6b..0b8bf6795 100644 --- a/os/nil/include/ch.h +++ b/os/nil/include/ch.h @@ -467,7 +467,7 @@ struct nil_thread { /* Note, the following union contains a pointer/value while the thread is in a sleeping state or a wake-up message when the thread is made ready.*/ union { - msg_t msg; /**< @brief Wake-up message. */ + msg_t msg; /**< @brief Wake-up/exit message. */ void *p; /**< @brief Generic pointer. */ nil_system_t *nsp; /**< @brief Pointer to nil base struct. */ thread_reference_t *trp; /**< @brief Pointer to thread reference.*/ @@ -1070,7 +1070,7 @@ struct nil_system { #define chSchWakeupS(ntp, msg) do { \ chSchReadyI(ntp, msg); \ chSchRescheduleS(); \ -} while (0) +} while (false) /** * @brief Evaluates if a reschedule is required. @@ -1113,7 +1113,7 @@ struct nil_system { #define chThdResumeS(trp, msg) do { \ chThdResumeI(trp, msg); \ chSchRescheduleS(); \ -} while (0) +} while (false) /** * @brief Delays the invoking thread for the specified number of seconds. diff --git a/os/nil/include/chevt.h b/os/nil/include/chevt.h index cc7613665..d67358241 100644 --- a/os/nil/include/chevt.h +++ b/os/nil/include/chevt.h @@ -203,7 +203,7 @@ typedef void (*evhandler_t)(eventid_t id); * * @iclass */ -#define chEvtAddEventsI(events) (bool)(nil.current->epmask |= events) +#define chEvtAddEventsI(events) (nil.current->epmask |= events) /** * @brief Returns the events mask. diff --git a/os/nil/include/chmsg.h b/os/nil/include/chmsg.h index 2c4035c96..19ed088ba 100644 --- a/os/nil/include/chmsg.h +++ b/os/nil/include/chmsg.h @@ -77,9 +77,9 @@ * @sclass */ #define chMsgReleaseS(tp, msg) do { \ - chSchReadyI(tp, msg); \ + (void) chSchReadyI(tp, msg); \ chSchRescheduleS(); \ - } while (0) + } while (false) /** @} */ /*===========================================================================*/ diff --git a/os/nil/src/ch.c b/os/nil/src/ch.c index 3d0f74eb8..abeb91b9e 100644 --- a/os/nil/src/ch.c +++ b/os/nil/src/ch.c @@ -304,7 +304,7 @@ void chSysInit(void) { /* Iterates through the list of threads to be auto-started.*/ tcp = nil_thd_configs; do { - chThdCreateI(tcp); + (void) chThdCreateI(tcp); tcp++; } while (tcp->funcp != NULL); #endif @@ -737,7 +737,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout) { thread_t *chThdCreateI(const thread_config_t *tcp) { thread_t *tp; - chDbgCheck((tcp->prio < CH_CFG_MAX_THREADS) && + chDbgCheck((tcp->prio < (tprio_t)CH_CFG_MAX_THREADS) && (tcp->wbase != NULL) && MEM_IS_ALIGNED(tcp->wbase, PORT_WORKING_AREA_ALIGN) && (tcp->wend > tcp->wbase) && @@ -830,7 +830,8 @@ void chThdExit(msg_t msg) { #endif /* Going into final state with exit message stored.*/ - chSchGoSleepTimeoutS(NIL_STATE_FINAL, msg); + nil.current->u1.msg = msg; + (void) chSchGoSleepTimeoutS(NIL_STATE_FINAL, TIME_INFINITE); /* The thread never returns here.*/ chDbgAssert(false, "zombies apocalypse"); diff --git a/os/nil/src/chevt.c b/os/nil/src/chevt.c index 31a583a84..ed33af44c 100644 --- a/os/nil/src/chevt.c +++ b/os/nil/src/chevt.c @@ -237,14 +237,14 @@ eventflags_t chEvtGetAndClearFlags(event_listener_t *elp) { * @brief Adds a set of event flags directly to the specified @p thread_t. * * @param[in] tp the thread to be signaled - * @param[in] mask the event flags set to be ORed + * @param[in] events the event flags set to be ORed * * @api */ -void chEvtSignal(thread_t *tp, eventmask_t mask) { +void chEvtSignal(thread_t *tp, eventmask_t events) { chSysLock(); - chEvtSignalI(tp, mask); + chEvtSignalI(tp, events); chSchRescheduleS(); chSysUnlock(); } @@ -257,16 +257,16 @@ void chEvtSignal(thread_t *tp, eventmask_t mask) { * reschedule must not be performed in ISRs. * * @param[in] tp the thread to be signaled - * @param[in] mask the event flags set to be ORed + * @param[in] events the event flags set to be ORed * * @iclass */ -void chEvtSignalI(thread_t *tp, eventmask_t mask) { +void chEvtSignalI(thread_t *tp, eventmask_t events) { chDbgCheckClassI(); chDbgCheck(tp != NULL); - tp->epmask |= mask; + tp->epmask |= events; if ((NIL_THD_IS_WTOREVT(tp) && ((tp->epmask & tp->u1.ewmask) != (eventmask_t)0)) || (NIL_THD_IS_WTANDEVT(tp) && diff --git a/os/oslib/include/chobjcaches.h b/os/oslib/include/chobjcaches.h index 135da051d..d8051bf1d 100644 --- a/os/oslib/include/chobjcaches.h +++ b/os/oslib/include/chobjcaches.h @@ -185,10 +185,6 @@ struct ch_oc_object { * @p chCacheObjectInit() initializes it to @p NULL. */ void *dptr; - /** - * @brief Embedded data as an open array. - */ - uint8_t dbuf[]; }; /** diff --git a/os/oslib/src/chobjcaches.c b/os/oslib/src/chobjcaches.c index bbe467bcb..c8a6de7bf 100644 --- a/os/oslib/src/chobjcaches.c +++ b/os/oslib/src/chobjcaches.c @@ -167,7 +167,7 @@ static oc_object_t *lru_get_last_s(objects_cache_t *ocp) { while (true) { /* Waiting for an object buffer to become available in the LRU.*/ - chSemWaitS(&ocp->lru_sem); + (void) chSemWaitS(&ocp->lru_sem); /* Now an object buffer is in the LRU for sure, taking it from the LRU tail.*/ @@ -208,7 +208,7 @@ static oc_object_t *lru_get_last_s(objects_cache_t *ocp) { is written. It is responsibility of the write function to release the buffer.*/ objp->obj_flags = OC_FLAG_INHASH | OC_FLAG_FORGET; - ocp->writef(ocp, objp, true); + (void) ocp->writef(ocp, objp, true); /* Critical section enter again.*/ chSysLock(); @@ -231,8 +231,8 @@ static oc_object_t *lru_get_last_s(objects_cache_t *ocp) { * @param[in] objn number of elements in the objects table array * @param[in] objsz size of elements in the objects table array, the * minimum value is sizeof (oc_object_t). - * @param[in] hashp pointer to the hash objects as an array of - * @p oc_object_t + * @param[in] objvp pointer to the hash objects as an array of structures + * starting with an @p oc_object_t * @param[in] readf pointer to an object reader function * @param[in] writef pointer to an object writer function * @@ -248,8 +248,8 @@ void chCacheObjectInit(objects_cache_t *ocp, oc_writef_t writef) { chDbgCheck((ocp != NULL) && (hashp != NULL) && (objvp != NULL) && - ((hashn & (hashn - 1U)) == 0U) && - (objn > (size_t)0) && (hashn >= objn) && + ((hashn & (hashn - (ucnt_t)1)) == (ucnt_t)0) && + (objn > (ucnt_t)0) && (hashn >= objn) && (objsz >= sizeof (oc_object_t)) && ((objsz & (PORT_NATURAL_ALIGN - 1U)) == 0U)); @@ -283,9 +283,9 @@ void chCacheObjectInit(objects_cache_t *ocp, objp->obj_key = 0U; objp->obj_flags = OC_FLAG_INLRU; objp->dptr = NULL; - objvp += objsz; + objvp = (void *)((uint8_t *)objvp + objsz); objn--; - } while (objn > 0U); + } while (objn > (ucnt_t)0); } /** @@ -339,7 +339,7 @@ oc_object_t *chCacheGetObject(objects_cache_t *ocp, chDbgAssert((objp->obj_flags & OC_FLAG_INLRU) == 0U, "in LRU"); /* Waiting on the buffer semaphore.*/ - chSemWaitS(&objp->obj_sem); + (void) chSemWaitS(&objp->obj_sem); } } else {