Skip to content

Commit 29155bd

Browse files
Abramo-Bagnaranashif
authored andcommitted
coding guidelines: comply with MISRA C:2012 Rule 12.1.
In particular: - added requested parentheses verifying the lack of ambiguities Signed-off-by: Abramo Bagnara <abramo.bagnara@bugseng.com>
1 parent 5b627ad commit 29155bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+256
-257
lines changed

arch/x86/core/acpi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ static void find_rsdp(void)
6262
search_length = 1024;
6363
z_phys_map((uint8_t **)&search, search_phys, search_length, 0);
6464

65-
for (size_t i = 0; i < 1024/8; i++) {
65+
for (size_t i = 0; i < (1024/8); i++) {
6666
if (search[i] == ACPI_RSDP_SIGNATURE) {
67-
rsdp_phys = search_phys + i * 8;
67+
rsdp_phys = search_phys + (i * 8);
6868
rsdp = (void *)&search[i];
6969
goto found;
7070
}
@@ -81,9 +81,9 @@ static void find_rsdp(void)
8181
z_phys_map((uint8_t **)&search, search_phys, search_length, 0);
8282

8383
rsdp_phys = 0U;
84-
for (size_t i = 0; i < 128*1024/8; i++) {
84+
for (size_t i = 0; i < ((128*1024)/8); i++) {
8585
if (search[i] == ACPI_RSDP_SIGNATURE) {
86-
rsdp_phys = search_phys + i * 8;
86+
rsdp_phys = search_phys + (i * 8);
8787
rsdp = (void *)&search[i];
8888
goto found;
8989
}
@@ -154,7 +154,7 @@ void *z_acpi_find_table(uint32_t signature)
154154
z_phys_map(&mapped_tbl, t_phys, sizeof(*t), 0);
155155
t = (void *)mapped_tbl;
156156

157-
if (t->signature == signature && check_sum(t)) {
157+
if ((t->signature == signature) && check_sum(t)) {
158158
tbl_found = true;
159159
break;
160160
}
@@ -191,7 +191,7 @@ void *z_acpi_find_table(uint32_t signature)
191191
z_phys_map(&mapped_tbl, t_phys, sizeof(*t), 0);
192192
t = (void *)mapped_tbl;
193193

194-
if (t->signature == signature && check_sum(t)) {
194+
if ((t->signature == signature) && check_sum(t)) {
195195
tbl_found = true;
196196
break;
197197
}

arch/x86/core/early_serial.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
* together.
2222
*/
2323
static mm_reg_t mmio;
24-
#define IN(reg) (sys_read32(mmio + (reg) * 4U) & 0xffU)
25-
#define OUT(reg, val) sys_write32((uint32_t)(val) & 0xffU, mmio + (reg) * 4U)
24+
#define IN(reg) (sys_read32(mmio + ((reg) * 4U)) & 0xffU)
25+
#define OUT(reg, val) sys_write32((uint32_t)(val) & 0xffU, mmio + ((reg) * 4U))
2626
#elif defined(X86_SOC_EARLY_SERIAL_MMIO8_ADDR)
2727
/* Still other devices use a MMIO region containing packed byte
2828
* registers

arch/x86/core/fatal.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool z_x86_check_stack_bounds(uintptr_t addr, size_t size, uint16_t cs)
5757
{
5858
uintptr_t start, end;
5959

60-
if (_current == NULL || arch_is_in_isr()) {
60+
if ((_current == NULL) || arch_is_in_isr()) {
6161
/* We were servicing an interrupt or in early boot environment
6262
* and are supposed to be on the interrupt stack */
6363
uint8_t cpu_id;
@@ -71,8 +71,8 @@ bool z_x86_check_stack_bounds(uintptr_t addr, size_t size, uint16_t cs)
7171
z_interrupt_stacks[cpu_id]);
7272
end = start + CONFIG_ISR_STACK_SIZE;
7373
#ifdef CONFIG_USERSPACE
74-
} else if ((cs & 0x3U) == 0U &&
75-
(_current->base.user_options & K_USER) != 0) {
74+
} else if (((cs & 0x3U) == 0U) &&
75+
((_current->base.user_options & K_USER) != 0)) {
7676
/* The low two bits of the CS register is the privilege
7777
* level. It will be 0 in supervisor mode and 3 in user mode
7878
* corresponding to ring 0 / ring 3.
@@ -90,7 +90,7 @@ bool z_x86_check_stack_bounds(uintptr_t addr, size_t size, uint16_t cs)
9090
_current->stack_info.size);
9191
}
9292

93-
return (addr <= start) || (addr + size > end);
93+
return (addr <= start) || ((addr + size) > end);
9494
}
9595
#endif
9696

@@ -307,8 +307,8 @@ static void dump_page_fault(z_arch_esf_t *esf)
307307
LOG_ERR("Linear address not present in page tables");
308308
}
309309
LOG_ERR("Access violation: %s thread not allowed to %s",
310-
(err & PF_US) != 0U ? "user" : "supervisor",
311-
(err & PF_ID) != 0U ? "execute" : ((err & PF_WR) != 0U ?
310+
((err & PF_US) != 0U) ? "user" : "supervisor",
311+
((err & PF_ID) != 0U) ? "execute" : (((err & PF_WR) != 0U) ?
312312
"write" :
313313
"read"));
314314
if ((err & PF_PK) != 0) {
@@ -415,14 +415,14 @@ void z_x86_page_fault_handler(z_arch_esf_t *esf)
415415
#ifdef CONFIG_USERSPACE
416416
for (size_t i = 0; i < ARRAY_SIZE(exceptions); i++) {
417417
#ifdef CONFIG_X86_64
418-
if ((void *)esf->rip >= exceptions[i].start &&
419-
(void *)esf->rip < exceptions[i].end) {
418+
if (((void *)esf->rip >= exceptions[i].start) &&
419+
((void *)esf->rip < exceptions[i].end)) {
420420
esf->rip = (uint64_t)(exceptions[i].fixup);
421421
return;
422422
}
423423
#else
424-
if ((void *)esf->eip >= exceptions[i].start &&
425-
(void *)esf->eip < exceptions[i].end) {
424+
if (((void *)esf->eip >= exceptions[i].start) &&
425+
((void *)esf->eip < exceptions[i].end)) {
426426
esf->eip = (unsigned int)(exceptions[i].fixup);
427427
return;
428428
}
@@ -458,8 +458,8 @@ void z_x86_do_kernel_oops(const z_arch_esf_t *esf)
458458
/* User mode is only allowed to induce oopses and stack check
459459
* failures via this software interrupt
460460
*/
461-
if ((esf->cs & 0x3U) != 0 && !(reason == (unsigned int)K_ERR_KERNEL_OOPS ||
462-
reason == (unsigned int)K_ERR_STACK_CHK_FAIL)) {
461+
if (((esf->cs & 0x3U) != 0) && !((reason == (unsigned int)K_ERR_KERNEL_OOPS) ||
462+
(reason == (unsigned int)K_ERR_STACK_CHK_FAIL))) {
463463
reason = (unsigned int)K_ERR_KERNEL_OOPS;
464464
}
465465
#endif

arch/x86/core/intel64/irq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int z_x86_allocate_vector(unsigned int priority, int prev_vector)
6262
const int end_vector = vector + (int) VECTORS_PER_PRIORITY;
6363

6464
for (; vector < end_vector; ++vector) {
65-
if (prev_vector != 1 && vector == prev_vector) {
65+
if ((prev_vector != 1) && (vector == prev_vector)) {
6666
continue;
6767
}
6868

arch/x86/core/pcie.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void pcie_mm_init(void)
3939
if (m != NULL) {
4040
size_t n = (m->sdt.length - sizeof(*m)) / sizeof(m->pci_segs[0]);
4141

42-
for (size_t i = 0; i < n && i < MAX_PCI_BUS_SEGMENTS; i++) {
42+
for (size_t i = 0; (i < n) && (i < MAX_PCI_BUS_SEGMENTS); i++) {
4343
size_t size;
4444
uintptr_t phys_addr;
4545

arch/x86/core/x86_mmu.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static inline void pentry_get(unsigned int *paging_level, pentry_t *val,
371371
for (unsigned int level = 0; level < NUM_LEVELS; level++) {
372372
pentry_t entry = get_entry(table, virt, level);
373373

374-
if ((entry & MMU_P) == 0 || is_leaf(level, entry)) {
374+
if (((entry & MMU_P) == 0) || is_leaf(level, entry)) {
375375
*val = entry;
376376
if (paging_level != NULL) {
377377
*paging_level = level;
@@ -398,7 +398,7 @@ static inline void tlb_flush_page(void *addr)
398398
__pinned_func
399399
static inline bool is_flipped_pte(pentry_t pte)
400400
{
401-
return (pte & MMU_P) == 0 && (pte & PTE_ZERO) != 0;
401+
return ((pte & MMU_P) == 0) && ((pte & PTE_ZERO) != 0);
402402
}
403403
#endif
404404

@@ -550,7 +550,7 @@ static void print_entries(pentry_t entries_array[], uint8_t *base, unsigned int
550550
if (phys == virt) {
551551
/* Identity mappings */
552552
COLOR(YELLOW);
553-
} else if (phys + Z_MEM_VM_OFFSET == virt) {
553+
} else if ((phys + Z_MEM_VM_OFFSET) == virt) {
554554
/* Permanent RAM mappings */
555555
COLOR(GREEN);
556556
} else {
@@ -638,8 +638,8 @@ static void dump_ptables(pentry_t *table, uint8_t *base, unsigned int level)
638638
pentry_t entry = table[j];
639639
pentry_t *next;
640640

641-
if ((entry & MMU_P) == 0U ||
642-
(entry & MMU_PS) != 0U) {
641+
if (((entry & MMU_P) == 0U) ||
642+
((entry & MMU_PS) != 0U)) {
643643
/* Not present or big page, skip */
644644
continue;
645645
}
@@ -788,8 +788,8 @@ static inline pentry_t pte_finalize_value(pentry_t val, bool user_table,
788788
static const uintptr_t shared_phys_addr =
789789
Z_MEM_PHYS_ADDR(POINTER_TO_UINT(&z_shared_kernel_page_start));
790790

791-
if (user_table && (val & MMU_US) == 0 && (val & MMU_P) != 0 &&
792-
get_entry_phys(val, level) != shared_phys_addr) {
791+
if (user_table && ((val & MMU_US) == 0) && ((val & MMU_P) != 0) &&
792+
(get_entry_phys(val, level) != shared_phys_addr)) {
793793
val = ~val;
794794
}
795795
#else

arch/x86/include/x86_mmu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static inline pentry_t *z_x86_thread_page_tables_get(struct k_thread *thread)
210210
{
211211
#if defined(CONFIG_USERSPACE) && !defined(CONFIG_X86_COMMON_PAGE_TABLE)
212212
if (!(IS_ENABLED(CONFIG_X86_KPTI)) ||
213-
(thread->base.user_options & K_USER) != 0U) {
213+
((thread->base.user_options & K_USER) != 0U)) {
214214
/* If KPTI is enabled, supervisor threads always use
215215
* the kernel's page tables and not the page tables associated
216216
* with their memory domain.

arch/x86/zefi/printf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ static size_t vpf(struct _pfr *r, const char *f, va_list ap)
8484
}
8585

8686
/* Ignore (but accept) field width and precision values */
87-
while (f[1] >= '0' && f[1] <= '9') {
87+
while ((f[1] >= '0') && (f[1] <= '9')) {
8888
f++;
8989
}
9090
if (f[1] == '.') {
9191
f++;
9292
}
93-
while (f[1] >= '0' && f[1] <= '9') {
93+
while ((f[1] >= '0') && (f[1] <= '9')) {
9494
f++;
9595
}
9696

@@ -129,7 +129,7 @@ static size_t vpf(struct _pfr *r, const char *f, va_list ap)
129129
if (d != 0) {
130130
sig = true;
131131
}
132-
if (sig || i == 0)
132+
if (sig || (i == 0))
133133
pc(r, "0123456789abcdef"[d]);
134134
}
135135
break;

arch/x86/zefi/zefi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void efi_putchar(int c)
3636
efibuf[n] = (uint16_t)c;
3737
++n;
3838

39-
if (c == (int)'\n' || n == PUTCHAR_BUFSZ) {
39+
if ((c == (int)'\n') || (n == PUTCHAR_BUFSZ)) {
4040
efibuf[n] = 0U;
4141
efi->ConOut->OutputString(efi->ConOut, efibuf);
4242
n = 0;
@@ -74,7 +74,7 @@ uintptr_t __abi efi_entry(void *img_handle, struct efi_system_table *sys_tab)
7474
z_putchar = efi_putchar;
7575
printf("*** Zephyr EFI Loader ***\n");
7676

77-
for (size_t i = 0; i < sizeof(zefi_zsegs)/sizeof(zefi_zsegs[0]); i++) {
77+
for (size_t i = 0; i < (sizeof(zefi_zsegs)/sizeof(zefi_zsegs[0])); i++) {
7878
uint32_t bytes = zefi_zsegs[i].sz;
7979
uint8_t *dst = (uint8_t *)zefi_zsegs[i].addr;
8080

@@ -84,7 +84,7 @@ uintptr_t __abi efi_entry(void *img_handle, struct efi_system_table *sys_tab)
8484
}
8585
}
8686

87-
for (size_t i = 0; i < sizeof(zefi_dsegs)/sizeof(zefi_dsegs[0]); i++) {
87+
for (size_t i = 0; i < (sizeof(zefi_dsegs)/sizeof(zefi_dsegs[0])); i++) {
8888
uint32_t bytes = zefi_dsegs[i].sz;
8989
uint32_t off = zefi_dsegs[i].off;
9090
uint8_t *dst = (uint8_t *)zefi_dsegs[i].addr;
@@ -104,7 +104,7 @@ uintptr_t __abi efi_entry(void *img_handle, struct efi_system_table *sys_tab)
104104
* starts, because the very first thing it does is
105105
* install its own page table that disallows writes.
106106
*/
107-
if (((uintptr_t)dst & 0xfff) == 0 && (uintptr_t)dst < 0x100000ULL) {
107+
if ((((uintptr_t)dst & 0xfff) == 0) && ((uintptr_t)dst < 0x100000ULL)) {
108108
for (int i = 0; i < 8; i++) {
109109
dst[i] = 0x90; /* 0x90 == 1-byte NOP */
110110
}

drivers/pcie/host/pcie.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ bool pcie_get_mbar(pcie_bdf_t bdf,
127127
reg++;
128128
phys_addr |= ((uint64_t)pcie_conf_read(bdf, reg)) << 32;
129129

130-
if (PCIE_CONF_BAR_ADDR(phys_addr) == PCIE_CONF_BAR_INVAL64 ||
131-
PCIE_CONF_BAR_ADDR(phys_addr) == PCIE_CONF_BAR_NONE) {
130+
if ((PCIE_CONF_BAR_ADDR(phys_addr) == PCIE_CONF_BAR_INVAL64) ||
131+
(PCIE_CONF_BAR_ADDR(phys_addr) == PCIE_CONF_BAR_NONE)) {
132132
/* Discard on invalid address */
133133
return false;
134134
}
135135

136136
pcie_conf_write(bdf, reg, 0xFFFFFFFFU);
137137
size |= ((uint64_t)pcie_conf_read(bdf, reg)) << 32;
138138
pcie_conf_write(bdf, reg, (uint32_t)((uint64_t)phys_addr >> 32));
139-
} else if (PCIE_CONF_BAR_ADDR(phys_addr) == PCIE_CONF_BAR_INVAL ||
140-
PCIE_CONF_BAR_ADDR(phys_addr) == PCIE_CONF_BAR_NONE) {
139+
} else if ((PCIE_CONF_BAR_ADDR(phys_addr) == PCIE_CONF_BAR_INVAL) ||
140+
(PCIE_CONF_BAR_ADDR(phys_addr) == PCIE_CONF_BAR_NONE)) {
141141
/* Discard on invalid address */
142142
return false;
143143
}
@@ -161,7 +161,7 @@ bool pcie_probe_mbar(pcie_bdf_t bdf,
161161
uint32_t reg;
162162

163163
for (reg = PCIE_CONF_BAR0;
164-
index > 0 && reg <= PCIE_CONF_BAR5; reg++, index--) {
164+
(index > 0) && (reg <= PCIE_CONF_BAR5); reg++, index--) {
165165
uintptr_t addr = pcie_conf_read(bdf, reg);
166166

167167
if (PCIE_CONF_BAR_MEM(addr) && PCIE_CONF_BAR_64(addr)) {
@@ -233,7 +233,7 @@ unsigned int pcie_alloc_irq(pcie_bdf_t bdf)
233233
data = pcie_conf_read(bdf, PCIE_CONF_INTR);
234234
irq = PCIE_CONF_INTR_IRQ(data);
235235

236-
if (irq == PCIE_CONF_INTR_IRQ_NONE || irq >= (unsigned int)CONFIG_MAX_IRQ_LINES ||
236+
if ((irq == PCIE_CONF_INTR_IRQ_NONE) || (irq >= (unsigned int)CONFIG_MAX_IRQ_LINES) ||
237237
irq_is_reserved(irq)) {
238238

239239
irq = irq_alloc();

0 commit comments

Comments
 (0)