From b5522fffbc9104438ca64c139f93ebdea1150c47 Mon Sep 17 00:00:00 2001 From: Simon Hein Date: Tue, 19 Jul 2022 22:04:49 +0200 Subject: [PATCH] arch: 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 `do { ... } while (false)' instead of `do { ... } while (0)'. Use comparisons with zero instead of implicitly testing integers. Use comparisons with NULL instead of implicitly testing pointers. Use comparisons with NUL instead of implicitly testing plain chars. This commit is a subset of the original auditable-branch commit: 5d02614e34a86b549c7707d3d9f0984bc3a5f22a Signed-off-by: Simon Hein --- arch/arm/include/aarch32/cortex_m/tz_ns.h | 2 +- arch/nios2/include/kernel_arch_func.h | 6 +++--- arch/x86/core/acpi.c | 4 ++-- arch/x86/core/x86_mmu.c | 4 ++-- arch/x86/zefi/printf.h | 9 +++++---- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/arm/include/aarch32/cortex_m/tz_ns.h b/arch/arm/include/aarch32/cortex_m/tz_ns.h index 2bb081e644474a..ecf928821d08fd 100644 --- a/arch/arm/include/aarch32/cortex_m/tz_ns.h +++ b/arch/arm/include/aarch32/cortex_m/tz_ns.h @@ -65,7 +65,7 @@ "pop {r0-r3}\n\t" \ load_lr "\n\t" \ ::); \ - } while (0) + } while (false) /** * @brief Macro for "sandwiching" a function call (@p name) in two other calls diff --git a/arch/nios2/include/kernel_arch_func.h b/arch/nios2/include/kernel_arch_func.h index efb3582c90bde9..2f2030c1c731cb 100644 --- a/arch/nios2/include/kernel_arch_func.h +++ b/arch/nios2/include/kernel_arch_func.h @@ -53,15 +53,15 @@ void z_irq_do_offload(void); #if ALT_CPU_ICACHE_SIZE > 0 void z_nios2_icache_flush_all(void); #else -#define z_nios2_icache_flush_all() do { } while (0) +#define z_nios2_icache_flush_all() do { } while (false) #endif #if ALT_CPU_DCACHE_SIZE > 0 void z_nios2_dcache_flush_all(void); void z_nios2_dcache_flush_no_writeback(void *start, uint32_t len); #else -#define z_nios2_dcache_flush_all() do { } while (0) -#define z_nios2_dcache_flush_no_writeback(x, y) do { } while (0) +#define z_nios2_dcache_flush_all() do { } while (false) +#define z_nios2_dcache_flush_no_writeback(x, y) do { } while (false) #endif #endif /* _ASMLANGUAGE */ diff --git a/arch/x86/core/acpi.c b/arch/x86/core/acpi.c index 2828c6fe667943..4d4fb1ffa92d64 100644 --- a/arch/x86/core/acpi.c +++ b/arch/x86/core/acpi.c @@ -149,7 +149,7 @@ void *z_acpi_find_table(uint32_t signature) return NULL; } - if (rsdp->rsdt_ptr) { + if (rsdp->rsdt_ptr != 0U) { z_phys_map((uint8_t **)&rsdt, rsdp->rsdt_ptr, sizeof(*rsdt), 0); tbl_found = false; @@ -191,7 +191,7 @@ void *z_acpi_find_table(uint32_t signature) return NULL; } - if (rsdp->xsdt_ptr) { + if (rsdp->xsdt_ptr != 0ULL) { z_phys_map((uint8_t **)&xsdt, rsdp->xsdt_ptr, sizeof(*xsdt), 0); tbl_found = false; diff --git a/arch/x86/core/x86_mmu.c b/arch/x86/core/x86_mmu.c index 8e78a375caf49e..3ef53299251e39 100644 --- a/arch/x86/core/x86_mmu.c +++ b/arch/x86/core/x86_mmu.c @@ -531,7 +531,7 @@ static inline bool is_region_page_aligned(void *addr, size_t size) #define COLOR(x) printk(_CONCAT(ANSI_, x)) #else -#define COLOR(x) do { } while (0) +#define COLOR(x) do { } while (false) #endif __pinned_func @@ -740,7 +740,7 @@ static void dump_entry(int level, void *virt, pentry_t entry) if ((entry & MMU_##bit) != 0U) { \ str_append(&pos, &sz, #bit " "); \ } \ - } while (0) + } while (false) DUMP_BIT(RW); DUMP_BIT(US); diff --git a/arch/x86/zefi/printf.h b/arch/x86/zefi/printf.h index 12e5182be21420..2f234967028320 100644 --- a/arch/x86/zefi/printf.h +++ b/arch/x86/zefi/printf.h @@ -5,6 +5,7 @@ */ #include #include +#include /* Tiny, but not-as-primitive-as-it-looks implementation of something * like s/n/printf(). Handles %d, %x, %p, %c and %s only, allows a @@ -24,7 +25,7 @@ static void (*z_putchar)(int c); static void pc(struct _pfr *r, int c) { - if (r->buf) { + if (r->buf != NULL) { if (r->idx <= r->len) { r->buf[r->idx] = c; } @@ -50,7 +51,7 @@ static void prdec(struct _pfr *r, long v) v /= 10; } - while (digs[++i]) { + while (digs[++i] != '\0') { pc(r, digs[i]); } } @@ -64,7 +65,7 @@ static void endrec(struct _pfr *r) static int vpf(struct _pfr *r, const char *f, va_list ap) { - for (/**/; *f; f++) { + for (/**/; *f != '\0'; f++) { bool islong = false; if (*f != '%') { @@ -100,7 +101,7 @@ static int vpf(struct _pfr *r, const char *f, va_list ap) case 's': { char *s = va_arg(ap, char *); - while (*s) + while (*s != '\0') pc(r, *s++); break; }