Skip to contentSkip to conversation

fdtdec: use full path in fdtdec_get_alias_seq comparison

PATCH New Vladimir Oltean 2 participants 6 messages Mar 27, 2020 – Mar 28, 2020 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fdtdec: use full path in fdtdec_get_alias_seq comparison

From: Vladimir Oltean <[email protected]>

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")
---
 lib/fdtdec.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
lib/fdtdec.c +7 -8
index eb11fc898e30..55c1b36e823b 100644
@@ -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) {
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 fdtdec: use full path in fdtdec_get_alias_seq comparison

Hi Vladimir,

Quoted 34 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

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")
---
 lib/fdtdec.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
lib/fdtdec.c +0 -0
index eb11fc898e30..55c1b36e823b 100644
@@ -455,13 +455,14 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
                         int *seqp)
 {
        int base_len = strlen(base);

lib/fdtdec.c int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, · line 463

Quoted 10 lines
lib/fdtdec.c +3 -4
-       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));

This is really slow. I would prefer not to change this for what seems like an odd case.

Can you enable CONFIG_OF_LIVE instead?

Quoted 26 lines
lib/fdtdec.c +4 -5
+       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) {
--
Quoted 2 lines

2.17.1

Regards,
Simon

#2 lore raw

PATCH 1/1 fdtdec: use full path in fdtdec_get_alias_seq comparison

Hi Simon,

Quoted 45 lines · Simon Glass

Hi Vladimir,

Quoted 41 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

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")
---
 lib/fdtdec.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
lib/fdtdec.c +2 -2
index eb11fc898e30..55c1b36e823b 100644
@@ -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;
 
Quoted 9 lines

lib/fdtdec.c int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, · line 463

Quoted 3 lines
lib/fdtdec.c +1 -2
-       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));

This is really slow. I would prefer not to change this for what seems like an odd case.

Can you enable CONFIG_OF_LIVE instead?

No, why would I want to do that?
Why is this an odd case? I thought aliases are supposed to match on full path, no?

Quoted 19 lines
Quoted 19 lines
lib/fdtdec.c +3 -2
+       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;
 
Quoted 12 lines
Quoted 9 lines
lib/fdtdec.c +1 -3
-               slash = strrchr(prop, '/');
-               if (strcmp(slash + 1, find_name))
+               if (strcmp(prop, path))
                        continue;
                val = trailing_strtol(name);
                if (val != -1) {
--

2.17.1

Regards,
Simon

Regards,
-Vladimir

#3 lore raw

PATCH 1/1 fdtdec: use full path in fdtdec_get_alias_seq comparison

Hi Vladimir,

Quoted 56 lines · Vladimir Oltean

Hi Simon,

Quoted 52 lines · Simon Glass

Hi Vladimir,

Quoted 34 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

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")
---
 lib/fdtdec.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
lib/fdtdec.c +0 -0
index eb11fc898e30..55c1b36e823b 100644
@@ -455,13 +455,14 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
                         int *seqp)
 {
        int base_len = strlen(base);

lib/fdtdec.c int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, · line 463

Quoted 10 lines
lib/fdtdec.c +3 -4
-       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));

This is really slow. I would prefer not to change this for what seems like an odd case.

Quoted 4 lines
Quoted 2 lines

Can you enable CONFIG_OF_LIVE instead?

No, why would I want to do that?

Because it uses a different algorithm - see of_alias_get_id(). It might already work.

Quoted 2 lines

Why is this an odd case? I thought aliases are supposed to match on full path, no?

Because we've been using the current algorithm for 5+ years without any comment.

Note that fdt_get_path() likely takes a long time in SPL and before relocation.

Regards,
Simon

#4 lore raw

PATCH 1/1 fdtdec: use full path in fdtdec_get_alias_seq comparison

Quoted 71 lines · Simon Glass

Hi Vladimir,

Quoted 56 lines · Vladimir Oltean

Hi Simon,

Quoted 52 lines · Simon Glass

Hi Vladimir,

Quoted 34 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

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")
---
 lib/fdtdec.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
lib/fdtdec.c +0 -0
index eb11fc898e30..55c1b36e823b 100644
@@ -455,13 +455,14 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
                         int *seqp)
 {
        int base_len = strlen(base);

lib/fdtdec.c int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, · line 463

Quoted 10 lines
lib/fdtdec.c +3 -4
-       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));

This is really slow. I would prefer not to change this for what seems like an odd case.

Quoted 4 lines
Quoted 2 lines

Can you enable CONFIG_OF_LIVE instead?

No, why would I want to do that?

Because it uses a different algorithm - see of_alias_get_id(). It might already work.

Quoted 2 lines

Why is this an odd case? I thought aliases are supposed to match on full path, no?

Quoted 6 lines

Because we've been using the current algorithm for 5+ years without any comment.

Note that fdt_get_path() likely takes a long time in SPL and before relocation.

Regards,
Simon

So we have no disagreement about the fact that the function doesn't do what's written on the box, and that the implementation for CONFIG_OF_LIVE=y and CONFIG_OF_LIVE=n yields different results, however your argument is that we should leave it alone because nobody noticed thus far? Don't I count?

Regards,
-Vladimir

#5 lore raw

PATCH 1/1 fdtdec: use full path in fdtdec_get_alias_seq comparison

Hi Vladimir,

Quoted 77 lines · Vladimir Oltean
Quoted 75 lines · Simon Glass

Hi Vladimir,

Quoted 56 lines · Vladimir Oltean

Hi Simon,

Quoted 52 lines · Simon Glass

Hi Vladimir,

Quoted 34 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

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")
---
 lib/fdtdec.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
lib/fdtdec.c +0 -0
index eb11fc898e30..55c1b36e823b 100644
@@ -455,13 +455,14 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
                         int *seqp)
 {
        int base_len = strlen(base);

lib/fdtdec.c int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, · line 463

Quoted 10 lines
lib/fdtdec.c +3 -4
-       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));

This is really slow. I would prefer not to change this for what seems like an odd case.

Quoted 4 lines
Quoted 2 lines

Can you enable CONFIG_OF_LIVE instead?

No, why would I want to do that?

Because it uses a different algorithm - see of_alias_get_id(). It might already work.

Quoted 2 lines

Why is this an odd case? I thought aliases are supposed to match on full path, no?

Because we've been using the current algorithm for 5+ years without any comment.

Note that fdt_get_path() likely takes a long time in SPL and before relocation.

Quoted 8 lines
Quoted 2 lines

Regards,
Simon

So we have no disagreement about the fact that the function doesn't do what's written on the box, and that the implementation for CONFIG_OF_LIVE=y and CONFIG_OF_LIVE=n yields different results, however your argument is that we should leave it alone because nobody noticed thus far? Don't I count?

You are very special and count a lot :-)

Actually my argument is mostly that fdt_get_path() is a very slow function and I would like to avoid calling it in SPL if at all possible.

Does your board need to access this alias before relocation?

Regards,
Simon