All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Removes OF_UNITTEST dependency on OF_DYNAMIC config symbol
@ 2015-01-11  7:19 Gaurav Minocha
       [not found] ` <1420960791-26761-1-git-send-email-gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Gaurav Minocha @ 2015-01-11  7:19 UTC (permalink / raw)
  To: devicetree-u79uwXL29TY76Z2rM5mHXA
  Cc: grant.likely-QSEj5FYQhm4dnm+yROfE0A,
	rob.herring-QSEj5FYQhm4dnm+yROfE0A, Gaurav Minocha

This patch intends to remove the unittests dependency on
the functions defined in dynamic.c. So, rather than calling
of_attach_node defined in dynamic.c, minimal functionality
required to attach a new node is re-defined in unittest.c.
Also, now after executing the tests the test data is not
removed from the device tree so there is no need to call
of_detach_node.

Tested with and without OF_DYNAMIC enabled on ppc, arm and
x86

Signed-off-by: Gaurav Minocha <gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/of/Kconfig    |  1 -
 drivers/of/unittest.c | 70 +++++++++------------------------------------------
 2 files changed, 12 insertions(+), 59 deletions(-)

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index b5e0c87..38d1c51 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -10,7 +10,6 @@ menu "Device Tree and Open Firmware support"
 config OF_UNITTEST
 	bool "Device Tree runtime unit tests"
 	depends on OF_IRQ && OF_EARLY_FLATTREE
-	select OF_DYNAMIC
 	select OF_RESOLVE
 	help
 	  This option builds in test cases for the device tree infrastructure
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 844838e..139363a 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -822,6 +822,7 @@ static void update_node_properties(struct device_node *np,
 static int attach_node_and_children(struct device_node *np)
 {
 	struct device_node *next, *dup, *child;
+	unsigned long flags;
 
 	dup = of_find_node_by_path(np->full_name);
 	if (dup) {
@@ -838,8 +839,17 @@ static int attach_node_and_children(struct device_node *np)
 
 	child = np->child;
 	np->child = NULL;
-	np->sibling = NULL;
-	of_attach_node(np);
+
+	mutex_lock(&of_mutex);
+	raw_spin_lock_irqsave(&devtree_lock, flags);
+	np->sibling = np->parent->child;
+	np->parent->child = np;
+	of_node_clear_flag(np, OF_DETACHED);
+	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+
+	__of_attach_node_sysfs(np);
+	mutex_unlock(&of_mutex);
+
 	while (child) {
 		next = child->sibling;
 		attach_node_and_children(child);
@@ -911,59 +921,6 @@ static int __init selftest_data_add(void)
 	return 0;
 }
 
-/**
- *	detach_node_and_children - detaches node
- *	and its children from live tree
- *
- *	@np:	Node to detach from live tree
- */
-static void detach_node_and_children(struct device_node *np)
-{
-	while (np->child)
-		detach_node_and_children(np->child);
-	of_detach_node(np);
-}
-
-/**
- *	selftest_data_remove - removes the selftest data
- *	nodes from the live tree
- */
-static void selftest_data_remove(void)
-{
-	struct device_node *np;
-	struct property *prop;
-
-	if (selftest_live_tree) {
-		of_node_put(of_aliases);
-		of_node_put(of_chosen);
-		of_aliases = NULL;
-		of_chosen = NULL;
-		for_each_child_of_node(of_root, np)
-			detach_node_and_children(np);
-		__of_detach_node_sysfs(of_root);
-		of_root = NULL;
-		return;
-	}
-
-	while (last_node_index-- > 0) {
-		if (nodes[last_node_index]) {
-			np = of_find_node_by_path(nodes[last_node_index]->full_name);
-			if (np == nodes[last_node_index]) {
-				if (of_aliases == np) {
-					of_node_put(of_aliases);
-					of_aliases = NULL;
-				}
-				detach_node_and_children(np);
-			} else {
-				for_each_property_of_node(np, prop) {
-					if (strcmp(prop->name, "testcase-alias") == 0)
-						of_remove_property(np, prop);
-				}
-			}
-		}
-	}
-}
-
 #ifdef CONFIG_OF_OVERLAY
 
 static int selftest_probe(struct platform_device *pdev)
@@ -1475,9 +1432,6 @@ static int __init of_selftest(void)
 	of_selftest_platform_populate();
 	of_selftest_overlay();
 
-	/* removing selftest data from live tree */
-	selftest_data_remove();
-
 	/* Double check linkage after removing testcase data */
 	of_selftest_check_tree_linkage();
 
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Removes OF_UNITTEST dependency on OF_DYNAMIC config symbol
       [not found] ` <1420960791-26761-1-git-send-email-gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2015-01-13 20:06   ` Rob Herring
  2015-01-22 16:56   ` Grant Likely
  2015-01-23 13:03   ` Geert Uytterhoeven
  2 siblings, 0 replies; 5+ messages in thread
From: Rob Herring @ 2015-01-13 20:06 UTC (permalink / raw)
  To: Gaurav Minocha
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, Grant Likely, Rob Herring

On Sun, Jan 11, 2015 at 1:19 AM, Gaurav Minocha
<gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> This patch intends to remove the unittests dependency on
> the functions defined in dynamic.c. So, rather than calling
> of_attach_node defined in dynamic.c, minimal functionality
> required to attach a new node is re-defined in unittest.c.
> Also, now after executing the tests the test data is not
> removed from the device tree so there is no need to call
> of_detach_node.
>
> Tested with and without OF_DYNAMIC enabled on ppc, arm and
> x86
>
> Signed-off-by: Gaurav Minocha <gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Applied for 3.20. Thanks.

> ---
>  drivers/of/Kconfig    |  1 -
>  drivers/of/unittest.c | 70 +++++++++------------------------------------------
>  2 files changed, 12 insertions(+), 59 deletions(-)
>
> diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
> index b5e0c87..38d1c51 100644
> --- a/drivers/of/Kconfig
> +++ b/drivers/of/Kconfig
> @@ -10,7 +10,6 @@ menu "Device Tree and Open Firmware support"
>  config OF_UNITTEST
>         bool "Device Tree runtime unit tests"
>         depends on OF_IRQ && OF_EARLY_FLATTREE
> -       select OF_DYNAMIC
>         select OF_RESOLVE
>         help
>           This option builds in test cases for the device tree infrastructure
> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index 844838e..139363a 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -822,6 +822,7 @@ static void update_node_properties(struct device_node *np,
>  static int attach_node_and_children(struct device_node *np)
>  {
>         struct device_node *next, *dup, *child;
> +       unsigned long flags;
>
>         dup = of_find_node_by_path(np->full_name);
>         if (dup) {
> @@ -838,8 +839,17 @@ static int attach_node_and_children(struct device_node *np)
>
>         child = np->child;
>         np->child = NULL;
> -       np->sibling = NULL;
> -       of_attach_node(np);
> +
> +       mutex_lock(&of_mutex);
> +       raw_spin_lock_irqsave(&devtree_lock, flags);
> +       np->sibling = np->parent->child;
> +       np->parent->child = np;
> +       of_node_clear_flag(np, OF_DETACHED);
> +       raw_spin_unlock_irqrestore(&devtree_lock, flags);
> +
> +       __of_attach_node_sysfs(np);
> +       mutex_unlock(&of_mutex);
> +
>         while (child) {
>                 next = child->sibling;
>                 attach_node_and_children(child);
> @@ -911,59 +921,6 @@ static int __init selftest_data_add(void)
>         return 0;
>  }
>
> -/**
> - *     detach_node_and_children - detaches node
> - *     and its children from live tree
> - *
> - *     @np:    Node to detach from live tree
> - */
> -static void detach_node_and_children(struct device_node *np)
> -{
> -       while (np->child)
> -               detach_node_and_children(np->child);
> -       of_detach_node(np);
> -}
> -
> -/**
> - *     selftest_data_remove - removes the selftest data
> - *     nodes from the live tree
> - */
> -static void selftest_data_remove(void)
> -{
> -       struct device_node *np;
> -       struct property *prop;
> -
> -       if (selftest_live_tree) {
> -               of_node_put(of_aliases);
> -               of_node_put(of_chosen);
> -               of_aliases = NULL;
> -               of_chosen = NULL;
> -               for_each_child_of_node(of_root, np)
> -                       detach_node_and_children(np);
> -               __of_detach_node_sysfs(of_root);
> -               of_root = NULL;
> -               return;
> -       }
> -
> -       while (last_node_index-- > 0) {
> -               if (nodes[last_node_index]) {
> -                       np = of_find_node_by_path(nodes[last_node_index]->full_name);
> -                       if (np == nodes[last_node_index]) {
> -                               if (of_aliases == np) {
> -                                       of_node_put(of_aliases);
> -                                       of_aliases = NULL;
> -                               }
> -                               detach_node_and_children(np);
> -                       } else {
> -                               for_each_property_of_node(np, prop) {
> -                                       if (strcmp(prop->name, "testcase-alias") == 0)
> -                                               of_remove_property(np, prop);
> -                               }
> -                       }
> -               }
> -       }
> -}
> -
>  #ifdef CONFIG_OF_OVERLAY
>
>  static int selftest_probe(struct platform_device *pdev)
> @@ -1475,9 +1432,6 @@ static int __init of_selftest(void)
>         of_selftest_platform_populate();
>         of_selftest_overlay();
>
> -       /* removing selftest data from live tree */
> -       selftest_data_remove();
> -
>         /* Double check linkage after removing testcase data */
>         of_selftest_check_tree_linkage();
>
> --
> 2.1.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Removes OF_UNITTEST dependency on OF_DYNAMIC config symbol
       [not found] ` <1420960791-26761-1-git-send-email-gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2015-01-13 20:06   ` Rob Herring
@ 2015-01-22 16:56   ` Grant Likely
       [not found]     ` <20150122165601.E4BA6C40A80-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
  2015-01-23 13:03   ` Geert Uytterhoeven
  2 siblings, 1 reply; 5+ messages in thread
From: Grant Likely @ 2015-01-22 16:56 UTC (permalink / raw)
  To: devicetree-u79uwXL29TY76Z2rM5mHXA
  Cc: rob.herring-QSEj5FYQhm4dnm+yROfE0A, Gaurav Minocha

On Sat, 10 Jan 2015 23:19:51 -0800
, Gaurav Minocha <gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
 wrote:
> This patch intends to remove the unittests dependency on
> the functions defined in dynamic.c. So, rather than calling
> of_attach_node defined in dynamic.c, minimal functionality
> required to attach a new node is re-defined in unittest.c.
> Also, now after executing the tests the test data is not
> removed from the device tree so there is no need to call
> of_detach_node.
> 
> Tested with and without OF_DYNAMIC enabled on ppc, arm and
> x86
> 
> Signed-off-by: Gaurav Minocha <gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Looks good, but it leaves in some stale node removal code. I've fixed it
up and applied for v3.19. Here is my fixup:

---

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 139363af5c88..28beed1b3c2c 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -27,11 +27,6 @@ static struct selftest_results {
 	int failed;
 } selftest_results;
 
-#define NO_OF_NODES 3
-static struct device_node *nodes[NO_OF_NODES];
-static int last_node_index;
-static bool selftest_live_tree;
-
 #define selftest(result, fmt, ...) ({ \
 	bool failed = !(result); \
 	if (failed) { \
@@ -830,13 +825,6 @@ static int attach_node_and_children(struct device_node *np)
 		return 0;
 	}
 
-	/* Children of the root need to be remembered for removal */
-	if (np->parent == of_root) {
-		if (WARN_ON(last_node_index >= NO_OF_NODES))
-			return -EINVAL;
-		nodes[last_node_index++] = np;
-	}
-
 	child = np->child;
 	np->child = NULL;
 
@@ -899,8 +887,6 @@ static int __init selftest_data_add(void)
 	}
 
 	if (!of_root) {
-		/* enabling flag for removing nodes */
-		selftest_live_tree = true;
 		of_root = selftest_data_node;
 
 		for_each_of_allnodes(np)

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Removes OF_UNITTEST dependency on OF_DYNAMIC config symbol
       [not found]     ` <20150122165601.E4BA6C40A80-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
@ 2015-01-22 16:59       ` Grant Likely
  0 siblings, 0 replies; 5+ messages in thread
From: Grant Likely @ 2015-01-22 16:59 UTC (permalink / raw)
  To: Gaurav Minocha, devicetree-u79uwXL29TY76Z2rM5mHXA; +Cc: Rob Herring

On Thu, Jan 22, 2015 at 4:56 PM, Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
> On Sat, 10 Jan 2015 23:19:51 -0800
> , Gaurav Minocha <gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>  wrote:
>> This patch intends to remove the unittests dependency on
>> the functions defined in dynamic.c. So, rather than calling
>> of_attach_node defined in dynamic.c, minimal functionality
>> required to attach a new node is re-defined in unittest.c.
>> Also, now after executing the tests the test data is not
>> removed from the device tree so there is no need to call
>> of_detach_node.
>>
>> Tested with and without OF_DYNAMIC enabled on ppc, arm and
>> x86
>>
>> Signed-off-by: Gaurav Minocha <gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>
> Looks good, but it leaves in some stale node removal code. I've fixed it
> up and applied for v3.19. Here is my fixup:

On reflection, picking this up for v3.19 is a bad decision because it
is not a regression fix. I'll submit a separate fixup patch to remove
the stale code.

g.

>
> ---
>
> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index 139363af5c88..28beed1b3c2c 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -27,11 +27,6 @@ static struct selftest_results {
>         int failed;
>  } selftest_results;
>
> -#define NO_OF_NODES 3
> -static struct device_node *nodes[NO_OF_NODES];
> -static int last_node_index;
> -static bool selftest_live_tree;
> -
>  #define selftest(result, fmt, ...) ({ \
>         bool failed = !(result); \
>         if (failed) { \
> @@ -830,13 +825,6 @@ static int attach_node_and_children(struct device_node *np)
>                 return 0;
>         }
>
> -       /* Children of the root need to be remembered for removal */
> -       if (np->parent == of_root) {
> -               if (WARN_ON(last_node_index >= NO_OF_NODES))
> -                       return -EINVAL;
> -               nodes[last_node_index++] = np;
> -       }
> -
>         child = np->child;
>         np->child = NULL;
>
> @@ -899,8 +887,6 @@ static int __init selftest_data_add(void)
>         }
>
>         if (!of_root) {
> -               /* enabling flag for removing nodes */
> -               selftest_live_tree = true;
>                 of_root = selftest_data_node;
>
>                 for_each_of_allnodes(np)
>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Removes OF_UNITTEST dependency on OF_DYNAMIC config symbol
       [not found] ` <1420960791-26761-1-git-send-email-gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2015-01-13 20:06   ` Rob Herring
  2015-01-22 16:56   ` Grant Likely
@ 2015-01-23 13:03   ` Geert Uytterhoeven
  2 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2015-01-23 13:03 UTC (permalink / raw)
  To: Gaurav Minocha
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, Grant Likely, Rob Herring

On Sun, Jan 11, 2015 at 8:19 AM, Gaurav Minocha
<gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> This patch intends to remove the unittests dependency on
> the functions defined in dynamic.c. So, rather than calling
> of_attach_node defined in dynamic.c, minimal functionality
> required to attach a new node is re-defined in unittest.c.
> Also, now after executing the tests the test data is not
> removed from the device tree so there is no need to call
> of_detach_node.

Could there be unwanted side effects of not removing the test data?

> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c

> @@ -1475,9 +1432,6 @@ static int __init of_selftest(void)
>         of_selftest_platform_populate();
>         of_selftest_overlay();
>
> -       /* removing selftest data from live tree */
> -       selftest_data_remove();
> -
>         /* Double check linkage after removing testcase data */

You forgot to remove the comment above.

>         of_selftest_check_tree_linkage();

Is this test still relevant now the testcase data has been removed?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-01-23 13:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-11  7:19 [PATCH v2] Removes OF_UNITTEST dependency on OF_DYNAMIC config symbol Gaurav Minocha
     [not found] ` <1420960791-26761-1-git-send-email-gaurav.minocha.os-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-01-13 20:06   ` Rob Herring
2015-01-22 16:56   ` Grant Likely
     [not found]     ` <20150122165601.E4BA6C40A80-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2015-01-22 16:59       ` Grant Likely
2015-01-23 13:03   ` Geert Uytterhoeven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.