diff options
| author | liYangYang <[email protected]> | 2024-05-13 20:56:32 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-13 20:56:32 +0800 |
| commit | 78bdf67ab23a559b5484469a826cfece975d267f (patch) | |
| tree | 44d32cc0832b4e17a9ab0bbc6f2082db9f638546 /components | |
| parent | b421b4e1f4502c4490d9fe97cb2ec629bc670f8b (diff) | |
[drivers][ofw] fix ofw_alias_scan() bug (#8908)
* fix ofw_alias_scan() bug
* fix tag_len
Diffstat (limited to 'components')
| -rw-r--r-- | components/drivers/ofw/base.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/components/drivers/ofw/base.c b/components/drivers/ofw/base.c index 8d629a9f67..75c5a7987f 100644 --- a/components/drivers/ofw/base.c +++ b/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); |
