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

* fix ofw_alias_scan() bug

* fix tag_len
This commit is contained in:
liYangYang 2024-05-13 20:56:32 +08:00 committed by GitHub
parent b421b4e1f4
commit 78bdf67ab2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 9 deletions

View File

@ -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);