From: Vladimir Oltean <olteanv@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH] fdtdec: use full path in fdtdec_get_alias_seq comparison
Date: Fri, 27 Mar 2020 19:28:55 +0200 [thread overview]
Message-ID: <20200327172855.11746-1-olteanv@gmail.com> (raw)
From: Vladimir Oltean <vladimir.oltean@nxp.com>
Currently fdtdec_get_alias_seq() calls fdt_get_name() which returns only
the name of the leaf node. So it needs to also trim the path of the
alias to the leaf name only, leading to imperfect matches.
This means that the following aliases:
/aliases {
eth0 = "/dspi at 2120000/ethernet-switch at 0/ports/port at 0";
eth1 = "/pcie at 1f0000000/pci at 0,5/ports/port at 0";
};
will make fdtdec_get_alias_seq to return a seq of zero for both aliases,
as the match will only take place on the "port at 0" portion.
Fix this by calling fdt_get_path and comparing the full path of the
alias.
Fixes: 5c33c9fdbb3f ("fdt: Add a function to get the alias sequence of a node")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
lib/fdtdec.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index eb11fc898e30..55c1b36e823b 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -455,13 +455,14 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
int *seqp)
{
int base_len = strlen(base);
- const char *find_name;
- int find_namelen;
int prop_offset;
+ char path[64];
+ int path_len;
int aliases;
- find_name = fdt_get_name(blob, offset, &find_namelen);
- debug("Looking for '%s' at %d, name %s\n", base, offset, find_name);
+ fdt_get_path(blob, offset, path, sizeof(path));
+ path_len = strlen(path);
+ debug("Looking for '%s' at %d, path %s\n", base, offset, path);
aliases = fdt_path_offset(blob, "/aliases");
for (prop_offset = fdt_first_property_offset(blob, aliases);
@@ -469,17 +470,15 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
prop_offset = fdt_next_property_offset(blob, prop_offset)) {
const char *prop;
const char *name;
- const char *slash;
int len, val;
prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len);
debug(" - %s, %s\n", name, prop);
- if (len < find_namelen || *prop != '/' || prop[len - 1] ||
+ if (len < path_len || *prop != '/' || prop[len - 1] ||
strncmp(name, base, base_len))
continue;
- slash = strrchr(prop, '/');
- if (strcmp(slash + 1, find_name))
+ if (strcmp(prop, path))
continue;
val = trailing_strtol(name);
if (val != -1) {
--
2.17.1
next reply other threads:[~2020-03-27 17:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-27 17:28 Vladimir Oltean [this message]
2020-03-28 20:05 ` [PATCH] fdtdec: use full path in fdtdec_get_alias_seq comparison Simon Glass
2020-03-28 20:25 ` Vladimir Oltean
2020-03-28 21:00 ` Simon Glass
2020-03-28 21:12 ` Vladimir Oltean
2020-03-28 22:00 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200327172855.11746-1-olteanv@gmail.com \
--to=olteanv@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox