2022-06-24 03:58:12

by Frank Rowand

[permalink] [raw]
Subject: [PATCH 2/2] of: unittest: treat missing of_root as error instead of fixing up

From: Frank Rowand <[email protected]>

setup_of() now ensures that of_root node is populated with the
root of a default devicetree. Remove the unittest code that
created of_root if it was missing. Verify that of_root is
valid before attempting to attach the testcase-data subtree.

Signed-off-by: Frank Rowand <[email protected]>
---
drivers/of/unittest.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 7f6bba18c515..9d106998c1f2 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1469,20 +1469,16 @@ static int __init unittest_data_add(void)
return -EINVAL;
}

- if (!of_root) {
- of_root = unittest_data_node;
- for_each_of_allnodes(np)
- __of_attach_node_sysfs(np);
- of_aliases = of_find_node_by_path("/aliases");
- of_chosen = of_find_node_by_path("/chosen");
- of_overlay_mutex_unlock();
- return 0;
- }
-
EXPECT_BEGIN(KERN_INFO,
"Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");

/* attach the sub-tree to live tree */
+ if (!of_root) {
+ pr_warn("%s: no live tree to attach sub-tree\n", __func__);
+ kfree(unittest_data);
+ return -ENODEV;
+ }
+
np = unittest_data_node->child;
while (np) {
struct device_node *next = np->sibling;
--
Frank Rowand <[email protected]>


2022-06-28 14:42:13

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH 2/2] of: unittest: treat missing of_root as error instead of fixing up

On Thu, Jun 23, 2022 at 10:43:27PM -0500, [email protected] wrote:
> From: Frank Rowand <[email protected]>
>
> setup_of() now ensures that of_root node is populated with the
> root of a default devicetree. Remove the unittest code that
> created of_root if it was missing. Verify that of_root is
> valid before attempting to attach the testcase-data subtree.

What happened with the formatting here?

>
> Signed-off-by: Frank Rowand <[email protected]>
> ---
> drivers/of/unittest.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index 7f6bba18c515..9d106998c1f2 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -1469,20 +1469,16 @@ static int __init unittest_data_add(void)
> return -EINVAL;
> }
>
> - if (!of_root) {
> - of_root = unittest_data_node;
> - for_each_of_allnodes(np)
> - __of_attach_node_sysfs(np);
> - of_aliases = of_find_node_by_path("/aliases");
> - of_chosen = of_find_node_by_path("/chosen");
> - of_overlay_mutex_unlock();
> - return 0;
> - }
> -
> EXPECT_BEGIN(KERN_INFO,
> "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
>
> /* attach the sub-tree to live tree */
> + if (!of_root) {
> + pr_warn("%s: no live tree to attach sub-tree\n", __func__);
> + kfree(unittest_data);
> + return -ENODEV;
> + }
> +
> np = unittest_data_node->child;
> while (np) {
> struct device_node *next = np->sibling;
> --
> Frank Rowand <[email protected]>
>
>

2022-06-28 19:52:07

by Frank Rowand

[permalink] [raw]
Subject: Re: [PATCH 2/2] of: unittest: treat missing of_root as error instead of fixing up

On 6/28/22 10:36, Rob Herring wrote:
> On Thu, Jun 23, 2022 at 10:43:27PM -0500, [email protected] wrote:
>> From: Frank Rowand <[email protected]>
>>
>> setup_of() now ensures that of_root node is populated with the
>> root of a default devicetree. Remove the unittest code that
>> created of_root if it was missing. Verify that of_root is
>> valid before attempting to attach the testcase-data subtree.
>
> What happened with the formatting here?

I'm guessing you are referring to the leading space?

I pasted the text from another file into the commit message in
my repo and failed to remove the leading blank. So a "typo"
on my part.

-Frank

>
>>
>> Signed-off-by: Frank Rowand <[email protected]>
>> ---
>> drivers/of/unittest.c | 16 ++++++----------
>> 1 file changed, 6 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
>> index 7f6bba18c515..9d106998c1f2 100644
>> --- a/drivers/of/unittest.c
>> +++ b/drivers/of/unittest.c
>> @@ -1469,20 +1469,16 @@ static int __init unittest_data_add(void)
>> return -EINVAL;
>> }
>>
>> - if (!of_root) {
>> - of_root = unittest_data_node;
>> - for_each_of_allnodes(np)
>> - __of_attach_node_sysfs(np);
>> - of_aliases = of_find_node_by_path("/aliases");
>> - of_chosen = of_find_node_by_path("/chosen");
>> - of_overlay_mutex_unlock();
>> - return 0;
>> - }
>> -
>> EXPECT_BEGIN(KERN_INFO,
>> "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
>>
>> /* attach the sub-tree to live tree */
>> + if (!of_root) {
>> + pr_warn("%s: no live tree to attach sub-tree\n", __func__);
>> + kfree(unittest_data);
>> + return -ENODEV;
>> + }
>> +
>> np = unittest_data_node->child;
>> while (np) {
>> struct device_node *next = np->sibling;
>> --
>> Frank Rowand <[email protected]>
>>
>>