Skip to content

Commit 6fdc56d

Browse files
Flavio Ceolinnashif
authored andcommitted
kernel: Using boolean types for boolean constants
Make boolean expressions use boolean types. MISRA-C rule 14.4 Signed-off-by: Flavio Ceolin <[email protected]>
1 parent 2c92411 commit 6fdc56d

File tree

19 files changed

+64
-46
lines changed

19 files changed

+64
-46
lines changed

include/arch/arc/v2/error.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <arch/arc/syscall.h>
1818
#include <arch/arc/v2/exc.h>
19+
#include <stdbool.h>
1920

2021
#ifdef __cplusplus
2122
extern "C" {
@@ -54,7 +55,7 @@ extern void _SysFatalErrorHandler(unsigned int cause, const NANO_ESF *esf);
5455
: "memory"); \
5556
CODE_UNREACHABLE; \
5657
} \
57-
} while (0)
58+
} while (false)
5859

5960
#ifdef __cplusplus
6061
}

include/arch/arm/cortex_m/error.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <arch/arm/syscall.h>
1818
#include <arch/arm/cortex_m/exc.h>
19+
#include <stdbool.h>
1920

2021
#ifdef __cplusplus
2122
extern "C" {
@@ -51,7 +52,7 @@ extern void _SysFatalErrorHandler(unsigned int reason, const NANO_ESF *esf);
5152
: [reason] "i" (reason_p), [id] "i" (_SVC_CALL_RUNTIME_EXCEPT) \
5253
: "memory"); \
5354
CODE_UNREACHABLE; \
54-
} while (0)
55+
} while (false)
5556
#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
5657
#define _ARCH_EXCEPT(reason_p) do { \
5758
__asm__ volatile ( \
@@ -63,7 +64,7 @@ extern void _SysFatalErrorHandler(unsigned int reason, const NANO_ESF *esf);
6364
: [reason] "i" (reason_p), [id] "i" (_SVC_CALL_RUNTIME_EXCEPT) \
6465
: "memory"); \
6566
CODE_UNREACHABLE; \
66-
} while (0)
67+
} while (false)
6768
#else
6869
#error Unknown ARM architecture
6970
#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */

include/arch/arm/cortex_m/irq.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <irq.h>
1818
#include <sw_isr_table.h>
19+
#include <stdbool.h>
1920

2021
#ifdef __cplusplus
2122
extern "C" {
@@ -104,7 +105,7 @@ extern void _irq_priority_set(unsigned int irq, unsigned int prio,
104105
extern void _arch_isr_direct_pm(void);
105106
#define _ARCH_ISR_DIRECT_PM() _arch_isr_direct_pm()
106107
#else
107-
#define _ARCH_ISR_DIRECT_PM() do { } while (0)
108+
#define _ARCH_ISR_DIRECT_PM() do { } while (false)
108109
#endif
109110

110111
#define _ARCH_ISR_DIRECT_HEADER() _arch_isr_direct_header()

include/arch/x86/arch.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <kernel_arch_thread.h>
2020
#include <generated_dts_board.h>
2121
#include <mmustructs.h>
22+
#include <stdbool.h>
2223

2324
#ifndef _ASMLANGUAGE
2425
#include <arch/x86/asm_inline.h>
@@ -48,8 +49,8 @@ extern "C" {
4849
void _int_latency_start(void);
4950
void _int_latency_stop(void);
5051
#else
51-
#define _int_latency_start() do { } while (0)
52-
#define _int_latency_stop() do { } while (0)
52+
#define _int_latency_start() do { } while (false)
53+
#define _int_latency_stop() do { } while (false)
5354
#endif
5455

5556
/* interrupt/exception/error related definitions */
@@ -266,7 +267,7 @@ extern unsigned char _irq_to_interrupt_vector[];
266267
extern void _arch_irq_direct_pm(void);
267268
#define _ARCH_ISR_DIRECT_PM() _arch_irq_direct_pm()
268269
#else
269-
#define _ARCH_ISR_DIRECT_PM() do { } while (0)
270+
#define _ARCH_ISR_DIRECT_PM() do { } while (false)
270271
#endif
271272

272273
#define _ARCH_ISR_DIRECT_HEADER() _arch_isr_direct_header()
@@ -624,7 +625,7 @@ extern struct task_state_segment _main_tss;
624625
: [vector] "i" (CONFIG_X86_KERNEL_OOPS_VECTOR), \
625626
[reason] "i" (reason_p)); \
626627
CODE_UNREACHABLE; \
627-
} while (0)
628+
} while (false)
628629
#endif
629630

630631
/** Dummy ESF for fatal errors that would otherwise not have an ESF */

include/debug/object_tracing_common.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
#ifndef ZEPHYR_INCLUDE_DEBUG_OBJECT_TRACING_COMMON_H_
1313
#define ZEPHYR_INCLUDE_DEBUG_OBJECT_TRACING_COMMON_H_
1414

15+
#include <stdbool.h>
16+
1517
#ifndef CONFIG_OBJECT_TRACING
1618

17-
#define SYS_TRACING_OBJ_INIT(name, obj) do { } while ((0))
18-
#define SYS_TRACING_OBJ_INIT_DLL(name, obj) do { } while ((0))
19-
#define SYS_TRACING_OBJ_REMOVE_DLL(name, obj) do { } while ((0))
19+
#define SYS_TRACING_OBJ_INIT(name, obj) do { } while (false)
20+
#define SYS_TRACING_OBJ_INIT_DLL(name, obj) do { } while (false)
21+
#define SYS_TRACING_OBJ_REMOVE_DLL(name, obj) do { } while (false)
2022

2123
#else
2224

@@ -40,7 +42,7 @@
4042
_trace_list_ ## name = obj; \
4143
irq_unlock(key); \
4244
} \
43-
while (0)
45+
while (false)
4446

4547
/**
4648
* @def SYS_TRACING_OBJ_INIT_DLL
@@ -67,7 +69,7 @@
6769
_trace_list_ ## name = obj; \
6870
irq_unlock(key); \
6971
} \
70-
while (0)
72+
while (false)
7173

7274
/**
7375
* @def SYS_TRACING_OBJ_REMOVE_DLL
@@ -95,7 +97,7 @@
9597
} \
9698
irq_unlock(key); \
9799
} \
98-
while (0)
100+
while (false)
99101

100102
#endif /*CONFIG_OBJECT_TRACING*/
101103
#endif /*ZEPHYR_INCLUDE_DEBUG_OBJECT_TRACING_COMMON_H_*/

include/drivers/system_timer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ GTEXT(_timer_int_handler)
2626
#else /* _ASMLANGUAGE */
2727

2828
#include <device.h>
29+
#include <stdbool.h>
2930

3031
extern int _sys_clock_driver_init(struct device *device);
3132

@@ -39,8 +40,8 @@ extern void sys_clock_disable(void);
3940
extern void _timer_idle_enter(s32_t ticks);
4041
extern void _timer_idle_exit(void);
4142
#else
42-
#define _timer_idle_enter(ticks) do { } while ((0))
43-
#define _timer_idle_exit() do { } while ((0))
43+
#define _timer_idle_enter(ticks) do { } while (false)
44+
#define _timer_idle_exit() do { } while (false)
4445
#endif /* CONFIG_TICKLESS_IDLE */
4546

4647
extern void _nano_sys_clock_tick_announce(s32_t ticks);

include/kernel.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#if !defined(_ASMLANGUAGE)
1717
#include <kernel_includes.h>
1818
#include <errno.h>
19+
#include <stdbool.h>
1920

2021
#ifdef __cplusplus
2122
extern "C" {
@@ -4206,9 +4207,9 @@ extern void *k_calloc(size_t nmemb, size_t size);
42064207
/* polling API - PRIVATE */
42074208

42084209
#ifdef CONFIG_POLL
4209-
#define _INIT_OBJ_POLL_EVENT(obj) do { (obj)->poll_event = NULL; } while ((0))
4210+
#define _INIT_OBJ_POLL_EVENT(obj) do { (obj)->poll_event = NULL; } while (false)
42104211
#else
4211-
#define _INIT_OBJ_POLL_EVENT(obj) do { } while ((0))
4212+
#define _INIT_OBJ_POLL_EVENT(obj) do { } while (false)
42124213
#endif
42134214

42144215
/* private - implementation data created as needed, per-type */
@@ -4563,7 +4564,7 @@ extern void _sys_power_save_idle_exit(s32_t ticks);
45634564
printk("@ %s:%d:\n", __FILE__, __LINE__); \
45644565
_NanoFatalErrorHandler(reason, &_default_esf); \
45654566
CODE_UNREACHABLE; \
4566-
} while (0)
4567+
} while (false)
45674568

45684569
#endif /* _ARCH__EXCEPT */
45694570

@@ -4605,7 +4606,7 @@ extern void _init_static_threads(void);
46054606
/**
46064607
* @internal
46074608
*/
4608-
#define _init_static_threads() do { } while ((0))
4609+
#define _init_static_threads() do { } while (false)
46094610
#endif
46104611

46114612
/**

include/logging/log_core.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <logging/log_msg.h>
1010
#include <logging/log_instance.h>
1111
#include <misc/util.h>
12+
#include <stdbool.h>
1213

1314
#ifdef __cplusplus
1415
extern "C" {
@@ -153,7 +154,7 @@ extern "C" {
153154
do { \
154155
u32_t args[] = {__LOG_ARGUMENTS(__VA_ARGS__)}; \
155156
log_n(_str, args, ARRAY_SIZE(args), _src_level); \
156-
} while (0)
157+
} while (false)
157158

158159
#define _LOG_INTERNAL_4(_src_level, _str, ...) \
159160
_LOG_INTERNAL_LONG(_src_level, _str, __VA_ARGS__)
@@ -206,7 +207,7 @@ extern "C" {
206207
/* evaluated once when log is enabled.*/ \
207208
log_printf_arg_checker(__VA_ARGS__); \
208209
} \
209-
} while (0)
210+
} while (false)
210211

211212
#define _LOG(_level, ...) \
212213
__LOG(_level, \
@@ -237,7 +238,7 @@ extern "C" {
237238
}; \
238239
log_hexdump(_str, _data, _length, src_level); \
239240
} \
240-
} while (0)
241+
} while (false)
241242

242243
#define _LOG_HEXDUMP(_level, _data, _length, _str) \
243244
__LOG_HEXDUMP(_level, \
@@ -286,7 +287,7 @@ extern "C" {
286287
LOG_FILTER_SLOT_SHIFT(_id)); \
287288
*(_filters) |= ((_filter) & LOG_FILTER_SLOT_MASK) << \
288289
LOG_FILTER_SLOT_SHIFT(_id); \
289-
} while (0)
290+
} while (false)
290291

291292
#define LOG_FILTER_AGGR_SLOT_IDX 0
292293

include/misc/__assert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ extern void posix_exit(int exit_code);
102102
(void)printk(fmt, ##__VA_ARGS__); \
103103
__ASSERT_POST; \
104104
} \
105-
} while ((0))
105+
} while (false)
106106

107107
#define __ASSERT_EVAL(expr1, expr2, test, fmt, ...) \
108108
do { \

include/misc/util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef _ASMLANGUAGE
1818

1919
#include <zephyr/types.h>
20+
#include <stdbool.h>
2021

2122
/* Helper to pass a int as a pointer or vice-versa.
2223
* Those are available for 32 bits architectures:
@@ -181,7 +182,7 @@ static inline s64_t arithmetic_shift_right(s64_t value, u8_t shift)
181182
* ENABLED: _IS_ENABLED3(_YYYY, 1, 0)
182183
* DISABLED _IS_ENABLED3(_XXXX 1, 0)
183184
*/
184-
#define _IS_ENABLED2(one_or_two_args) _IS_ENABLED3(one_or_two_args 1, 0)
185+
#define _IS_ENABLED2(one_or_two_args) _IS_ENABLED3(one_or_two_args true, false)
185186

186187
/* And our second argument is thus now cooked to be 1 in the case
187188
* where the value is defined to 1, and 0 if not:

0 commit comments

Comments
 (0)