board: fsl: lx2160a: Fix the loop in board_fix_fdt function
authorPankaj Bansal <pankaj.bansal@nxp.com>
Wed, 15 Jan 2020 05:57:00 +0000 (05:57 +0000)
committerPriyanka Jain <priyanka.jain@nxp.com>
Fri, 24 Jan 2020 08:58:26 +0000 (14:28 +0530)
Fix loop in board_fix_fdt that erroneously increments the counter
in all cases whereas the counter should be incremented only if a
matching string has been found.

Fixes: 5d535aa40b ("board: fsl: lx2160a: implement board_fix_fdt")

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Signed-off-by: Priyanka Jain <priyanka.jain@nxp.com>
board/freescale/lx2160a/lx2160a.c

index 0b0d6bf91aa78bf16e6d72cff61c2c9e802db72e..6555b5ad3a8b859a4959eb23176ef3f87717fd09 100644 (file)
@@ -132,7 +132,7 @@ int board_fix_fdt(void *fdt)
                { "ccsr", "dbi" },
                { "pf_ctrl", "ctrl" }
        };
-       int off = -1, i;
+       int off = -1, i = 0;
 
        if (IS_SVR_REV(get_svr(), 1, 0))
                return 0;
@@ -149,7 +149,7 @@ int board_fix_fdt(void *fdt)
 
                reg_name = reg_names;
                remaining_names_len = names_len - (reg_name - reg_names);
-               for (i = 0; (i < ARRAY_SIZE(reg_names_map)) && names_len; i++) {
+               while ((i < ARRAY_SIZE(reg_names_map)) && remaining_names_len) {
                        old_name_len = strlen(reg_names_map[i].old_str);
                        new_name_len = strlen(reg_names_map[i].new_str);
                        if (memcmp(reg_name, reg_names_map[i].old_str,
@@ -165,6 +165,7 @@ int board_fix_fdt(void *fdt)
                                       new_name_len);
                                names_len -= old_name_len;
                                names_len += new_name_len;
+                               i++;
                        }
 
                        reg_name = memchr(reg_name, '\0', remaining_names_len);