Skip to contentSkip to conversation

of/device: Register children with a compatible value in of_platform_bus_probe()

PATCH In review Lan Chunhe 2 participants 6 messages Dec 10, 2010 – Dec 30, 2010 Device tree

lore
Share & tools
lore

Lan Chunhe

author
#0 lore raw

PATCH v2 3/3 of/device: Register children with a compatible value in of_platform_bus_probe()

Currently, of_platform_bus_probe() completely skips nodes which do not explicitly match the 'matches' table passed in. Or, if the root node matches, then it registers all the children unconditionally. However, there are situations, such as registering devices from the root node, when it is desirable to register child nodes, but only if they actually represent devices. For example, the root node may contain both a local bus and a PCI device, but it also contains the chosen, aliases and cpus nodes which don't represent real devices.

This patch changes of_platform_bus_probe() to register all nodes at the top level if they either match the matches table (the current behaviour), or if they have a 'compatible' value (indicating it represents a device).

---
 drivers/of/platform.c |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)
drivers/of/platform.c +23 -5
index 5b4a07f..02755ab 100644
@@ -714,6 +714,8 @@ int of_platform_bus_probe(struct device_node *root,
 	struct device_node *child;
 	struct platform_device *dev;
 	int rc = 0;
+	const void *compat;
+	const struct of_device_id *match;
 
 	if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE))
 		return -EINVAL;
@@ -741,16 +743,32 @@ int of_platform_bus_probe(struct device_node *root,
 		rc = of_platform_bus_create(root, matches, &dev->dev);
 		goto bail;
 	}
+
+	/*
+	 * Register each child node if either:
+	 *  a) it has a 'compatible' value indicating they are a device, or
+	 *  b) it is specified by the 'matches' table (by name or device_type)
+	 * If a node is specified in the matches table, then all its children
+	 * also get registered.
+	 */
 	for_each_child_of_node(root, child) {
-		if (!of_match_node(matches, child))
+		compat = of_get_property(child, "compatible", NULL);
+		match = of_match_node(matches, child);
+		if (!compat && !match)
 			continue;
 
-		pr_debug("  match: %s\n", child->full_name);
+		pr_debug("  register device: %s\n", child->full_name);
 		dev = of_platform_device_create(child, NULL, parent);
-		if (dev == NULL)
+		if (!dev) {
 			rc = -ENOMEM;
-		else
-			rc = of_platform_bus_create(child, matches, &dev->dev);
+			of_node_put(child);
+			break;
+		}
+		if (!match)
+			continue;
+
+		pr_debug("  register children of: %s\n", child->full_name);
+		rc = of_platform_bus_create(child, matches, &dev->dev);
 		if (rc) {
 			of_node_put(child);
 			break;
Signature · 1 line
1.5.4.5
#1 lore raw
Quoted 9 lines · Lan Chunhe

Currently, of_platform_bus_probe() completely skips nodes which do not explicitly match the 'matches' table passed in. Or, if the root node matches, then it registers all the children unconditionally. However, there are situations, such as registering devices from the root node, when it is desirable to register child nodes, but only if they actually represent devices. For example, the root node may contain both a local bus and a PCI device, but it also contains the chosen, aliases and cpus nodes which don't represent real devices.

Quoted 5 lines

This patch changes of_platform_bus_probe() to register all nodes at the top level if they either match the matches table (the current behaviour), or if they have a 'compatible' value (indicating it represents a device).

I believe this is my patch I wrote and pushed out to my tree back in October. Was this cherry-picked out of the test-devicetree branch?

Quoted 59 lines
---
 drivers/of/platform.c |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)
drivers/of/platform.c +23 -5
index 5b4a07f..02755ab 100644
@@ -714,6 +714,8 @@ int of_platform_bus_probe(struct device_node *root,
 	struct device_node *child;
 	struct platform_device *dev;
 	int rc = 0;
+	const void *compat;
+	const struct of_device_id *match;
 
 	if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE))
 		return -EINVAL;
@@ -741,16 +743,32 @@ int of_platform_bus_probe(struct device_node *root,
 		rc = of_platform_bus_create(root, matches, &dev->dev);
 		goto bail;
 	}
+
+	/*
+	 * Register each child node if either:
+	 *  a) it has a 'compatible' value indicating they are a device, or
+	 *  b) it is specified by the 'matches' table (by name or device_type)
+	 * If a node is specified in the matches table, then all its children
+	 * also get registered.
+	 */
 	for_each_child_of_node(root, child) {
-		if (!of_match_node(matches, child))
+		compat = of_get_property(child, "compatible", NULL);
+		match = of_match_node(matches, child);
+		if (!compat && !match)
 			continue;
 
-		pr_debug("  match: %s\n", child->full_name);
+		pr_debug("  register device: %s\n", child->full_name);
 		dev = of_platform_device_create(child, NULL, parent);
-		if (dev == NULL)
+		if (!dev) {
 			rc = -ENOMEM;
-		else
-			rc = of_platform_bus_create(child, matches, &dev->dev);
+			of_node_put(child);
+			break;
+		}
+		if (!match)
+			continue;
+
+		pr_debug("  register children of: %s\n", child->full_name);
+		rc = of_platform_bus_create(child, matches, &dev->dev);
 		if (rc) {
 			of_node_put(child);
 			break;
Signature · 1 line
1.5.4.5
author
#2 lore raw
Quoted 10 lines · Grant Likely
Quoted 9 lines · Lan Chunhe

Currently, of_platform_bus_probe() completely skips nodes which do not explicitly match the 'matches' table passed in. Or, if the root node matches, then it registers all the children unconditionally. However, there are situations, such as registering devices from the root node, when it is desirable to register child nodes, but only if they actually represent devices. For example, the root node may contain both a local bus and a PCI device, but it also contains the chosen, aliases and cpus nodes which don't represent real devices.

Quoted 8 lines
Quoted 5 lines

This patch changes of_platform_bus_probe() to register all nodes at the top level if they either match the matches table (the current behaviour), or if they have a 'compatible' value (indicating it represents a device).

I believe this is my patch I wrote and pushed out to my tree back in October. Was this cherry-picked out of the test-devicetree branch?

Yes, I will add the signed off with you.

Quoted 1 line
Quoted 1 line

At present I think that it is cherry-picked, and I have tested it which is OK.
Do you have better method?

Thanks.
-Lan

Quoted 61 lines
Quoted 60 lines
---
 drivers/of/platform.c |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)
drivers/of/platform.c +23 -5
index 5b4a07f..02755ab 100644
@@ -714,6 +714,8 @@ int of_platform_bus_probe(struct device_node *root,
 	struct device_node *child;
 	struct platform_device *dev;
 	int rc = 0;
+	const void *compat;
+	const struct of_device_id *match;
 
 	if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE))
 		return -EINVAL;
@@ -741,16 +743,32 @@ int of_platform_bus_probe(struct device_node  
 *root,
 		rc = of_platform_bus_create(root, matches, &dev->dev);
 		goto bail;
 	}
+
+	/*
+	 * Register each child node if either:
+	 *  a) it has a 'compatible' value indicating they are a device, or
+	 *  b) it is specified by the 'matches' table (by name or device_type)
+	 * If a node is specified in the matches table, then all its children
+	 * also get registered.
+	 */
 	for_each_child_of_node(root, child) {
-		if (!of_match_node(matches, child))
+		compat = of_get_property(child, "compatible", NULL);
+		match = of_match_node(matches, child);
+		if (!compat && !match)
 			continue;
 
-		pr_debug("  match: %s\n", child->full_name);
+		pr_debug("  register device: %s\n", child->full_name);
 		dev = of_platform_device_create(child, NULL, parent);
-		if (dev == NULL)
+		if (!dev) {
 			rc = -ENOMEM;
-		else
-			rc = of_platform_bus_create(child, matches, &dev->dev);
+			of_node_put(child);
+			break;
+		}
+		if (!match)
+			continue;
+
+		pr_debug("  register children of: %s\n", child->full_name);
+		rc = of_platform_bus_create(child, matches, &dev->dev);
 		if (rc) {
 			of_node_put(child);

break;
--
1.5.4.5

#3 lore raw
Quoted 24 lines · Lan Chunhe
Quoted 16 lines · Grant Likely
Quoted 15 lines · Lan Chunhe

Currently, of_platform_bus_probe() completely skips nodes which do not explicitly match the 'matches' table passed in. Or, if the root node matches, then it registers all the children unconditionally. However, there are situations, such as registering devices from the root node, when it is desirable to register child nodes, but only if they actually represent devices. For example, the root node may contain both a local bus and a PCI device, but it also contains the chosen, aliases and cpus nodes which don't represent real devices.

This patch changes of_platform_bus_probe() to register all nodes at the top level if they either match the matches table (the current behaviour),
or if they have a 'compatible' value (indicating it represents a device).

Quoted 4 lines
Quoted 1 line

I believe this is my patch I wrote and pushed out to my tree back in October. Was this cherry-picked out of the test-devicetree branch?

Quoted 8 lines

Yes, I will add the signed off with you.

Quoted 1 line
Quoted 1 line

At present I think that it is cherry-picked, and I have tested it which is OK.
Do you have better method?

You need to be very careful about stuff like this. Posting a patch without attribution of the original author and has the original signed-off-by lines stripped off is an absolute no-no. In literary circles this would be called plagiarism.

I don't think you did it intentionally, but proper attribution is a must, particularly because there are copyright issues involved.

As for this particular patch, I'm not particularly happy with it and I was planning to rewrite it. It is an inelegant solution and I think the registration of devices from the device tree can be made simpler instead of more complex like in this patch.

g.

Quoted 67 lines

Thanks.
-Lan

Quoted 61 lines
Quoted 60 lines

---
drivers/of/platform.c | 28 +++++++++++++++++++++++-----

1 files changed, 23 insertions(+), 5 deletions(-)
drivers/of/platform.c +23 -5
index 5b4a07f..02755ab 100644
@@ -714,6 +714,8 @@ int of_platform_bus_probe(struct device_node *root,
 	struct device_node *child;
 	struct platform_device *dev;
 	int rc = 0;
+	const void *compat;
+	const struct of_device_id *match;
 
 	if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE))
 		return -EINVAL;
@@ -741,16 +743,32 @@ int of_platform_bus_probe(struct
 device_node *root,
 		rc = of_platform_bus_create(root, matches, &dev->dev);
 		goto bail;
 	}
+
+	/*
+	 * Register each child node if either:
+	 *  a) it has a 'compatible' value indicating they are a device, or
+	 *  b) it is specified by the 'matches' table (by name or device_type)
+	 * If a node is specified in the matches table, then all its children
+	 * also get registered.
+	 */
 	for_each_child_of_node(root, child) {
-		if (!of_match_node(matches, child))
+		compat = of_get_property(child, "compatible", NULL);
+		match = of_match_node(matches, child);
+		if (!compat && !match)
 			continue;
 
-		pr_debug("  match: %s\n", child->full_name);
+		pr_debug("  register device: %s\n", child->full_name);
 		dev = of_platform_device_create(child, NULL, parent);
-		if (dev == NULL)
+		if (!dev) {
 			rc = -ENOMEM;
-		else
-			rc = of_platform_bus_create(child, matches, &dev->dev);
+			of_node_put(child);
+			break;
+		}
+		if (!match)
+			continue;
+
+		pr_debug("  register children of: %s\n", child->full_name);
+		rc = of_platform_bus_create(child, matches, &dev->dev);
 		if (rc) {
 			of_node_put(child);
			break;

--
1.5.4.5

author
#4 lore raw
Quoted 39 lines · Grant Likely
Quoted 30 lines · Lan Chunhe
Quoted 6 lines · Grant Likely
Quoted 5 lines · Lan Chunhe

Currently, of_platform_bus_probe() completely skips nodes which do not explicitly match the 'matches' table passed in. Or, if the root node matches, then it registers all the children unconditionally. However, there are situations, such as registering devices from the root node, when it is desirable to register child nodes, but only if they

actually

Quoted 1 line
Quoted 1 line

represent devices. For example, the root node may contain both a

local

Quoted 1 line
Quoted 1 line

bus and a PCI device, but it also contains the chosen, aliases and

cpus

Quoted 3 lines
Quoted 3 lines

nodes which don't represent real devices.

This patch changes of_platform_bus_probe() to register all nodes at

the

Quoted 9 lines
Quoted 6 lines

top level if they either match the matches table (the current behaviour),
or if they have a 'compatible' value (indicating it represents a device).

I believe this is my patch I wrote and pushed out to my tree back in October. Was this cherry-picked out of the test-devicetree branch?

Yes, I will add the signed off with you.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

At present I think that it is cherry-picked, and I have tested it
which
is OK.
Do you have better method?

Quoted 7 lines

You need to be very careful about stuff like this. Posting a patch without attribution of the original author and has the original signed-off-by lines stripped off is an absolute no-no. In literary circles this would be called plagiarism.

I don't think you did it intentionally, but proper attribution is a must, particularly because there are copyright issues involved.

Sorry, thank you that you remind me.

Quoted 4 lines

As for this particular patch, I'm not particularly happy with it and I was planning to rewrite it. It is an inelegant solution and I think the registration of devices from the device tree can be made simpler instead of more complex like in this patch.

Now this patch registers devices from the device tree. Then which function of which file do you will modify?

Thanks.
-Lan

Quoted 73 lines

g.

Quoted 70 lines

Thanks.
-Lan

Quoted 9 lines

drivers/of/platform.c int of_platform_bus_probe(struct device_node

Quoted 9 lines

---
drivers/of/platform.c | 28 +++++++++++++++++++++++-----

1 files changed, 23 insertions(+), 5 deletions(-)
drivers/of/platform.c +0 -0
index 5b4a07f..02755ab 100644
@@ -714,6 +714,8 @@ int of_platform_bus_probe(struct device_node  

*root,

Quoted 6 lines
Quoted 6 lines
drivers/of/platform.c +2 -0
 	struct device_node *child;
 	struct platform_device *dev;
 	int rc = 0;
+	const void *compat;
+	const struct of_device_id *match;
 
Quoted 12 lines

drivers/of/platform.c int of_platform_bus_probe(struct · line 751

Quoted 12 lines
drivers/of/platform.c +5 -0
 	if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE))
 		return -EINVAL;
@@ -741,16 +743,32 @@ int of_platform_bus_probe(struct
 device_node *root,
 		rc = of_platform_bus_create(root, matches, &dev->dev);
 		goto bail;
 	}
+
+	/*
+	 * Register each child node if either:
+	 *  a) it has a 'compatible' value indicating they are a device, or
+	 *  b) it is specified by the 'matches' table (by name or  

device_type)

Quoted 1 line

drivers/of/platform.c int of_platform_bus_probe(struct · line 752

Quoted 1 line
drivers/of/platform.c +1 -0
+	 * If a node is specified in the matches table, then all its  

children

Quoted 33 lines
Quoted 32 lines
drivers/of/platform.c +15 -5
+	 * also get registered.
+	 */
 	for_each_child_of_node(root, child) {
-		if (!of_match_node(matches, child))
+		compat = of_get_property(child, "compatible", NULL);
+		match = of_match_node(matches, child);
+		if (!compat && !match)
 			continue;
 
-		pr_debug("  match: %s\n", child->full_name);
+		pr_debug("  register device: %s\n", child->full_name);
 		dev = of_platform_device_create(child, NULL, parent);
-		if (dev == NULL)
+		if (!dev) {
 			rc = -ENOMEM;
-		else
-			rc = of_platform_bus_create(child, matches, &dev->dev);
+			of_node_put(child);
+			break;
+		}
+		if (!match)
+			continue;
+
+		pr_debug("  register children of: %s\n", child->full_name);
+		rc = of_platform_bus_create(child, matches, &dev->dev);
 		if (rc) {
 			of_node_put(child);
			break;

--
1.5.4.5

#5 lore raw
Quoted 52 lines · Lan Chunhe
Quoted 39 lines · Grant Likely
Quoted 30 lines · Lan Chunhe
Quoted 6 lines · Grant Likely
Quoted 5 lines · Lan Chunhe

Currently, of_platform_bus_probe() completely skips nodes which do not explicitly match the 'matches' table passed in. Or, if the root node matches, then it registers all the children unconditionally. However, there are situations, such as registering devices from the root node, when it is desirable to register child nodes, but only if they

actually

Quoted 1 line
Quoted 1 line

represent devices. For example, the root node may contain

both a local

Quoted 1 line
Quoted 1 line

bus and a PCI device, but it also contains the chosen, aliases

and cpus

Quoted 3 lines
Quoted 3 lines

nodes which don't represent real devices.

This patch changes of_platform_bus_probe() to register all

nodes at the

Quoted 9 lines
Quoted 6 lines

top level if they either match the matches table (the current behaviour),
or if they have a 'compatible' value (indicating it represents a device).

I believe this is my patch I wrote and pushed out to my tree back in October. Was this cherry-picked out of the test-devicetree branch?

Yes, I will add the signed off with you.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

At present I think that it is cherry-picked, and I have
tested it which
is OK.
Do you have better method?

Quoted 7 lines

You need to be very careful about stuff like this. Posting a patch without attribution of the original author and has the original signed-off-by lines stripped off is an absolute no-no. In literary circles this would be called plagiarism.

I don't think you did it intentionally, but proper attribution is a must, particularly because there are copyright issues involved.

Sorry, thank you that you remind me.

Quoted 7 lines
Quoted 4 lines

As for this particular patch, I'm not particularly happy with it and I was planning to rewrite it. It is an inelegant solution and I think the registration of devices from the device tree can be made simpler instead of more complex like in this patch.

Now this patch registers devices from the device tree. Then which function of which file do you will modify?

I'm thinking about deprecating the whole recursive device registration entirely and instead making child device registration always the responsibility of a device driver. That would mean each bus node would bind to a simple device driver that registers the child platform devices in the .probe() hook.

g.