Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1702643 > unrolled thread

[PATCH v2 1/5] of/platform: Generalize /reserved-memory handling

Started byBjorn Andersson <bjorn.andersson@linaro.org>
First post2017-08-03 05:00 +0200
Last post2017-08-04 01:40 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v2 1/5] of/platform: Generalize /reserved-memory handling Bjorn Andersson <bjorn.andersson@linaro.org> - 2017-08-03 05:00 +0200
    Re: [PATCH v2 1/5] of/platform: Generalize /reserved-memory handling Rob Herring <robh+dt@kernel.org> - 2017-08-03 19:50 +0200
      Re: [PATCH v2 1/5] of/platform: Generalize /reserved-memory handling Bjorn Andersson <bjorn.andersson@linaro.org> - 2017-08-04 01:40 +0200

#1702643 — [PATCH v2 1/5] of/platform: Generalize /reserved-memory handling

FromBjorn Andersson <bjorn.andersson@linaro.org>
Date2017-08-03 05:00 +0200
Subject[PATCH v2 1/5] of/platform: Generalize /reserved-memory handling
Message-ID<uaewG-224-21@gated-at.bofh.it>
By iterating over all /reserved-memory child nodes and match each one to
a list of compatibles that we want to treat specially, we can easily
extend the list of compatibles to handle - without having to resort to
of_platform_populate() that would create unnecessary platform_devices.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---

Changes since v1:
- New patch

 drivers/of/platform.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index b19524623498..8c241a116b08 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -497,23 +497,32 @@ int of_platform_default_populate(struct device_node *root,
 EXPORT_SYMBOL_GPL(of_platform_default_populate);
 
 #ifndef CONFIG_PPC
+static const char *rmem_compats[] = {
+	"ramoops",
+	NULL
+};
+
 static int __init of_platform_default_populate_init(void)
 {
+	struct device_node *rmem_nodes;
 	struct device_node *node;
+	int ret;
 
 	if (!of_have_populated_dt())
 		return -ENODEV;
 
 	/*
-	 * Handle ramoops explicitly, since it is inside /reserved-memory,
-	 * which lacks a "compatible" property.
+	 * Handle certain compatibles explicitly, since we don't want to create
+	 * platform_devices for every node in /reserved-memory with a
+	 * "compatible",
 	 */
-	node = of_find_node_by_path("/reserved-memory");
-	if (node) {
-		node = of_find_compatible_node(node, NULL, "ramoops");
-		if (node)
+	rmem_nodes = of_find_node_by_path("/reserved-memory");
+	for_each_available_child_of_node(rmem_nodes, node) {
+		ret = of_device_compatible_match(node, rmem_compats);
+		if (ret)
 			of_platform_device_create(node, NULL, NULL);
 	}
+	of_node_put(rmem_nodes);
 
 	/* Populate everything else. */
 	of_platform_default_populate(NULL, NULL, NULL);
-- 
2.12.0

[toc] | [next] | [standalone]


#1703310

FromRob Herring <robh+dt@kernel.org>
Date2017-08-03 19:50 +0200
Message-ID<uaspZ-3iy-27@gated-at.bofh.it>
In reply to#1702643
On Wed, Aug 2, 2017 at 9:57 PM, Bjorn Andersson
<bjorn.andersson@linaro.org> wrote:
> By iterating over all /reserved-memory child nodes and match each one to
> a list of compatibles that we want to treat specially, we can easily
> extend the list of compatibles to handle - without having to resort to
> of_platform_populate() that would create unnecessary platform_devices.
>
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
>
> Changes since v1:
> - New patch
>
>  drivers/of/platform.c | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index b19524623498..8c241a116b08 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -497,23 +497,32 @@ int of_platform_default_populate(struct device_node *root,
>  EXPORT_SYMBOL_GPL(of_platform_default_populate);
>
>  #ifndef CONFIG_PPC
> +static const char *rmem_compats[] = {
> +       "ramoops",
> +       NULL
> +};
> +
>  static int __init of_platform_default_populate_init(void)
>  {
> +       struct device_node *rmem_nodes;
>         struct device_node *node;
> +       int ret;
>
>         if (!of_have_populated_dt())
>                 return -ENODEV;
>
>         /*
> -        * Handle ramoops explicitly, since it is inside /reserved-memory,
> -        * which lacks a "compatible" property.
> +        * Handle certain compatibles explicitly, since we don't want to create
> +        * platform_devices for every node in /reserved-memory with a
> +        * "compatible",
>          */
> -       node = of_find_node_by_path("/reserved-memory");
> -       if (node) {
> -               node = of_find_compatible_node(node, NULL, "ramoops");
> -               if (node)
> +       rmem_nodes = of_find_node_by_path("/reserved-memory");
> +       for_each_available_child_of_node(rmem_nodes, node) {
> +               ret = of_device_compatible_match(node, rmem_compats);
> +               if (ret)

I would just do:

for_each_matching_node(node, ...)
    of_platform_device_create(node, NULL, NULL);

I don't think the kernel has to validate that ramoops and any others
we add are children of /reserved-memory. We should only have those
compatibles located there and any other location would be an error.

>                         of_platform_device_create(node, NULL, NULL);
>         }
> +       of_node_put(rmem_nodes);
>
>         /* Populate everything else. */
>         of_platform_default_populate(NULL, NULL, NULL);
> --
> 2.12.0
>

[toc] | [prev] | [next] | [standalone]


#1703544

FromBjorn Andersson <bjorn.andersson@linaro.org>
Date2017-08-04 01:40 +0200
Message-ID<uaxSG-7aD-15@gated-at.bofh.it>
In reply to#1703310
On Thu 03 Aug 10:40 PDT 2017, Rob Herring wrote:

> On Wed, Aug 2, 2017 at 9:57 PM, Bjorn Andersson
> <bjorn.andersson@linaro.org> wrote:
> > diff --git a/drivers/of/platform.c b/drivers/of/platform.c
[..]
> > +       rmem_nodes = of_find_node_by_path("/reserved-memory");
> > +       for_each_available_child_of_node(rmem_nodes, node) {
> > +               ret = of_device_compatible_match(node, rmem_compats);
> > +               if (ret)
> 
> I would just do:
> 
> for_each_matching_node(node, ...)
>     of_platform_device_create(node, NULL, NULL);
> 
> I don't think the kernel has to validate that ramoops and any others
> we add are children of /reserved-memory. We should only have those
> compatibles located there and any other location would be an error.
> 

Okay, looks reasonable.

Will update and resend once I know your decision on 2/5.

Regards,
Bjorn

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web