From e7d75448b9e46dee22fe23b37c28a522b9ec3a6c Mon Sep 17 00:00:00 2001 From: Yann Gautier Date: Mon, 21 Nov 2022 11:45:04 +0100 Subject: [PATCH] fix(st): use indices when counting GPIOs in DT Fix MISRA C2012-18.4: The +, -, += and -= operators should not be applied to an expression of pointer type. While at it, avoid computing twice the same value, by removing the initial value computation outside the loop. Signed-off-by: Yann Gautier Change-Id: Iabfe587bf72535541c94bfa341de10148aa58030 --- plat/st/common/stm32mp_dt.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plat/st/common/stm32mp_dt.c b/plat/st/common/stm32mp_dt.c index 5681fa6a7..5a5ca565d 100644 --- a/plat/st/common/stm32mp_dt.c +++ b/plat/st/common/stm32mp_dt.c @@ -386,7 +386,7 @@ int fdt_get_gpio_bank_pin_count(unsigned int bank) fdt_for_each_subnode(node, fdt, pinctrl_node) { const fdt32_t *cuint; - int pin_count; + int pin_count = 0; int len; int i; @@ -415,11 +415,9 @@ 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++) { - pin_count = MAX(pin_count, (int)(fdt32_to_cpu(*(cuint + 1)) + - fdt32_to_cpu(*(cuint + 3)))); - cuint += 4; + for (i = 0; i < len; i += 4) { + pin_count = MAX(pin_count, (int)(fdt32_to_cpu(cuint[i + 1]) + + fdt32_to_cpu(cuint[i + 3]))); } return pin_count;