From 56048fe215997ab6788ebd251e8cde094392dfc7 Mon Sep 17 00:00:00 2001 From: Yann Gautier Date: Fri, 18 Nov 2022 15:03:22 +0100 Subject: [PATCH] fix(st): explicitly check operators precedence This corrects the MISRA violation C2012-12.1: The precedence of operators within expressions should be made explicit. This is done either by adding parentheses, or by creating dedicated variables to ease readability. Signed-off-by: Yann Gautier Change-Id: I5e3f191ee38eca7ef634bd7542e615ab625271f6 --- plat/st/common/stm32mp_dt.c | 2 +- plat/st/stm32mp1/stm32mp1_fconf_firewall.c | 9 +++++---- plat/st/stm32mp1/stm32mp1_private.c | 12 ++++++------ plat/st/stm32mp1/stm32mp1_syscfg.c | 4 +++- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/plat/st/common/stm32mp_dt.c b/plat/st/common/stm32mp_dt.c index c9efeb533..5681fa6a7 100644 --- a/plat/st/common/stm32mp_dt.c +++ b/plat/st/common/stm32mp_dt.c @@ -416,7 +416,7 @@ int fdt_get_gpio_bank_pin_count(unsigned int bank) /* Get the last defined gpio line (offset + nb of pins) */ pin_count = fdt32_to_cpu(*(cuint + 1)) + fdt32_to_cpu(*(cuint + 3)); - for (i = 0; i < len / 4; i++) { + for (i = 0; i < (len / 4); i++) { pin_count = MAX(pin_count, (int)(fdt32_to_cpu(*(cuint + 1)) + fdt32_to_cpu(*(cuint + 3)))); cuint += 4; diff --git a/plat/st/stm32mp1/stm32mp1_fconf_firewall.c b/plat/st/stm32mp1/stm32mp1_fconf_firewall.c index f2568ab5a..7d9956409 100644 --- a/plat/st/stm32mp1/stm32mp1_fconf_firewall.c +++ b/plat/st/stm32mp1/stm32mp1_fconf_firewall.c @@ -99,15 +99,16 @@ static int fconf_populate_stm32mp1_firewall(uintptr_t config) /* Locate the memory cells and read all values */ for (i = 0U; i < (unsigned int)(len / (sizeof(uint32_t) * STM32MP_REGION_PARAMS)); i++) { + uint32_t idx = i * STM32MP_REGION_PARAMS; uint32_t base; uint32_t size; uint32_t sec_attr; uint32_t nsaid; - base = fdt32_to_cpu(conf_list->id_attr[i * STM32MP_REGION_PARAMS]); - size = fdt32_to_cpu(conf_list->id_attr[i * STM32MP_REGION_PARAMS + 1]); - sec_attr = fdt32_to_cpu(conf_list->id_attr[i * STM32MP_REGION_PARAMS + 2]); - nsaid = fdt32_to_cpu(conf_list->id_attr[i * STM32MP_REGION_PARAMS + 3]); + base = fdt32_to_cpu(conf_list->id_attr[idx]); + size = fdt32_to_cpu(conf_list->id_attr[idx + 1]); + sec_attr = fdt32_to_cpu(conf_list->id_attr[idx + 2]); + nsaid = fdt32_to_cpu(conf_list->id_attr[idx + 3]); VERBOSE("FCONF: stm32mp1-firewall cell found with value = 0x%x 0x%x 0x%x 0x%x\n", base, size, sec_attr, nsaid); diff --git a/plat/st/stm32mp1/stm32mp1_private.c b/plat/st/stm32mp1/stm32mp1_private.c index 9bdb07552..ae39c0bce 100644 --- a/plat/st/stm32mp1/stm32mp1_private.c +++ b/plat/st/stm32mp1/stm32mp1_private.c @@ -140,14 +140,14 @@ void configure_mmu(void) uintptr_t stm32_get_gpio_bank_base(unsigned int bank) { #if STM32MP13 - assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_I); + assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_I)); #endif #if STM32MP15 if (bank == GPIO_BANK_Z) { return GPIOZ_BASE; } - assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K); + assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_K)); #endif return GPIOA_BASE + (bank * GPIO_BANK_OFFSET); @@ -156,14 +156,14 @@ uintptr_t stm32_get_gpio_bank_base(unsigned int bank) uint32_t stm32_get_gpio_bank_offset(unsigned int bank) { #if STM32MP13 - assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_I); + assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_I)); #endif #if STM32MP15 if (bank == GPIO_BANK_Z) { return 0; } - assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K); + assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_K)); #endif return bank * GPIO_BANK_OFFSET; @@ -186,14 +186,14 @@ bool stm32_gpio_is_secure_at_reset(unsigned int bank) unsigned long stm32_get_gpio_bank_clock(unsigned int bank) { #if STM32MP13 - assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_I); + assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_I)); #endif #if STM32MP15 if (bank == GPIO_BANK_Z) { return GPIOZ; } - assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K); + assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_K)); #endif return GPIOA + (bank - GPIO_BANK_A); diff --git a/plat/st/stm32mp1/stm32mp1_syscfg.c b/plat/st/stm32mp1/stm32mp1_syscfg.c index ff79428a6..75dd70931 100644 --- a/plat/st/stm32mp1/stm32mp1_syscfg.c +++ b/plat/st/stm32mp1/stm32mp1_syscfg.c @@ -235,7 +235,9 @@ static void enable_hslv_by_index(uint32_t index) } if (apply_hslv) { - mmio_write_32(SYSCFG_BASE + SYSCFG_HSLVEN0R + index * sizeof(uint32_t), HSLV_KEY); + uint32_t reg_offset = index * sizeof(uint32_t); + + mmio_write_32(SYSCFG_BASE + SYSCFG_HSLVEN0R + reg_offset, HSLV_KEY); } } #endif -- 2.39.5