Skip to content

Commit

Permalink
kernel: Using boolean constants instead of 0 or 1
Browse files Browse the repository at this point in the history
MISRA C requires that every controlling expression of and if or while
statement have a boolean type.

Signed-off-by: Flavio Ceolin <[email protected]>
  • Loading branch information
Flavio Ceolin authored and nashif committed Sep 18, 2018
1 parent 4218d5f commit b3d9202
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 14 deletions.
3 changes: 2 additions & 1 deletion kernel/alert.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <toolchain.h>
#include <linker/sections.h>
#include <syscall_handler.h>
#include <stdbool.h>

extern struct k_alert _k_alert_list_start[];
extern struct k_alert _k_alert_list_end[];
Expand Down Expand Up @@ -48,7 +49,7 @@ void _alert_deliver(struct k_work *work)
{
struct k_alert *alert = CONTAINER_OF(work, struct k_alert, work_item);

while (1) {
while (true) {
if ((alert->handler)(alert) == 0) {
/* do nothing -- handler has processed the alert */
} else {
Expand Down
8 changes: 4 additions & 4 deletions kernel/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <drivers/system_timer.h>
#include <wait_q.h>
#include <power.h>
#include <stdbool.h>

#if defined(CONFIG_TICKLESS_IDLE)
/*
Expand All @@ -20,7 +21,7 @@
s32_t _sys_idle_threshold_ticks = CONFIG_TICKLESS_IDLE_THRESH;

#if defined(CONFIG_TICKLESS_KERNEL)
#define _must_enter_tickless_idle(ticks) (1)
#define _must_enter_tickless_idle(ticks) (true)
#else
#define _must_enter_tickless_idle(ticks) \
((ticks == K_FOREVER) || (ticks >= _sys_idle_threshold_ticks))
Expand All @@ -47,7 +48,6 @@ void __attribute__((weak)) _sys_soc_resume_from_deep_sleep(void)
{
}
#endif

/**
*
* @brief Indicate that kernel is idling in tickless mode
Expand All @@ -64,7 +64,7 @@ static void set_kernel_idle_time_in_ticks(s32_t ticks)
_kernel.idle = ticks;
}
#else
#define set_kernel_idle_time_in_ticks(x) do { } while (0)
#define set_kernel_idle_time_in_ticks(x) do { } while (false)
#endif

#ifndef CONFIG_SMP
Expand Down Expand Up @@ -175,7 +175,7 @@ void idle(void *unused1, void *unused2, void *unused3)
* busy waiting is needed to prevent lock contention. Long
* term we need to wake up idle CPUs with an IPI.
*/
while (1) {
while (true) {
k_busy_wait(100);
k_yield();
}
Expand Down
3 changes: 2 additions & 1 deletion kernel/include/kernel_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define ZEPHYR_KERNEL_INCLUDE_KERNEL_INTERNAL_H_

#include <kernel.h>
#include <stdbool.h>

#ifndef _ASMLANGUAGE

Expand Down Expand Up @@ -198,7 +199,7 @@ extern void _thread_monitor_exit(struct k_thread *thread);
#else
#define _thread_monitor_exit(thread) \
do {/* nothing */ \
} while (0)
} while (false)
#endif /* CONFIG_THREAD_MONITOR */

extern void smp_init(void);
Expand Down
3 changes: 2 additions & 1 deletion kernel/include/syscall_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <kernel.h>
#include <misc/printk.h>
#include <kernel_internal.h>
#include <stdbool.h>

extern const _k_syscall_handler_t _k_syscall_table[K_SYSCALL_LIMIT];

Expand Down Expand Up @@ -259,7 +260,7 @@ extern int z_user_string_copy(char *dst, char *src, size_t maxlen);
if (expr) { \
_arch_syscall_oops(ssf); \
} \
} while (0)
} while (false)

static inline __attribute__((warn_unused_result)) __printf_like(2, 3)
bool z_syscall_verify_msg(bool expr, const char *fmt, ...)
Expand Down
5 changes: 3 additions & 2 deletions kernel/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <entropy.h>
#include <logging/log_ctrl.h>
#include <tracing.h>
#include <stdbool.h>

/* kernel build timestamp items */
#define BUILD_TIMESTAMP "BUILD: " __DATE__ " " __TIME__
Expand All @@ -55,7 +56,7 @@ static const unsigned int boot_delay;
#endif

#if !defined(CONFIG_BOOT_BANNER)
#define PRINT_BOOT_BANNER() do { } while (0)
#define PRINT_BOOT_BANNER() do { } while (false)
#else
#define PRINT_BOOT_BANNER() printk("***** " BOOT_BANNER " *****\n")
#endif
Expand Down Expand Up @@ -493,7 +494,7 @@ FUNC_NORETURN void _Cstart(void)
bg_thread_main(NULL, NULL, NULL);

irq_lock();
while (1) {
while (true) {
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion kernel/mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <init.h>
#include <string.h>
#include <misc/__assert.h>
#include <stdbool.h>

/* Linker-defined symbols bound the static pool structs */
extern struct k_mem_pool _k_mem_pool_list_start[];
Expand Down Expand Up @@ -59,7 +60,7 @@ int k_mem_pool_alloc(struct k_mem_pool *p, struct k_mem_block *block,
end = _tick_get() + _ms_to_ticks(timeout);
}

while (1) {
while (true) {
u32_t level_num, block_num;

/* There is a "managed race" in alloc that can fail
Expand Down
4 changes: 2 additions & 2 deletions kernel/sys_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static inline void handle_timeouts(s32_t ticks)
_handle_expired_timeouts(&expired);
}
#else
#define handle_timeouts(ticks) do { } while ((0))
#define handle_timeouts(ticks) do { } while (false)
#endif

#ifdef CONFIG_TIMESLICING
Expand Down Expand Up @@ -295,7 +295,7 @@ static void handle_time_slicing(s32_t ticks)
#endif
}
#else
#define handle_time_slicing(ticks) do { } while (0)
#define handle_time_slicing(ticks) do { } while (false)
#endif

/**
Expand Down
2 changes: 1 addition & 1 deletion kernel/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ void k_thread_access_grant(struct k_thread *thread, ...)
va_list args;
va_start(args, thread);

while (1) {
while (true) {
void *object = va_arg(args, void *);
if (object == NULL) {
break;
Expand Down
3 changes: 2 additions & 1 deletion kernel/work_q.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <kernel_structs.h>
#include <wait_q.h>
#include <errno.h>
#include <stdbool.h>

static void work_q_main(void *work_q_ptr, void *p2, void *p3)
{
Expand All @@ -22,7 +23,7 @@ static void work_q_main(void *work_q_ptr, void *p2, void *p3)
ARG_UNUSED(p2);
ARG_UNUSED(p3);

while (1) {
while (true) {
struct k_work *work;
k_work_handler_t handler;

Expand Down

0 comments on commit b3d9202

Please sign in to comment.