of: fix bugs and improve codes
Subsystems (2)
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]>
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.
--- drivers/of/base.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/of/base.c +3 -3
@@ -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
Rob Herring
maintainerRe: [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 19The 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()")Signed-off-by Zijun Hu <[email protected]>--- drivers/of/base.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/of/base.c +3
-4@@ -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
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()")Signed-off-by Zijun Hu <[email protected]>--- drivers/of/base.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/of/base.c +3
-4@@ -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
PATCH 2/10 of: Correct return value for API of_parse_phandle_with_args_map()
In reply to Zijun HuFrom: 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.
--- drivers/of/base.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/of/base.c +2 -0
@@ -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
Rob Herring
maintainerRe: [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-EINVALbefore 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
-EINVALafter the operation.
Already have a similar fix queued up.
Rob
PATCH 3/10 of: Correct child specifier used as input of the 2nd nexus node
In reply to Zijun HuFrom: 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.
--- drivers/of/base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/base.c +1 -1
@@ -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
PATCH 4/10 of: Fix refcount leakage for OF node returned by __of_get_dma_parent()
In reply to Zijun HuFrom: 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().
--- drivers/of/address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/address.c +1 -1
@@ -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
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 bothof_parse_phandle_with_args()andof_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")Signed-off-by Zijun Hu <[email protected]>--- drivers/of/address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks.
Rob
PATCH 5/10 of: Fix available buffer size calculating error in API of_device_uevent_modalias()
In reply to Zijun HuFrom: 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).
--- drivers/of/device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/of/device.c +2 -2
@@ -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
Rob Herring
maintainerRe: [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")Signed-off-by Zijun Hu <[email protected]>--- drivers/of/device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/of/device.c +0
-0
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
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")Signed-off-by Zijun Hu <[email protected]>--- drivers/of/device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/of/device.c +0
-0drivers/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_varwork to construct the full value. We could add "%pOFm" format that callsof_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
Rob Herring
maintainerRe: [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")Signed-off-by Zijun Hu <[email protected]>--- drivers/of/device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/of/device.c +0
-0drivers/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->buflenandenv->envp_idxare 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_varwork to construct the full value. We could add "%pOFm" format that callsof_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
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->buflenandenv->envp_idxare 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 theadd_uevent_var()call updatedenv->buflenandenv->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. (^^)
PATCH 6/10 of/fdt: Dump __be32 array in CPU type order in of_dump_addr()
In reply to Zijun HuFrom: 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
@@ -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
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__be32array 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.Signed-off-by Zijun Hu <[email protected]>--- drivers/of/fdt_address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks.
Rob
PATCH 7/10 of: Correct comments for of_alias_scan()
In reply to Zijun HuFrom: 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
@@ -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
Rob Herring
maintainerRe: [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.
Signed-off-by Zijun Hu <[email protected]>--- drivers/of/base.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/of/base.c +2
-4@@ -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
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 toof_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.
PATCH 8/10 of: Swap implementation between of_property_present() and of_property_read_bool()
In reply to Zijun HuFrom: 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
@@ -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
PATCH 9/10 of: property: Implement of_fwnode_property_present() by of_property_present()
In reply to Zijun HuFrom: 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
@@ -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
Rob Herring
maintainerRe: [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, butof_fwnode_property_present()still uses it.Fix by using
of_property_present()instead ofof_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
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, butof_fwnode_property_present()still uses it.Fix by using
of_property_present()instead ofof_property_read_bool().
of_property_present()just callsof_property_read_bool(). For now. I'm working on making usingof_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
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, butof_fwnode_property_present()still uses it.Fix by using
of_property_present()instead ofof_property_read_bool().
of_property_present()just callsof_property_read_bool(). For now. I'm working on making usingof_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 withof_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.
PATCH 10/10 of: Simplify API of_find_node_with_property() implementation
In reply to Zijun HuFrom: 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
@@ -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
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().Signed-off-by Zijun Hu <[email protected]>--- drivers/of/base.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
Applied, thanks.
Rob