lib: utils/serial: Fix fdt_serial to match more dt nodes
authorXiang W <wxjstz@126.com>
Tue, 11 Jun 2024 11:19:32 +0000 (19:19 +0800)
committerAnup Patel <anup@brainfault.org>
Thu, 13 Jun 2024 13:09:37 +0000 (18:39 +0530)
If there are multiple dt nodes, the previous code only tries to match
the first one, which may lose initialization.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/utils/serial/fdt_serial.c

index 8b6e6b9774287f8c1f71ae015058196bf7758eb3..798ac749e86d4141b9949cba62fc77e2c9f56fdb 100644 (file)
@@ -68,21 +68,21 @@ int fdt_serial_init(void)
        for (pos = 0; pos < fdt_serial_drivers_size; pos++) {
                drv = fdt_serial_drivers[pos];
 
-               noff = fdt_find_match(fdt, -1, drv->match_table, &match);
-               if (noff < 0)
-                       continue;
-
-               if (!fdt_node_is_enabled(fdt, noff))
-                       continue;
+               noff = -1;
+               while ((noff = fdt_find_match(fdt, noff,
+                                       drv->match_table, &match)) >= 0) {
+                       if (!fdt_node_is_enabled(fdt, noff))
+                               continue;
 
-               /* drv->init must not be NULL */
-               if (drv->init == NULL)
-                       return SBI_EFAIL;
+                       /* drv->init must not be NULL */
+                       if (drv->init == NULL)
+                               return SBI_EFAIL;
 
-               rc = drv->init(fdt, noff, match);
-               if (rc == SBI_ENODEV)
-                       continue;
-               return rc;
+                       rc = drv->init(fdt, noff, match);
+                       if (rc == SBI_ENODEV)
+                               continue;
+                       return rc;
+               }
        }
 
        return SBI_ENODEV;