Skip to content

Commit 78bdf67

Browse files
authored
[drivers][ofw] fix ofw_alias_scan() bug (#8908)
* fix ofw_alias_scan() bug * fix tag_len
1 parent b421b4e commit 78bdf67

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Diff for: components/drivers/ofw/base.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,9 @@ rt_err_t ofw_alias_scan(void)
10511051

10521052
rt_ofw_foreach_prop(np, prop)
10531053
{
1054-
int id = 0, rate = 1;
1054+
int id = 0;
10551055
struct alias_info *info;
1056-
const char *name = prop->name, *end;
1056+
const char *name = prop->name, *end, *id_start;
10571057

10581058
/* Maybe the bootloader will set the name, or other nodes reference the aliases */
10591059
if (!rt_strcmp(name, "name") || !rt_strcmp(name, "phandle"))
@@ -1066,19 +1066,20 @@ rt_err_t ofw_alias_scan(void)
10661066
continue;
10671067
}
10681068

1069-
end = name + rt_strlen(name) - 1;
1069+
end = name + rt_strlen(name);
10701070

1071-
while (*end && !(*end >= '0' && *end <= '9') && end > name)
1071+
while (*(end - 1) && (*(end - 1) >= '0' && *(end - 1) <= '9') && end > name)
10721072
{
10731073
--end;
10741074
}
10751075

1076-
while (*end && (*end >= '0' && *end <= '9'))
1076+
id_start = end;
1077+
while (*id_start && (*id_start >= '0' && *id_start <= '9'))
10771078
{
1078-
id += (*end - '0') * rate;
1079-
rate *= 10;
1079+
id *= 10;
1080+
id += (*id_start - '0');
10801081

1081-
++end;
1082+
++id_start;
10821083
}
10831084

10841085
info = rt_malloc(sizeof(*info));
@@ -1093,7 +1094,7 @@ rt_err_t ofw_alias_scan(void)
10931094

10941095
info->id = id;
10951096
info->tag = name;
1096-
info->tag_len = end - name - 1;
1097+
info->tag_len = end - name;
10971098
info->np = tmp;
10981099

10991100
rt_list_insert_after(&_aliases_nodes, &info->list);

0 commit comments

Comments
 (0)