Commit 5d02614e authored by Abramo Bagnara's avatar Abramo Bagnara Committed by Anas Nashif
Browse files

coding guidelines: partially comply with 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.
Use `bool' instead of `int' to represent Boolean values.
Use `while (true)' instead of `while (1)' to express infinite loops.

Signed-off-by: default avatarAbramo Bagnara <abramo.bagnara@bugseng.com>
parent 5b7cc3bf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+3 −3
Original line number Diff line number Diff line
@@ -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 */
+2 −2
Original line number Diff line number Diff line
@@ -137,7 +137,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;

@@ -174,7 +174,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;
+2 −2
Original line number Diff line number Diff line
@@ -488,7 +488,7 @@ static inline void assert_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
@@ -697,7 +697,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);
+5 −4
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 */
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>

/* 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;
		}
Loading