Browse Source

kernel: comply to coding guidelines MISRA C:2012 Rule 14.4

MISRA C:2012 Rule 14.4 (The controlling expression of an if statement
and the controlling expression of an iteration-statement shall have
essentially Boolean type.)

Use `bool' instead of `int' to represent Boolean values.
Use `do { ... } while (false)' instead of `do { ... } while (0)'.
Use comparisons with zero instead of implicitly testing integers.

This commit is a subset of the original commit:
5d02614e34

Signed-off-by: Simon Hein <SHein@baumer.com>
pull/48120/head
Simon Hein 3 years ago committed by Anas Nashif
parent
commit
02cfbfea51
  1. 8
      kernel/include/kswap.h
  2. 2
      kernel/mmu.c
  3. 4
      kernel/sched.c
  4. 2
      kernel/smp.c
  5. 2
      kernel/timer.c

8
kernel/include/kswap.h

@ -60,7 +60,7 @@ static inline void wait_for_switch(struct k_thread *thread) @@ -60,7 +60,7 @@ static inline void wait_for_switch(struct k_thread *thread)
*/
static ALWAYS_INLINE unsigned int do_swap(unsigned int key,
struct k_spinlock *lock,
int is_spinlock)
bool is_spinlock)
{
ARG_UNUSED(lock);
struct k_thread *new_thread, *old_thread;
@ -161,17 +161,17 @@ static ALWAYS_INLINE unsigned int do_swap(unsigned int key, @@ -161,17 +161,17 @@ static ALWAYS_INLINE unsigned int do_swap(unsigned int key,
static inline int z_swap_irqlock(unsigned int key)
{
return do_swap(key, NULL, 0);
return do_swap(key, NULL, false);
}
static inline int z_swap(struct k_spinlock *lock, k_spinlock_key_t key)
{
return do_swap(key.key, lock, 1);
return do_swap(key.key, lock, true);
}
static inline void z_swap_unlocked(void)
{
(void) do_swap(arch_irq_lock(), NULL, 1);
(void) do_swap(arch_irq_lock(), NULL, true);
}
#else /* !CONFIG_USE_SWITCH */

2
kernel/mmu.c

@ -69,7 +69,7 @@ static bool page_frames_initialized; @@ -69,7 +69,7 @@ static bool page_frames_initialized;
#define COLOR(x) printk(_CONCAT(ANSI_, x))
#else
#define COLOR(x) do { } while (0)
#define COLOR(x) do { } while (false)
#endif
/* LCOV_EXCL_START */

4
kernel/sched.c

@ -354,8 +354,8 @@ static ALWAYS_INLINE struct k_thread *next_up(void) @@ -354,8 +354,8 @@ static ALWAYS_INLINE struct k_thread *next_up(void)
end_thread(_current);
}
int queued = z_is_thread_queued(_current);
int active = !z_is_thread_prevented_from_running(_current);
bool queued = z_is_thread_queued(_current);
bool active = !z_is_thread_prevented_from_running(_current);
if (thread == NULL) {
thread = _current_cpu->idle_thread;

2
kernel/smp.c

@ -28,7 +28,7 @@ unsigned int z_smp_global_lock(void) @@ -28,7 +28,7 @@ unsigned int z_smp_global_lock(void)
void z_smp_global_unlock(unsigned int key)
{
if (_current->base.global_lock_count) {
if (_current->base.global_lock_count != 0U) {
_current->base.global_lock_count--;
if (!_current->base.global_lock_count) {

2
kernel/timer.c

@ -161,7 +161,7 @@ void z_impl_k_timer_stop(struct k_timer *timer) @@ -161,7 +161,7 @@ void z_impl_k_timer_stop(struct k_timer *timer)
{
SYS_PORT_TRACING_OBJ_FUNC(k_timer, stop, timer);
int inactive = z_abort_timeout(&timer->timeout) != 0;
bool inactive = (z_abort_timeout(&timer->timeout) != 0);
if (inactive) {
return;

Loading…
Cancel
Save