]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
fix(st): use indices when counting GPIOs in DT
authorYann Gautier <yann.gautier@st.com>
Mon, 21 Nov 2022 10:45:04 +0000 (11:45 +0100)
committerYann Gautier <yann.gautier@st.com>
Wed, 7 Dec 2022 13:20:01 +0000 (14:20 +0100)
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 <yann.gautier@st.com>
Change-Id: Iabfe587bf72535541c94bfa341de10148aa58030

plat/st/common/stm32mp_dt.c

index 5681fa6a7dbc2c0c8f1dcadd8cbc86b54b247399..5a5ca565d8b9e5d0c1d37b3a4d18bc901ceb01d0 100644 (file)
@@ -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;