Skip to contentSkip to conversation

of: fix bugs and improve codes

PATCH Applied Zijun Hu 3 participants 26 messages Dec 6, 2024 – Dec 11, 2024

Subsystems (2)

v1 of 5 Applied Latest is v5 →

lore
Share & tools
lore

Zijun Hu

author
#0 lore raw

cover of: fix bugs and improve codes

This patch series is to fix bugs and improve codes for drivers/of/*.

---
Zijun Hu (10):
of: Fix alias name length calculating error in API of_find_node_opts_by_path()
of: Correct return value for API of_parse_phandle_with_args_map()
of: Correct child specifier used as input of the 2nd nexus node
of: Fix refcount leakage for OF node returned by __of_get_dma_parent()
of: Fix available buffer size calculating error in API of_device_uevent_modalias() of/fdt: Dump __be32 array in CPU type order in of_dump_addr()
of: Correct comments for of_alias_scan()
of: Swap implementation between of_property_present() and of_property_read_bool()
of: property: Implement of_fwnode_property_present() by of_property_present()
of: Simplify API of_find_node_with_property() implementation

 drivers/of/address.c     |  2 +-
 drivers/of/base.c        | 25 +++++++++++--------------
 drivers/of/device.c      |  4 ++--
 drivers/of/fdt_address.c |  2 +-
 drivers/of/property.c    |  2 +-
 include/linux/of.h       | 23 ++++++++++++-----------
 6 files changed, 28 insertions(+), 30 deletions(-)

---
base-commit: 16ef9c9de0c48b836c5996c6e9792cb4f658c8f1
change-id: 20241206-of_core_fix-dc3021a06418

Best regards,

Signature · 1 line
Zijun Hu <[email protected]>
author
#1 lore raw

PATCH 1/10 of: Fix alias name length calculating error in API of_find_node_opts_by_path()

From: Zijun Hu <[email protected]>

Alias name length calculated by of_find_node_opts_by_path() is wrong as explained below:

Take "alias/serial@llc500:115200n8" as its @patch argument for an example
^ ^ ^
0 5 19

The right length of alias 'alias' is 5, but the API results in 19 which is obvious wrong.

The wrong length will cause finding device node failure for such paths. Fix by using index of either '/' or ':' as the length who comes earlier.

Fixes 106937e8ccdc ("of: fix handling of '/' in options for of_find_node_by_path()")
---
 drivers/of/base.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/of/base.c +3 -3
index 7dc394255a0a14cd1aed02ec79c2f787a222b44c..9a9313183d1f1b61918fe7e6fa80c2726b099a1c 100644
@@ -893,10 +893,10 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
 	/* The path could begin with an alias */
 	if (*path != '/') {
 		int len;
-		const char *p = separator;
+		const char *p = strchrnul(path, '/');
 
-		if (!p)
-			p = strchrnul(path, '/');
+		if (separator && separator < p)
+			p = separator;
 		len = p - path;
 
 		/* of_aliases must not be NULL */
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH 01/10] of: Fix alias name length calculating error in API of_find_node_opts_by_path()

Quoted 7 lines · Zijun Hu

From: Zijun Hu <[email protected]>

Alias name length calculated by of_find_node_opts_by_path() is wrong as explained below:

Take "alias/serial@llc500:115200n8" as its @patch argument for an example

Quoted 8 lines
      ^    ^             ^
      0    5             19

The right length of alias 'alias' is 5, but the API results in 19 which is obvious wrong.

The wrong length will cause finding device node failure for such paths. Fix by using index of either '/' or ':' as the length who comes earlier.

Can you add a test case in the unittest for this.

Quoted 30 lines
Fixes 106937e8ccdc ("of: fix handling of '/' in options for of_find_node_by_path()")
---
 drivers/of/base.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/of/base.c +3 -4
index 7dc394255a0a14cd1aed02ec79c2f787a222b44c..9a9313183d1f1b61918fe7e6fa80c2726b099a1c 100644
@@ -893,10 +893,10 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
        /* The path could begin with an alias */
        if (*path != '/') {
                int len;
-               const char *p = separator;
+               const char *p = strchrnul(path, '/');
 
-               if (!p)
-                       p = strchrnul(path, '/');
+               if (separator && separator < p)
+                       p = separator;
                len = p - path;
 
                /* of_aliases must not be NULL */
 
--

2.34.1

author
#3 lore raw

Re: [PATCH 01/10] of: Fix alias name length calculating error in API of_find_node_opts_by_path()

Quoted 11 lines · Rob Herring
Quoted 10 lines · Zijun Hu

From: Zijun Hu <[email protected]>

Alias name length calculated by of_find_node_opts_by_path() is wrong as explained below:

Take "alias/serial@llc500:115200n8" as its @patch argument for an example

      ^    ^             ^
      0    5             19
Quoted 7 lines
Quoted 5 lines

The right length of alias 'alias' is 5, but the API results in 19 which is obvious wrong.

The wrong length will cause finding device node failure for such paths. Fix by using index of either '/' or ':' as the length who comes earlier.

Can you add a test case in the unittest for this.

sure. let me try to do it.

Quoted 31 lines
Quoted 31 lines
Fixes 106937e8ccdc ("of: fix handling of '/' in options for of_find_node_by_path()")
---
 drivers/of/base.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/of/base.c +3 -4
index 7dc394255a0a14cd1aed02ec79c2f787a222b44c..9a9313183d1f1b61918fe7e6fa80c2726b099a1c 100644
@@ -893,10 +893,10 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
        /* The path could begin with an alias */
        if (*path != '/') {
                int len;
-               const char *p = separator;
+               const char *p = strchrnul(path, '/');
 
-               if (!p)
-                       p = strchrnul(path, '/');
+               if (separator && separator < p)
+                       p = separator;
                len = p - path;
 
                /* of_aliases must not be NULL */
 
--

2.34.1

author
#4 lore raw

PATCH 2/10 of: Correct return value for API of_parse_phandle_with_args_map()

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

@ret is used by of_parse_phandle_with_args_map() to record return value and it is preseted with -EINVAL before the outer while loop, but it is changed to 0 by below successful operation within the inner loop:
of_property_read_u32(new, cells_name, &new_size)

So cause 0(success) is returned for all failures which happen after the operation, that is obviously wrong.

Fix by restoring @ret with preseted -EINVAL after the operation.

Fixes bd6f2fd5a1d5 ("of: Support parsing phandle argument lists through a nexus node")
---
 drivers/of/base.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/base.c +2 -0
index 9a9313183d1f1b61918fe7e6fa80c2726b099a1c..b294924aa31cfed1ec06983f420a445f7fae7394 100644
@@ -1516,6 +1516,8 @@ int of_parse_phandle_with_args_map(const struct device_node *np,
 			ret = of_property_read_u32(new, cells_name, &new_size);
 			if (ret)
 				goto put;
+			/* Restore preseted error code */
+			ret = -EINVAL;
 
 			/* Check for malformed properties */
 			if (WARN_ON(new_size > MAX_PHANDLE_ARGS))
Signature · 1 line
2.34.1
maintainer
#5 lore raw

Re: [PATCH 02/10] of: Correct return value for API of_parse_phandle_with_args_map()

Quoted 8 lines · Zijun Hu

From: Zijun Hu <[email protected]>

@ret is used by of_parse_phandle_with_args_map() to record return value and it is preseted with -EINVAL before the outer while loop, but it is changed to 0 by below successful operation within the inner loop:
of_property_read_u32(new, cells_name, &new_size)

Quoted 4 lines

So cause 0(success) is returned for all failures which happen after the operation, that is obviously wrong.

Fix by restoring @ret with preseted -EINVAL after the operation.

Already have a similar fix queued up.

Rob

author
#6 lore raw

PATCH 3/10 of: Correct child specifier used as input of the 2nd nexus node

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

API of_parse_phandle_with_args_map() will use wrong input for nexus node Nexus_2 as shown below:

Node_1 Nexus_1 Nexus_2
&Nexus_1,arg_1 -> arg_1,&Nexus_2,arg_2' -> &Nexus_2,arg_2 -> arg_2,...

		  map-pass-thru=<...>

Nexus_1's output arg_2 should be used as input of Nexus_2, but the API wrongly uses arg_2' instead which != arg_2 due to Nexus_1's map-pass-thru.

Fix by always making @match_array point to @initial_match_array into which to store nexus output.

Fixes bd6f2fd5a1d5 ("of: Support parsing phandle argument lists through a nexus node")
---
 drivers/of/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/base.c +1 -1
index b294924aa31cfed1ec06983f420a445f7fae7394..1c62cda4ebcd9e3dc5f91d10fa68f975226693dd 100644
@@ -1542,7 +1542,6 @@ int of_parse_phandle_with_args_map(const struct device_node *np,
 		 * specifier into the out_args structure, keeping the
 		 * bits specified in <list>-map-pass-thru.
 		 */
-		match_array = map - new_size;
 		for (i = 0; i < new_size; i++) {
 			__be32 val = *(map - new_size + i);
 
@@ -1551,6 +1550,7 @@ int of_parse_phandle_with_args_map(const struct device_node *np,
 				val |= cpu_to_be32(out_args->args[i]) & pass[i];
 			}
 
+			initial_match_array[i] = val;
 			out_args->args[i] = be32_to_cpu(val);
 		}
 		out_args->args_count = list_size = new_size;
Signature · 1 line
2.34.1
author
#7 lore raw

PATCH 4/10 of: Fix refcount leakage for OF node returned by __of_get_dma_parent()

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

__of_get_dma_parent() returns OF device node @args.np, but the node's refcount is increased twice, by both of_parse_phandle_with_args() and of_node_get(), so causes refcount leakage for the node.

Fix by directly returning the node got by of_parse_phandle_with_args().

Fixes f83a6e5dea6c ("of: address: Add support for the parent DMA bus")
---
 drivers/of/address.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/address.c +1 -1
index c5b925ac469f16b8ae4b8275b60210a2d583ff83..cda1cbb82eabdcd39d32446023fbb105b69bc99d 100644
@@ -619,7 +619,7 @@ struct device_node *__of_get_dma_parent(const struct device_node *np)
 	if (ret < 0)
 		return of_get_parent(np);
 
-	return of_node_get(args.np);
+	return args.np;
 }
 #endif
 
Signature · 1 line
2.34.1
maintainer Applied
#8 lore raw

Re: [PATCH 04/10] of: Fix refcount leakage for OF node returned by __of_get_dma_parent()

Quoted 6 lines · Zijun Hu

From: Zijun Hu <[email protected]>

__of_get_dma_parent() returns OF device node @args.np, but the node's refcount is increased twice, by both of_parse_phandle_with_args() and of_node_get(), so causes refcount leakage for the node.

Quoted 8 lines

Fix by directly returning the node got by of_parse_phandle_with_args().

Fixes f83a6e5dea6c ("of: address: Add support for the parent DMA bus")
---
 drivers/of/address.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Rob

author
#9 lore raw

PATCH 5/10 of: Fix available buffer size calculating error in API of_device_uevent_modalias()

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

of_device_uevent_modalias() saves MODALIAS value from offset (@env->buflen - 1), so the available buffer size should be (sizeof(@env->buf) - @env->buflen + 1), but it uses the wrong size (sizeof(@env->buf) - @env->buflen).

Fix by using right size (sizeof(@env->buf) - @env->buflen + 1).

Fixes dd27dcda37f0 ("of/device: merge of_device_uevent")
---
 drivers/of/device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/of/device.c +2 -2
index edf3be1972658f6dc165f577da53b10c7eebc116..ee29c07c83b9e6abd9b1c7747dd341026bc79eb0 100644
@@ -266,10 +266,10 @@ int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *
 		return -ENOMEM;
 
 	sl = of_modalias(dev->of_node, &env->buf[env->buflen-1],
-			 sizeof(env->buf) - env->buflen);
+			 sizeof(env->buf) - env->buflen + 1);
 	if (sl < 0)
 		return sl;
-	if (sl >= (sizeof(env->buf) - env->buflen))
+	if (sl >= (sizeof(env->buf) - env->buflen + 1))
 		return -ENOMEM;
 	env->buflen += sl;
 
Signature · 1 line
2.34.1
maintainer
#10 lore raw

Re: [PATCH 05/10] of: Fix available buffer size calculating error in API of_device_uevent_modalias()

Quoted 9 lines · Zijun Hu

From: Zijun Hu <[email protected]>

of_device_uevent_modalias() saves MODALIAS value from offset (@env->buflen - 1), so the available buffer size should be (sizeof(@env->buf) - @env->buflen + 1), but it uses the wrong size (sizeof(@env->buf) - @env->buflen).

Fix by using right size (sizeof(@env->buf) - @env->buflen + 1).

Just writing what the diff says already is not that useful. The key part you need to know is why we back up by 1 character to begin with.

Quoted 12 lines
Fixes dd27dcda37f0 ("of/device: merge of_device_uevent")
---
 drivers/of/device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/of/device.c +0 -0
index edf3be1972658f6dc165f577da53b10c7eebc116..ee29c07c83b9e6abd9b1c7747dd341026bc79eb0 100644

drivers/of/device.c int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env * · line 268

Quoted 3 lines
drivers/of/device.c +0 -0
@@ -266,10 +266,10 @@ int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *
                return -ENOMEM;
 
        sl = of_modalias(dev->of_node, &env->buf[env->buflen-1],

This could use a comment why we back up by 1. Better to put it in a variable than add/subtract 1 everywhere:

/* After add_uevent_event(), buflen is at character after the nul char which needs to be overwritten */
buflen = env->buflen - 1;

And then use 'buflen' throughout.

drivers/of/device.c int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env * · line 273

Quoted 7 lines
drivers/of/device.c +2 -2
-                        sizeof(env->buf) - env->buflen);
+                        sizeof(env->buf) - env->buflen + 1);
        if (sl < 0)
                return sl;
-       if (sl >= (sizeof(env->buf) - env->buflen))
+       if (sl >= (sizeof(env->buf) - env->buflen + 1))
                return -ENOMEM;

There's another potential problem. If we return before here, we end up with "OF_MODALIAS=\0" or "OF_MODALIAS=some-non-nul-terminated-str". Maybe that doesn't matter? I haven't looked at the caller.

I think a better solution to all this would be making add_uevent_var work to construct the full value. We could add "%pOFm" format that calls of_mod_alias(). Then this function becomes just:

return add_uevent_var(env, "MODALIAS=%pOFm");

And of_device_modalias() can be:

sl = snprintf(str, len, "%pOFm\n", dev->of_node);
if (sl >= len)
return -ENOMEM;
return sl;

Rob

author
#11 lore raw

Re: [PATCH 05/10] of: Fix available buffer size calculating error in API of_device_uevent_modalias()

Quoted 9 lines · Rob Herring
Quoted 8 lines · Zijun Hu

From: Zijun Hu <[email protected]>

of_device_uevent_modalias() saves MODALIAS value from offset (@env->buflen - 1), so the available buffer size should be (sizeof(@env->buf) - @env->buflen + 1), but it uses the wrong size (sizeof(@env->buf) - @env->buflen).

Quoted 5 lines
Quoted 1 line

Fix by using right size (sizeof(@env->buf) - @env->buflen + 1).

Just writing what the diff says already is not that useful. The key part you need to know is why we back up by 1 character to begin with.

will correct commit message in v2.

Quoted 19 lines
Quoted 12 lines
Fixes dd27dcda37f0 ("of/device: merge of_device_uevent")
---
 drivers/of/device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/of/device.c +0 -0
index edf3be1972658f6dc165f577da53b10c7eebc116..ee29c07c83b9e6abd9b1c7747dd341026bc79eb0 100644

drivers/of/device.c int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env * · line 268

Quoted 3 lines
drivers/of/device.c +0 -0
@@ -266,10 +266,10 @@ int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *
                return -ENOMEM;
 
        sl = of_modalias(dev->of_node, &env->buf[env->buflen-1],

This could use a comment why we back up by 1. Better to put it in a variable than add/subtract 1 everywhere:

Quoted 6 lines

/* After add_uevent_event(), buflen is at character after the nul char which needs to be overwritten */
buflen = env->buflen - 1;

And then use 'buflen' throughout.

good proposal. may use it for v2 after discussion done.

Quoted 8 lines

drivers/of/device.c int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env * · line 273

Quoted 7 lines
drivers/of/device.c +2 -2
-                        sizeof(env->buf) - env->buflen);
+                        sizeof(env->buf) - env->buflen + 1);
        if (sl < 0)
                return sl;
-       if (sl >= (sizeof(env->buf) - env->buflen))
+       if (sl >= (sizeof(env->buf) - env->buflen + 1))
                return -ENOMEM;
Quoted 4 lines

There's another potential problem. If we return before here, we end up with "OF_MODALIAS=\0" or "OF_MODALIAS=some-non-nul-terminated-str". Maybe that doesn't matter? I haven't looked at the caller.

that does not matter since current logic follows below 2 rules

1) all strings in @env->buf always terminated with '\0'.
2) both env->buflen and env->envp_idx are not updated once @env->buf does not enough spaces then failed.

current logic has no difference with normal add_uevent_var() usage.

Quoted 4 lines

I think a better solution to all this would be making add_uevent_var work to construct the full value. We could add "%pOFm" format that calls of_mod_alias(). Then this function becomes just:

of_modalias() ?

agree with you.
for good practice, users should only use uevent APIs and should not depend on uevent's internal implementation.

Quoted 9 lines

return add_uevent_var(env, "MODALIAS=%pOFm");

And of_device_modalias() can be:

sl = snprintf(str, len, "%pOFm\n", dev->of_node);
if (sl >= len)
return -ENOMEM;
return sl;

looks good.

of_request_module() provides another solution.

Quoted 1 line

Rob

maintainer
#12 lore raw

Re: [PATCH 05/10] of: Fix available buffer size calculating error in API of_device_uevent_modalias()

Quoted 55 lines · Zijun Hu
Quoted 9 lines · Rob Herring
Quoted 8 lines · Zijun Hu

From: Zijun Hu <[email protected]>

of_device_uevent_modalias() saves MODALIAS value from offset (@env->buflen - 1), so the available buffer size should be (sizeof(@env->buf) - @env->buflen + 1), but it uses the wrong size (sizeof(@env->buf) - @env->buflen).

Quoted 5 lines
Quoted 1 line

Fix by using right size (sizeof(@env->buf) - @env->buflen + 1).

Just writing what the diff says already is not that useful. The key part you need to know is why we back up by 1 character to begin with.

will correct commit message in v2.

Quoted 19 lines
Quoted 12 lines
Fixes dd27dcda37f0 ("of/device: merge of_device_uevent")
---
 drivers/of/device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/of/device.c +0 -0
index edf3be1972658f6dc165f577da53b10c7eebc116..ee29c07c83b9e6abd9b1c7747dd341026bc79eb0 100644

drivers/of/device.c int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env * · line 268

Quoted 3 lines
drivers/of/device.c +0 -0
@@ -266,10 +266,10 @@ int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *
                return -ENOMEM;
 
        sl = of_modalias(dev->of_node, &env->buf[env->buflen-1],

This could use a comment why we back up by 1. Better to put it in a variable than add/subtract 1 everywhere:

Quoted 6 lines

/* After add_uevent_event(), buflen is at character after the nul char which needs to be overwritten */
buflen = env->buflen - 1;

And then use 'buflen' throughout.

good proposal. may use it for v2 after discussion done.

Quoted 8 lines
Quoted 7 lines
drivers/of/device.c +2 -2
-                        sizeof(env->buf) - env->buflen);
+                        sizeof(env->buf) - env->buflen + 1);
        if (sl < 0)
                return sl;
-       if (sl >= (sizeof(env->buf) - env->buflen))
+       if (sl >= (sizeof(env->buf) - env->buflen + 1))
                return -ENOMEM;
Quoted 8 lines
Quoted 4 lines

There's another potential problem. If we return before here, we end up with "OF_MODALIAS=\0" or "OF_MODALIAS=some-non-nul-terminated-str". Maybe that doesn't matter? I haven't looked at the caller.

that does not matter since current logic follows below 2 rules

1) all strings in @env->buf always terminated with '\0'.

Ah, right. However, we still end up with a truncated value though it is nul terminated.

Quoted 4 lines

2) both env->buflen and env->envp_idx are not updated once @env->buf does not enough spaces then failed.

current logic has no difference with normal add_uevent_var() usage.

There is one major difference. add_uevent_var() will not output anything if the whole string doesn't fit. Whereas we might output a truncated value because the add_uevent_var() call updated env->buflen and env->envp_idx. We could unwind that I suppose, but that involves even more mucking with the internals of the env struct.

Quoted 5 lines
Quoted 4 lines

I think a better solution to all this would be making add_uevent_var work to construct the full value. We could add "%pOFm" format that calls of_mod_alias(). Then this function becomes just:

of_modalias() ?

Yes.

Quoted 15 lines

agree with you.
for good practice, users should only use uevent APIs and should not depend on uevent's internal implementation.

Quoted 9 lines

return add_uevent_var(env, "MODALIAS=%pOFm");

And of_device_modalias() can be:

sl = snprintf(str, len, "%pOFm\n", dev->of_node);
if (sl >= len)
return -ENOMEM;
return sl;

Quoted 3 lines

looks good.

of_request_module() provides another solution.

Yes, that can be simplified to just a kasnprintf() call.

Rob

author
#13 lore raw

Re: [PATCH 05/10] of: Fix available buffer size calculating error in API of_device_uevent_modalias()

Quoted 6 lines · Rob Herring

Ah, right. However, we still end up with a truncated value though it is nul terminated.

Quoted 3 lines

2) both env->buflen and env->envp_idx are not updated once @env->buf does not enough spaces then failed.

Quoted 6 lines
Quoted 1 line

current logic has no difference with normal add_uevent_var() usage.

There is one major difference. add_uevent_var() will not output anything if the whole string doesn't fit. Whereas we might output a truncated value because the add_uevent_var() call updated env->buflen and env->envp_idx. We could unwind that I suppose, but that involves even more mucking with the internals of the env struct.

you are right.
i would like to try to solve involved issue in next revision. (^^)

author
#14 lore raw

PATCH 6/10 of/fdt: Dump __be32 array in CPU type order in of_dump_addr()

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

of_dump_addr() dumps __be32 array without conversion to CPU byte order in advance, that will reduce log readability for little endian CPUs.

Fix by be32_to_cpu() conversion before dump.

---
 drivers/of/fdt_address.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/fdt_address.c +1 -1
index 9804d7f067056a9437d37f0b4561d79dedcc3187..1e5311f6f1858b59b99f650bcafa55a8d11225f9 100644
@@ -28,7 +28,7 @@ static void __init of_dump_addr(const char *s, const __be32 *addr, int na)
 {
 	pr_debug("%s", s);
 	while(na--)
-		pr_cont(" %08x", *(addr++));
+		pr_cont(" %08x", be32_to_cpu(*(addr++)));
 	pr_cont("\n");
 }
 #else
Signature · 1 line
2.34.1
maintainer Applied
#15 lore raw

Re: [PATCH 06/10] of/fdt: Dump __be32 array in CPU type order in of_dump_addr()

Quoted 11 lines · Zijun Hu

From: Zijun Hu <[email protected]>

of_dump_addr() dumps __be32 array without conversion to CPU byte order in advance, that will reduce log readability for little endian CPUs.

Fix by be32_to_cpu() conversion before dump.

---
 drivers/of/fdt_address.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Rob

author
#16 lore raw

PATCH 7/10 of: Correct comments for of_alias_scan()

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

Correct of_alias_scan() comments by:

- Replace /* with /** to start comments since it is not a API.
- Delete return value descriptions since it is a void function.

---
 drivers/of/base.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/of/base.c +2 -3
index 1c62cda4ebcd9e3dc5f91d10fa68f975226693dd..33abb6227468c03fd191201aa2bbe05a41fdd9f4 100644
@@ -1812,14 +1812,13 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
 		 ap->alias, ap->stem, ap->id, np);
 }
 
-/**
+/*
  * of_alias_scan - Scan all properties of the 'aliases' node
  * @dt_alloc:	An allocator that provides a virtual address to memory
  *		for storing the resulting tree
  *
  * The function scans all the properties of the 'aliases' node and populates
- * the global lookup table with the properties.  It returns the
- * number of alias properties found, or an error code in case of failure.
+ * the global lookup table with the properties.
  */
 void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
 {
Signature · 1 line
2.34.1
maintainer
#17 lore raw

Re: [PATCH 07/10] of: Correct comments for of_alias_scan()

Quoted 6 lines · Zijun Hu

From: Zijun Hu <[email protected]>

Correct of_alias_scan() comments by:

- Replace /* with /** to start comments since it is not a API.

But it is because it's in of.h. However, you are correct in that it has no external callers. So please move the declaration to of_private.h.

Quoted 33 lines

- Delete return value descriptions since it is a void function.

---
 drivers/of/base.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/of/base.c +2 -4
index 1c62cda4ebcd9e3dc5f91d10fa68f975226693dd..33abb6227468c03fd191201aa2bbe05a41fdd9f4 100644
@@ -1812,14 +1812,13 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
                 ap->alias, ap->stem, ap->id, np);
 }
 
-/**
+/*
  * of_alias_scan - Scan all properties of the 'aliases' node
  * @dt_alloc:  An allocator that provides a virtual address to memory
  *             for storing the resulting tree
  *
  * The function scans all the properties of the 'aliases' node and populates
- * the global lookup table with the properties.  It returns the
- * number of alias properties found, or an error code in case of failure.
+ * the global lookup table with the properties.
  */
 void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
 {
 
--

2.34.1

author
#18 lore raw

Re: [PATCH 07/10] of: Correct comments for of_alias_scan()

Quoted 5 lines · Rob Herring
Quoted 1 line

- Replace /* with /** to start comments since it is not a API.

But it is because it's in of.h. However, you are correct in that it has no external callers. So please move the declaration to of_private.h.

thank you Rob for code review.
let me do it in next revision.

Quoted 1 line
Quoted 1 line

- Delete return value descriptions since it is a void function.

author
#19 lore raw

PATCH 8/10 of: Swap implementation between of_property_present() and of_property_read_bool()

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

of_property_present() is exactly same as of_property_read_bool().

Swap their implementation to make them more logical as shown below:
find property -> property is present or not -> boolean property value.

---
 include/linux/of.h | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
include/linux/of.h +12 -11
index f921786cb8ac782286ed5ff4425a35668204d050..7b0da8d352dffd8b872998903282119b6164a5bc 100644
@@ -1243,17 +1243,16 @@ static inline int of_property_read_string_index(const struct device_node *np,
 }
 
 /**
- * of_property_read_bool - Find a property
- * @np:		device node from which the property value is to be read.
+ * of_property_present - Test if a property is present in a node
+ * @np:		device node to search for the property.
  * @propname:	name of the property to be searched.
  *
- * Search for a boolean property in a device node. Usage on non-boolean
- * property types is deprecated.
+ * Test for a property present in a device node.
  *
  * Return: true if the property exists false otherwise.
  */
-static inline bool of_property_read_bool(const struct device_node *np,
-					 const char *propname)
+static inline bool of_property_present(const struct device_node *np,
+				       const char *propname)
 {
 	const struct property *prop = of_find_property(np, propname, NULL);
 
@@ -1261,17 +1260,19 @@ static inline bool of_property_read_bool(const struct device_node *np,
 }
 
 /**
- * of_property_present - Test if a property is present in a node
- * @np:		device node to search for the property.
+ * of_property_read_bool - Find a property
+ * @np:		device node from which the property value is to be read.
  * @propname:	name of the property to be searched.
  *
- * Test for a property present in a device node.
+ * Search for a boolean property in a device node. Usage on non-boolean
+ * property types is deprecated.
  *
  * Return: true if the property exists false otherwise.
  */
-static inline bool of_property_present(const struct device_node *np, const char *propname)
+static inline bool of_property_read_bool(const struct device_node *np,
+					 const char *propname)
 {
-	return of_property_read_bool(np, propname);
+	return of_property_present(np, propname);
 }
 
 /**
Signature · 1 line
2.34.1
author
#20 lore raw

PATCH 9/10 of: property: Implement of_fwnode_property_present() by of_property_present()

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

of_property_read_bool() is deprecated for non-boolean property, but of_fwnode_property_present() still uses it.

Fix by using of_property_present() instead of of_property_read_bool().

---
 drivers/of/property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/property.c +1 -1
index 519bf9229e613906547b57d8c68e7b8558eff327..dca1a3ebccae1093b2b11f51e8e692bca854d0e3 100644
@@ -966,7 +966,7 @@ of_fwnode_device_get_dma_attr(const struct fwnode_handle *fwnode)
 static bool of_fwnode_property_present(const struct fwnode_handle *fwnode,
 				       const char *propname)
 {
-	return of_property_read_bool(to_of_node(fwnode), propname);
+	return of_property_present(to_of_node(fwnode), propname);
 }
 
 static int of_fwnode_property_read_int_array(const struct fwnode_handle *fwnode,
Signature · 1 line
2.34.1
maintainer
#21 lore raw

Re: [PATCH 09/10] of: property: Implement of_fwnode_property_present() by of_property_present()

Quoted 7 lines · Zijun Hu

From: Zijun Hu <[email protected]>

of_property_read_bool() is deprecated for non-boolean property, but of_fwnode_property_present() still uses it.

Fix by using of_property_present() instead of of_property_read_bool().

of_property_present() just calls of_property_read_bool(). For now. I'm working on making using of_property_read_bool() on non-boolean a warning. No point in this change until that happens.

Rob

author
#22 lore raw

Re: [PATCH 09/10] of: property: Implement of_fwnode_property_present() by of_property_present()

Quoted 4 lines · Rob Herring
Quoted 3 lines · Zijun Hu

From: Zijun Hu <[email protected]>

Quoted 9 lines
Quoted 4 lines

of_property_read_bool() is deprecated for non-boolean property, but of_fwnode_property_present() still uses it.

Fix by using of_property_present() instead of of_property_read_bool().

of_property_present() just calls of_property_read_bool(). For now. I'm working on making using of_property_read_bool() on non-boolean a warning. No point in this change until that happens.

what about below idea?

replace all of_property_read_bool() usages with of_property_present() then remove the former.

Quoted 1 line

Rob

#23 lore raw

Re: [PATCH 09/10] of: property: Implement of_fwnode_property_present() by of_property_present()

Quoted 15 lines · Zijun Hu
Quoted 4 lines · Rob Herring
Quoted 3 lines · Zijun Hu

From: Zijun Hu <[email protected]>

Quoted 9 lines
Quoted 4 lines

of_property_read_bool() is deprecated for non-boolean property, but of_fwnode_property_present() still uses it.

Fix by using of_property_present() instead of of_property_read_bool().

of_property_present() just calls of_property_read_bool(). For now. I'm working on making using of_property_read_bool() on non-boolean a warning. No point in this change until that happens.

Quoted 4 lines

what about below idea?

replace all of_property_read_bool() usages with of_property_present() then remove the former.

No, the whole reason of_property_present() was added in the first place is because reading the effective "value" of a boolean property is a semantically different operation from checking whether a property of any type exists. Therefore (ab)using a single function for both purposes, whichever way round, is not an ideal API design. The fact that they both happen to share the same implementation at the moment is, as Rob says, not something we want to be tied to forever.

Thanks,
Robin.

author
#24 lore raw

PATCH 10/10 of: Simplify API of_find_node_with_property() implementation

In reply to Zijun Hu

From: Zijun Hu <[email protected]>

Simplify of_find_node_with_property() implementation by __of_find_property().

---
 drivers/of/base.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/of/base.c +3 -7
index 33abb6227468c03fd191201aa2bbe05a41fdd9f4..5fc061b66116d106c398f04a1d9d235f09741de7 100644
@@ -1026,19 +1026,15 @@ struct device_node *of_find_node_with_property(struct device_node *from,
 	const char *prop_name)
 {
 	struct device_node *np;
-	const struct property *pp;
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&devtree_lock, flags);
 	for_each_of_allnodes_from(from, np) {
-		for (pp = np->properties; pp; pp = pp->next) {
-			if (of_prop_cmp(pp->name, prop_name) == 0) {
-				of_node_get(np);
-				goto out;
-			}
+		if (__of_find_property(np, prop_name, NULL)) {
+			of_node_get(np);
+			break;
 		}
 	}
-out:
 	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
 	return np;
Signature · 1 line
2.34.1
maintainer Applied
#25 lore raw

Re: [PATCH 10/10] of: Simplify API of_find_node_with_property() implementation

Quoted 9 lines · Zijun Hu

From: Zijun Hu <[email protected]>

Simplify of_find_node_with_property() implementation by __of_find_property().

---
 drivers/of/base.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Applied, thanks.

Rob