From d0ad1cccdf791be977a1d8cd1dd37607e717d614 Mon Sep 17 00:00:00 2001 From: Ryad Benadjila Date: Sat, 11 May 2019 20:27:42 +0200 Subject: [PATCH] [style] Protect macro + missing parentheses (MISRA style) + const and volatile missing qualifiers. --- src/default_handlers.c | 6 ++++-- src/flash_regs.h | 12 ++++++------ src/main.c | 14 +++++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/default_handlers.c b/src/default_handlers.c index 0df3075..fe1bb53 100644 --- a/src/default_handlers.c +++ b/src/default_handlers.c @@ -99,6 +99,8 @@ stack_frame_t *exti_handler(stack_frame_t * stack_frame) } } break; + default: + break; } return stack_frame; } @@ -108,8 +110,8 @@ stack_frame_t *exti_handler(stack_frame_t * stack_frame) stack_frame_t *HardFault_Handler(stack_frame_t * frame) { - uint32_t cfsr = *((uint32_t *) r_CORTEX_M_SCB_CFSR); - uint32_t hfsr = *((uint32_t *) r_CORTEX_M_SCB_HFSR); + uint32_t cfsr = *((volatile uint32_t *) r_CORTEX_M_SCB_CFSR); + uint32_t hfsr = *((volatile uint32_t *) r_CORTEX_M_SCB_HFSR); uint32_t *p; int i; #ifdef KERNEL diff --git a/src/flash_regs.h b/src/flash_regs.h index df23325..0f0aeaa 100644 --- a/src/flash_regs.h +++ b/src/flash_regs.h @@ -135,15 +135,15 @@ /* return true if the the address is in the flash memory */ #if CONFIG_USR_DRV_FLASH_1M # if CONFIG_USR_DRV_FLASH_DUAL_BANK -# define IS_IN_FLASH(addr) (addr >= FLASH_SECTOR_0) && \ - (addr <= FLASH_SECTOR_19_END) +# define IS_IN_FLASH(addr) ((addr) >= FLASH_SECTOR_0) && \ + ((addr) <= FLASH_SECTOR_19_END) # else -# define IS_IN_FLASH(addr) (addr >= FLASH_SECTOR_0) && \ - (addr <= FLASH_SECTOR_11_END) +# define IS_IN_FLASH(addr) ((addr) >= FLASH_SECTOR_0) && \ + ((addr) <= FLASH_SECTOR_11_END) # endif #elif CONFIG_USR_DRV_FLASH_2M -# define IS_IN_FLASH(addr) (addr >= FLASH_SECTOR_0) && \ - (addr <= FLASH_SECTOR_23_END) +# define IS_IN_FLASH(addr) ((addr) >= FLASH_SECTOR_0) && \ + ((addr) <= FLASH_SECTOR_23_END) #else # error "Unkown flash size!" #endif diff --git a/src/main.c b/src/main.c index 03cde07..d4af4da 100644 --- a/src/main.c +++ b/src/main.c @@ -58,7 +58,7 @@ void hexdump(const uint8_t *bin, uint32_t len) { for (uint32_t i = 0; i < len; i++) { dbg_log("%x ", bin[i]); - if (i % 16 == 0 && i != 0) { + if ((i % 16 == 0) && (i != 0)) { dbg_log("\n"); } dbg_flush(); @@ -217,7 +217,7 @@ int main(void) start = soc_dwt_getcycles() / 168000; do { stop = soc_dwt_getcycles() / 168000; - } while (stop - start < 1000); // < 1s + } while ((stop - start) < 1000); // < 1s dbg_log("."); dbg_flush(); count--; @@ -360,17 +360,17 @@ int main(void) #endif uint32_t crc = 0; /* checking CRC32 header check */ - crc = crc32((uint8_t*)fw, sizeof(t_firmware_signature) - sizeof(uint32_t) - SHA256_DIGEST_SIZE - EC_MAX_SIGLEN, 0xffffffff); + crc = crc32((const uint8_t*)fw, sizeof(t_firmware_signature) - sizeof(uint32_t) - SHA256_DIGEST_SIZE - EC_MAX_SIGLEN, 0xffffffff); crc = crc32((uint8_t*)&buf, sizeof(uint32_t), crc); - crc = crc32((uint8_t*)fw->fw_sig.hash, SHA256_DIGEST_SIZE, crc); + crc = crc32((const uint8_t*)fw->fw_sig.hash, SHA256_DIGEST_SIZE, crc); for (uint32_t i = 0; i < EC_MAX_SIGLEN; ++i) { crc = crc32((uint8_t*)&buf, sizeof(uint8_t), crc); } /* check CRC of padding (fill field) */ - crc = crc32((uint8_t*)fw->fill, SHR_SECTOR_SIZE - sizeof(t_firmware_signature), crc); + crc = crc32((const uint8_t*)fw->fill, SHR_SECTOR_SIZE - sizeof(t_firmware_signature), crc); /* check CRC of bootable flag */ - crc = crc32((uint8_t*)&fw->bootable, sizeof(uint32_t), crc); - crc = crc32((uint8_t*)&fw->fill2, SHR_SECTOR_SIZE - sizeof(uint32_t), crc); + crc = crc32((const uint8_t*)&fw->bootable, sizeof(uint32_t), crc); + crc = crc32((const uint8_t*)&fw->fill2, SHR_SECTOR_SIZE - sizeof(uint32_t), crc); /* Double check for faults */ if (crc != fw->fw_sig.crc32) {