summaryrefslogtreecommitdiff
path: root/lib/fdtdec.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-06-23 15:39:08 -0600
committerSimon Glass <sjg@chromium.org>2015-07-21 17:39:28 -0600
commitc4af6732c4021ffe8b3d0c82bdcf1eebb263bfc3 (patch)
treeb34c0808db76437623e8c1f887ea24d36df91d59 /lib/fdtdec.c
parent1acab96d974a1b9f35cbc901f68ef00653d18738 (diff)
downloadu-boot-imx-c4af6732c4021ffe8b3d0c82bdcf1eebb263bfc3.zip
u-boot-imx-c4af6732c4021ffe8b3d0c82bdcf1eebb263bfc3.tar.gz
u-boot-imx-c4af6732c4021ffe8b3d0c82bdcf1eebb263bfc3.tar.bz2
lib: Add function to extract a number from the end of a string
Split out the code in fdtdec which finds a number at the end of a string. It can be useful in other situations. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/fdtdec.c')
-rw-r--r--lib/fdtdec.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 9c6b361..f6c2b19 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -505,8 +505,7 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
const char *prop;
const char *name;
const char *slash;
- const char *p;
- int len;
+ int len, val;
prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len);
debug(" - %s, %s\n", name, prop);
@@ -517,12 +516,11 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
slash = strrchr(prop, '/');
if (strcmp(slash + 1, find_name))
continue;
- for (p = name + strlen(name) - 1; p > name; p--) {
- if (!isdigit(*p)) {
- *seqp = simple_strtoul(p + 1, NULL, 10);
- debug("Found seq %d\n", *seqp);
- return 0;
- }
+ val = trailing_strtol(name);
+ if (val != -1) {
+ *seqp = val;
+ debug("Found seq %d\n", *seqp);
+ return 0;
}
}