Skip to content

Commit

Permalink
coding guidelines: partially comply with MISRA C:2012 Rule 20.7
Browse files Browse the repository at this point in the history
MISRA C:2012 Rule 20.7 (Expressions resulting from the expansion of
macro parameters shall be enclosed in parentheses.)

Where possible, change, e.g.,

 #define EXAMPLE1(h, k) (h + k)

to

 #define EXAMPLE1(h, k) ((h) + (k))

Where this is not possible and we have a macro we cannot change, e.g.,

 #define EXAMPLE2(h, k) (h * k)

change, e.g.,

  EXAMPLE2(x - y, a - b)

to

  EXAMPLE2((x - y), (a - b))

Signed-off-by: Abramo Bagnara <abramo.bagnara@bugseng.com>
  • Loading branch information
Abramo-Bagnara authored and nashif committed Dec 10, 2021
1 parent 63afaf7 commit 3c1d1a1
Show file tree
Hide file tree
Showing 46 changed files with 241 additions and 238 deletions.
4 changes: 2 additions & 2 deletions arch/x86/core/early_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* together.
*/
static mm_reg_t mmio;
#define IN(reg) (sys_read32(mmio + reg * 4) & 0xff)
#define OUT(reg, val) sys_write32((val) & 0xff, mmio + reg * 4)
#define IN(reg) (sys_read32(mmio + (reg) * 4) & 0xff)
#define OUT(reg, val) sys_write32((val) & 0xff, mmio + (reg) * 4)
#elif defined(X86_SOC_EARLY_SERIAL_MMIO8_ADDR)
/* Still other devices use a MMIO region containing packed byte
* registers
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/x86_mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ extern pentry_t z_x86_kernel_ptables[];
static inline pentry_t *z_x86_thread_page_tables_get(struct k_thread *thread)
{
#if defined(CONFIG_USERSPACE) && !defined(CONFIG_X86_COMMON_PAGE_TABLE)
if (!IS_ENABLED(CONFIG_X86_KPTI) ||
if (!(IS_ENABLED(CONFIG_X86_KPTI)) ||
(thread->base.user_options & K_USER) != 0U) {
/* If KPTI is enabled, supervisor threads always use
* the kernel's page tables and not the page tables associated
Expand Down
2 changes: 1 addition & 1 deletion drivers/interrupt_controller/intc_system_apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <irq.h>
#include <linker/sections.h>

#define IS_IOAPIC_IRQ(irq) (irq < z_loapic_irq_base())
#define IS_IOAPIC_IRQ(irq) ((irq) < z_loapic_irq_base())
#define HARDWARE_IRQ_LIMIT ((z_loapic_irq_base() + LOAPIC_IRQ_COUNT) - 1)

/**
Expand Down
2 changes: 1 addition & 1 deletion drivers/pcie/host/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ bool pcie_msi_enable(pcie_bdf_t bdf,
return false;
}

if (!msi && IS_ENABLED(CONFIG_PCIE_MSI_X)) {
if (!msi && (IS_ENABLED(CONFIG_PCIE_MSI_X))) {
enable_msix(bdf, vectors, n_vector, base, irq);
} else {
enable_msi(bdf, vectors, n_vector, base, irq);
Expand Down
2 changes: 1 addition & 1 deletion drivers/pcie/host/pcie.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool pcie_get_mbar(pcie_bdf_t bdf,
size = pcie_conf_read(bdf, reg);
pcie_conf_write(bdf, reg, (uint32_t)phys_addr);

if (IS_ENABLED(CONFIG_64BIT) && PCIE_CONF_BAR_64(phys_addr)) {
if ((IS_ENABLED(CONFIG_64BIT)) && PCIE_CONF_BAR_64(phys_addr)) {
reg++;
phys_addr |= ((uint64_t)pcie_conf_read(bdf, reg)) << 32;

Expand Down
4 changes: 2 additions & 2 deletions drivers/serial/uart_ns16550.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_PCIE), "NS16550(s) in DT need CONFIG_PCIE");
#else
#define INBYTE(x) sys_read8(x)
#define INWORD(x) sys_read32(x)
#define OUTBYTE(x, d) sys_write8(d, x)
#define OUTWORD(x, d) sys_write32(d, x)
#define OUTBYTE(x, d) sys_write8((d), (x))
#define OUTWORD(x, d) sys_write32((d), (x))
#endif /* UART_NS16550_ACCESS_IOPORT */

#ifdef CONFIG_UART_NS16550_ACCESS_WORD_ONLY
Expand Down
4 changes: 2 additions & 2 deletions drivers/timer/apic_tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void isr(const void *arg)
k_spin_unlock(&lock, key);
sys_clock_announce(ticks);

if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) {
if (!(IS_ENABLED(CONFIG_TICKLESS_KERNEL))) {
sys_clock_set_timeout(1, false);
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ int sys_clock_driver_init(const struct device *dev)
last_announce = rdtsc();
irq_enable(timer_irq());

if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) {
if (!(IS_ENABLED(CONFIG_TICKLESS_KERNEL))) {
sys_clock_set_timeout(1, false);
}

Expand Down
2 changes: 1 addition & 1 deletion include/arch/x86/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static ALWAYS_INLINE int sys_test_and_clear_bit(mem_addr_t addr,
extern unsigned char _irq_to_interrupt_vector[];

#define Z_IRQ_TO_INTERRUPT_VECTOR(irq) \
((unsigned int) _irq_to_interrupt_vector[irq])
((unsigned int) _irq_to_interrupt_vector[(irq)])


#endif /* _ASMLANGUAGE */
Expand Down
2 changes: 1 addition & 1 deletion include/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
const Z_DECL_ALIGN(struct device) \
DEVICE_NAME_GET(dev_name) __used \
__attribute__((__section__(".z_device_" #level STRINGIFY(prio)"_"))) = { \
.name = drv_name, \
.name = (drv_name), \
.config = (cfg_ptr), \
.api = (api_ptr), \
.state = &Z_DEVICE_STATE_NAME(dev_name), \
Expand Down
26 changes: 13 additions & 13 deletions include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ extern FUNC_NORETURN void k_thread_user_mode_enter(k_thread_entry_t entry,
* @param ... list of kernel object pointers
*/
#define k_thread_access_grant(thread, ...) \
FOR_EACH_FIXED_ARG(k_object_access_grant, (;), thread, __VA_ARGS__)
FOR_EACH_FIXED_ARG((k_object_access_grant), (;), (thread), __VA_ARGS__)

/**
* @brief Assign a resource memory pool to a thread
Expand Down Expand Up @@ -2398,10 +2398,10 @@ struct k_stack {

#define Z_STACK_INITIALIZER(obj, stack_buffer, stack_num_entries) \
{ \
.wait_q = Z_WAIT_Q_INIT(&obj.wait_q), \
.base = stack_buffer, \
.next = stack_buffer, \
.top = stack_buffer + stack_num_entries, \
.wait_q = Z_WAIT_Q_INIT(&(obj).wait_q), \
.base = (stack_buffer), \
.next = (stack_buffer), \
.top = (stack_buffer) + (stack_num_entries), \
}

/**
Expand Down Expand Up @@ -2509,7 +2509,7 @@ __syscall int k_stack_pop(struct k_stack *stack, stack_data_t *data,
*/
#define K_STACK_DEFINE(name, stack_num_entries) \
stack_data_t __noinit \
_k_stack_buf_##name[stack_num_entries]; \
_k_stack_buf_##name[(stack_num_entries)]; \
STRUCT_SECTION_ITERABLE(k_stack, name) = \
Z_STACK_INITIALIZER(name, _k_stack_buf_##name, \
stack_num_entries)
Expand Down Expand Up @@ -2558,7 +2558,7 @@ struct k_mutex {
*/
#define Z_MUTEX_INITIALIZER(obj) \
{ \
.wait_q = Z_WAIT_Q_INIT(&obj.wait_q), \
.wait_q = Z_WAIT_Q_INIT(&(obj).wait_q), \
.owner = NULL, \
.lock_count = 0, \
.owner_orig_prio = K_LOWEST_APPLICATION_THREAD_PRIO, \
Expand Down Expand Up @@ -2738,9 +2738,9 @@ struct k_sem {

#define Z_SEM_INITIALIZER(obj, initial_count, count_limit) \
{ \
.wait_q = Z_WAIT_Q_INIT(&obj.wait_q), \
.count = initial_count, \
.limit = count_limit, \
.wait_q = Z_WAIT_Q_INIT(&(obj).wait_q), \
.count = (initial_count), \
.limit = (count_limit), \
_POLL_EVENT_OBJ_INIT(obj) \
}

Expand Down Expand Up @@ -3507,7 +3507,7 @@ struct k_work {
};

#define Z_WORK_INITIALIZER(work_handler) { \
.handler = work_handler, \
.handler = (work_handler), \
}

/** @brief A structure used to submit work after a delay. */
Expand All @@ -3524,7 +3524,7 @@ struct k_work_delayable {

#define Z_WORK_DELAYABLE_INITIALIZER(work_handler) { \
.work = { \
.handler = work_handler, \
.handler = (work_handler), \
.flags = K_WORK_DELAYABLE, \
}, \
}
Expand Down Expand Up @@ -3858,7 +3858,7 @@ struct k_work_user {
#define Z_WORK_USER_INITIALIZER(work_handler) \
{ \
._reserved = NULL, \
.handler = work_handler, \
.handler = (work_handler), \
.flags = 0 \
}

Expand Down
4 changes: 2 additions & 2 deletions include/kernel/thread_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static inline char *z_stack_ptr_align(char *ptr)
*/
#define K_KERNEL_PINNED_STACK_ARRAY_EXTERN(sym, nmemb, size) \
extern struct z_thread_stack_element \
sym[nmemb][Z_KERNEL_STACK_LEN(size)]
sym[(nmemb)][Z_KERNEL_STACK_LEN(size)]

/**
* @def Z_KERNEL_STACK_DEFINE_IN
Expand Down Expand Up @@ -189,7 +189,7 @@ static inline char *z_stack_ptr_align(char *ptr)
#define Z_KERNEL_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, lsect) \
struct z_thread_stack_element lsect \
__aligned(Z_KERNEL_STACK_OBJ_ALIGN) \
sym[nmemb][Z_KERNEL_STACK_LEN(size)]
sym[(nmemb)][Z_KERNEL_STACK_LEN(size)]

/**
* @def K_KERNEL_STACK_DEFINE
Expand Down
20 changes: 10 additions & 10 deletions include/logging/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ extern "C" {
* @param _str Persistent, raw string.
*/
#define LOG_HEXDUMP_ERR(_data, _length, _str) \
Z_LOG_HEXDUMP(LOG_LEVEL_ERR, _data, _length, _str)
Z_LOG_HEXDUMP(LOG_LEVEL_ERR, _data, _length, (_str))

/**
* @brief Writes a WARNING level message to the log.
Expand All @@ -166,7 +166,7 @@ extern "C" {
* @param _str Persistent, raw string.
*/
#define LOG_HEXDUMP_WRN(_data, _length, _str) \
Z_LOG_HEXDUMP(LOG_LEVEL_WRN, _data, _length, _str)
Z_LOG_HEXDUMP(LOG_LEVEL_WRN, _data, _length, (_str))

/**
* @brief Writes an INFO level message to the log.
Expand All @@ -178,7 +178,7 @@ extern "C" {
* @param _str Persistent, raw string.
*/
#define LOG_HEXDUMP_INF(_data, _length, _str) \
Z_LOG_HEXDUMP(LOG_LEVEL_INF, _data, _length, _str)
Z_LOG_HEXDUMP(LOG_LEVEL_INF, _data, _length, (_str))

/**
* @brief Writes a DEBUG level message to the log.
Expand All @@ -190,7 +190,7 @@ extern "C" {
* @param _str Persistent, raw string.
*/
#define LOG_HEXDUMP_DBG(_data, _length, _str) \
Z_LOG_HEXDUMP(LOG_LEVEL_DBG, _data, _length, _str)
Z_LOG_HEXDUMP(LOG_LEVEL_DBG, _data, _length, (_str))

/**
* @brief Writes an ERROR hexdump message associated with the instance to the
Expand Down Expand Up @@ -289,7 +289,7 @@ static inline void log_printk(const char *fmt, va_list ap)
char *z_log_strdup(const char *str);
static inline char *log_strdup(const char *str)
{
if (IS_ENABLED(CONFIG_LOG_MINIMAL) || IS_ENABLED(CONFIG_LOG2)) {
if ((IS_ENABLED(CONFIG_LOG_MINIMAL)) || (IS_ENABLED(CONFIG_LOG2))) {
return (char *)str;
}

Expand Down Expand Up @@ -322,7 +322,7 @@ static inline char *log_strdup(const char *str)
__attribute__ ((section("." STRINGIFY(LOG_ITEM_CONST_DATA(_name))))) \
__attribute__((used)) = { \
.name = STRINGIFY(_name), \
.level = _level \
.level = (_level) \
}

#define _LOG_MODULE_DYNAMIC_DATA_CREATE(_name) \
Expand Down Expand Up @@ -415,19 +415,19 @@ static inline char *log_strdup(const char *str)
\
static const struct log_source_const_data * \
__log_current_const_data __unused = \
_LOG_LEVEL_RESOLVE(__VA_ARGS__) ? \
(_LOG_LEVEL_RESOLVE(__VA_ARGS__)) != 0 ? \
&LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__)) : \
NULL; \
\
static struct log_source_dynamic_data * \
__log_current_dynamic_data __unused = \
(_LOG_LEVEL_RESOLVE(__VA_ARGS__) && \
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) ? \
(((_LOG_LEVEL_RESOLVE(__VA_ARGS__)) != 0) && \
(IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING))) ? \
&LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__)) : \
NULL; \
\
static const uint32_t __log_level __unused = \
_LOG_LEVEL_RESOLVE(__VA_ARGS__)
(_LOG_LEVEL_RESOLVE(__VA_ARGS__))

/**
* @brief Macro for setting log level in the file or function where instance
Expand Down
Loading

0 comments on commit 3c1d1a1

Please sign in to comment.