Ver código fonte

[drivers][ofw] fix ofw_alias_scan() bug (#8908)

* fix ofw_alias_scan() bug

* fix tag_len
liYangYang 11 meses atrás
pai
commit
78bdf67ab2
1 arquivos alterados com 10 adições e 9 exclusões
  1. 10 9
      components/drivers/ofw/base.c

+ 10 - 9
components/drivers/ofw/base.c

@@ -1051,9 +1051,9 @@ rt_err_t ofw_alias_scan(void)
 
     rt_ofw_foreach_prop(np, prop)
     {
-        int id = 0, rate = 1;
+        int id = 0;
         struct alias_info *info;
-        const char *name = prop->name, *end;
+        const char *name = prop->name, *end, *id_start;
 
         /* Maybe the bootloader will set the name, or other nodes reference the aliases */
         if (!rt_strcmp(name, "name") || !rt_strcmp(name, "phandle"))
@@ -1066,19 +1066,20 @@ rt_err_t ofw_alias_scan(void)
             continue;
         }
 
-        end = name + rt_strlen(name) - 1;
+        end = name + rt_strlen(name);
 
-        while (*end && !(*end >= '0' && *end <= '9') && end > name)
+        while (*(end - 1) && (*(end - 1) >= '0' && *(end - 1) <= '9') && end > name)
         {
             --end;
         }
 
-        while (*end && (*end >= '0' && *end <= '9'))
+        id_start = end;
+        while (*id_start && (*id_start >= '0' && *id_start <= '9'))
         {
-            id += (*end - '0') * rate;
-            rate *= 10;
+            id *= 10;
+            id += (*id_start - '0');
 
-            ++end;
+            ++id_start;
         }
 
         info = rt_malloc(sizeof(*info));
@@ -1093,7 +1094,7 @@ rt_err_t ofw_alias_scan(void)
 
         info->id = id;
         info->tag = name;
-        info->tag_len = end - name - 1;
+        info->tag_len = end - name;
         info->np = tmp;
 
         rt_list_insert_after(&_aliases_nodes, &info->list);