Skip to contentSkip to conversation

drm: convert DT component matching to component_match_add_release()

PATCH In review Russell King 12 participants 20 messages Jun 3, 2016 – Jun 15, 2016 2 messages not in the archive

Subsystems (16)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: convert DT component matching to component_match_add_release()

Convert DT component matching to use component_match_add_release().

---
 drivers/gpu/drm/arm/hdlcd_drv.c             | 10 ++++++++--
 drivers/gpu/drm/armada/armada_drv.c         |  9 +++++++--
 drivers/gpu/drm/drm_of.c                    | 13 +++++++++----
 drivers/gpu/drm/msm/msm_drv.c               |  8 +++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 13 ++++++++++---
 drivers/gpu/drm/sti/sti_drv.c               |  9 +++++++--
 drivers/gpu/drm/tilcdc/tilcdc_external.c    |  9 +++++++--
 7 files changed, 55 insertions(+), 16 deletions(-)
drivers/gpu/drm/arm/hdlcd_drv.c +8 -2
index b987c63ba8d6..bbde48c4f550 100644
@@ -443,11 +443,16 @@ static const struct component_master_ops hdlcd_master_ops = {
 	.unbind		= hdlcd_drm_unbind,
 };
 
-static int compare_dev(struct device *dev, void *data)
+static int compare_of(struct device *dev, void *data)
 {
 	return dev->of_node == data;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 static int hdlcd_probe(struct platform_device *pdev)
 {
 	struct device_node *port, *ep;
@@ -474,7 +479,8 @@ static int hdlcd_probe(struct platform_device *pdev)
 		return -EAGAIN;
 	}
 
-	component_match_add(&pdev->dev, &match, compare_dev, port);
+	component_match_add_release(&pdev->dev, &match, release_of,
+				    compare_of, port);
 
 	return component_master_add_with_match(&pdev->dev, &hdlcd_master_ops,
 					       match);
drivers/gpu/drm/armada/armada_drv.c +7 -2
index 439824a61aa5..6ca2aa36515e 100644
@@ -232,6 +232,11 @@ static int compare_of(struct device *dev, void *data)
 	return dev->of_node == data;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 static int compare_dev_name(struct device *dev, void *data)
 {
 	const char *name = data;
@@ -255,8 +260,8 @@ static void armada_add_endpoints(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, match, compare_of, remote);
-		of_node_put(remote);
+		component_match_add_release(dev, match, release_of,
+					    compare_of, remote);
 	}
 }
 
drivers/gpu/drm/drm_of.c +9 -4
index bc98bb94264d..5d183479d7d6 100644
@@ -6,6 +6,11 @@
 #include <drm/drm_crtc.h>
 #include <drm/drm_of.h>
 
+static void drm_release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 /**
  * drm_crtc_port_mask - find the mask of a registered CRTC by port OF node
  * @dev: DRM device
@@ -101,8 +106,8 @@ int drm_of_component_probe(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, &match, compare_of, port);
-		of_node_put(port);
+		component_match_add_release(dev, &match, drm_release_of,
+					    compare_of, port);
 	}
 
 	if (i == 0) {
@@ -140,8 +145,8 @@ int drm_of_component_probe(struct device *dev,
 				continue;
 			}
 
-			component_match_add(dev, &match, compare_of, remote);
-			of_node_put(remote);
+			component_match_add_release(dev, &match, drm_release_of,
+						    compare_of, remote);
 		}
 		of_node_put(port);
 	}
drivers/gpu/drm/msm/msm_drv.c +7 -1
index 9c654092ef78..1f7de47d817e 100644
@@ -805,6 +805,11 @@ static int compare_of(struct device *dev, void *data)
 	return dev->of_node == data;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 static int add_components(struct device *dev, struct component_match **matchptr,
 		const char *name)
 {
@@ -818,7 +823,8 @@ static int add_components(struct device *dev, struct component_match **matchptr,
 		if (!node)
 			break;
 
-		component_match_add(dev, matchptr, compare_of, node);
+		component_match_add_release(dev, matchptr, release_of,
+					    compare_of, node);
 	}
 
 	return 0;
drivers/gpu/drm/rockchip/rockchip_drm_drv.c +10 -3
index a409d1f703cb..f5a68fc031ed 100644
@@ -421,6 +421,11 @@ static int compare_of(struct device *dev, void *data)
 	return dev->of_node == np;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 static void rockchip_add_endpoints(struct device *dev,
 				   struct component_match **match,
 				   struct device_node *port)
@@ -439,8 +444,8 @@ static void rockchip_add_endpoints(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, match, compare_of, remote);
-		of_node_put(remote);
+		component_match_add_release(dev, match, release_of,
+					    compare_of, remote);
 	}
 }
 
@@ -518,7 +523,9 @@ static int rockchip_drm_platform_probe(struct platform_device *pdev)
 			is_support_iommu = false;
 		}
 
-		component_match_add(dev, &match, compare_of, port->parent);
+		of_node_get(port->parent);
+		component_match_add_release(dev, &match, release_of,
+					    compare_of, port->parent);
 		of_node_put(port);
 	}
 
drivers/gpu/drm/sti/sti_drv.c +7 -2
index 872495e72294..4ee6fa4f1beb 100644
@@ -346,6 +346,11 @@ static int compare_of(struct device *dev, void *data)
 	return dev->of_node == data;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 static int sti_bind(struct device *dev)
 {
 	return drm_platform_init(&sti_driver, to_platform_device(dev));
@@ -375,8 +380,8 @@ static int sti_platform_probe(struct platform_device *pdev)
 	child_np = of_get_next_available_child(node, NULL);
 
 	while (child_np) {
-		component_match_add(dev, &match, compare_of, child_np);
-		of_node_put(child_np);
+		component_match_add_release(dev, &match, release_of,
+					    compare_of, child_np);
 		child_np = of_get_next_available_child(node, child_np);
 	}
 
drivers/gpu/drm/tilcdc/tilcdc_external.c +7 -2
index 03acb4f99982..7e11b5ecdd4a 100644
@@ -135,6 +135,11 @@ static int dev_match_of(struct device *dev, void *data)
 	return dev->of_node == data;
 }
 
+static void dev_release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 int tilcdc_get_external_components(struct device *dev,
 				   struct component_match **match)
 {
@@ -152,8 +157,8 @@ int tilcdc_get_external_components(struct device *dev,
 
 		dev_dbg(dev, "Subdevice node '%s' found\n", node->name);
 		if (match)
-			component_match_add(dev, match, dev_match_of, node);
-		of_node_put(node);
+			component_match_add_release(dev, match, dev_release_of,
+						    dev_match_of, node);
 		count++;
 	}
 
Signature · 1 line
2.1.0
maintainer Reviewed-by Acked-by on v1 1/1
#1 lore raw
Quoted 1 line · Russell King

Convert DT component matching to use component_match_add_release().

Hi Russell,

Any reason for not keeping the component_match_add() calls in the drivers? Planning to remove it?

Quoted 2 lines

Looks good to me!

For the HDLCD part:

Thanks,
Liviu

Quoted 234 lines
---
 drivers/gpu/drm/arm/hdlcd_drv.c             | 10 ++++++++--
 drivers/gpu/drm/armada/armada_drv.c         |  9 +++++++--
 drivers/gpu/drm/drm_of.c                    | 13 +++++++++----
 drivers/gpu/drm/msm/msm_drv.c               |  8 +++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 13 ++++++++++---
 drivers/gpu/drm/sti/sti_drv.c               |  9 +++++++--
 drivers/gpu/drm/tilcdc/tilcdc_external.c    |  9 +++++++--
 7 files changed, 55 insertions(+), 16 deletions(-)
drivers/gpu/drm/arm/hdlcd_drv.c +8 -2
index b987c63ba8d6..bbde48c4f550 100644
@@ -443,11 +443,16 @@ static const struct component_master_ops hdlcd_master_ops = {
 	.unbind		= hdlcd_drm_unbind,
 };
 
-static int compare_dev(struct device *dev, void *data)
+static int compare_of(struct device *dev, void *data)
 {
 	return dev->of_node == data;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 static int hdlcd_probe(struct platform_device *pdev)
 {
 	struct device_node *port, *ep;
@@ -474,7 +479,8 @@ static int hdlcd_probe(struct platform_device *pdev)
 		return -EAGAIN;
 	}
 
-	component_match_add(&pdev->dev, &match, compare_dev, port);
+	component_match_add_release(&pdev->dev, &match, release_of,
+				    compare_of, port);
 
 	return component_master_add_with_match(&pdev->dev, &hdlcd_master_ops,
 					       match);
drivers/gpu/drm/armada/armada_drv.c +7 -2
index 439824a61aa5..6ca2aa36515e 100644
@@ -232,6 +232,11 @@ static int compare_of(struct device *dev, void *data)
 	return dev->of_node == data;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 static int compare_dev_name(struct device *dev, void *data)
 {
 	const char *name = data;
@@ -255,8 +260,8 @@ static void armada_add_endpoints(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, match, compare_of, remote);
-		of_node_put(remote);
+		component_match_add_release(dev, match, release_of,
+					    compare_of, remote);
 	}
 }
 
drivers/gpu/drm/drm_of.c +9 -4
index bc98bb94264d..5d183479d7d6 100644
@@ -6,6 +6,11 @@
 #include <drm/drm_crtc.h>
 #include <drm/drm_of.h>
 
+static void drm_release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 /**
  * drm_crtc_port_mask - find the mask of a registered CRTC by port OF node
  * @dev: DRM device
@@ -101,8 +106,8 @@ int drm_of_component_probe(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, &match, compare_of, port);
-		of_node_put(port);
+		component_match_add_release(dev, &match, drm_release_of,
+					    compare_of, port);
 	}
 
 	if (i == 0) {
@@ -140,8 +145,8 @@ int drm_of_component_probe(struct device *dev,
 				continue;
 			}
 
-			component_match_add(dev, &match, compare_of, remote);
-			of_node_put(remote);
+			component_match_add_release(dev, &match, drm_release_of,
+						    compare_of, remote);
 		}
 		of_node_put(port);
 	}
drivers/gpu/drm/msm/msm_drv.c +7 -1
index 9c654092ef78..1f7de47d817e 100644
@@ -805,6 +805,11 @@ static int compare_of(struct device *dev, void *data)
 	return dev->of_node == data;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 static int add_components(struct device *dev, struct component_match **matchptr,
 		const char *name)
 {
@@ -818,7 +823,8 @@ static int add_components(struct device *dev, struct component_match **matchptr,
 		if (!node)
 			break;
 
-		component_match_add(dev, matchptr, compare_of, node);
+		component_match_add_release(dev, matchptr, release_of,
+					    compare_of, node);
 	}
 
 	return 0;
drivers/gpu/drm/rockchip/rockchip_drm_drv.c +10 -3
index a409d1f703cb..f5a68fc031ed 100644
@@ -421,6 +421,11 @@ static int compare_of(struct device *dev, void *data)
 	return dev->of_node == np;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 static void rockchip_add_endpoints(struct device *dev,
 				   struct component_match **match,
 				   struct device_node *port)
@@ -439,8 +444,8 @@ static void rockchip_add_endpoints(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, match, compare_of, remote);
-		of_node_put(remote);
+		component_match_add_release(dev, match, release_of,
+					    compare_of, remote);
 	}
 }
 
@@ -518,7 +523,9 @@ static int rockchip_drm_platform_probe(struct platform_device *pdev)
 			is_support_iommu = false;
 		}
 
-		component_match_add(dev, &match, compare_of, port->parent);
+		of_node_get(port->parent);
+		component_match_add_release(dev, &match, release_of,
+					    compare_of, port->parent);
 		of_node_put(port);
 	}
 
drivers/gpu/drm/sti/sti_drv.c +7 -2
index 872495e72294..4ee6fa4f1beb 100644
@@ -346,6 +346,11 @@ static int compare_of(struct device *dev, void *data)
 	return dev->of_node == data;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 static int sti_bind(struct device *dev)
 {
 	return drm_platform_init(&sti_driver, to_platform_device(dev));
@@ -375,8 +380,8 @@ static int sti_platform_probe(struct platform_device *pdev)
 	child_np = of_get_next_available_child(node, NULL);
 
 	while (child_np) {
-		component_match_add(dev, &match, compare_of, child_np);
-		of_node_put(child_np);
+		component_match_add_release(dev, &match, release_of,
+					    compare_of, child_np);
 		child_np = of_get_next_available_child(node, child_np);
 	}
 
drivers/gpu/drm/tilcdc/tilcdc_external.c +7 -2
index 03acb4f99982..7e11b5ecdd4a 100644
@@ -135,6 +135,11 @@ static int dev_match_of(struct device *dev, void *data)
 	return dev->of_node == data;
 }
 
+static void dev_release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
 int tilcdc_get_external_components(struct device *dev,
 				   struct component_match **match)
 {
@@ -152,8 +157,8 @@ int tilcdc_get_external_components(struct device *dev,
 
 		dev_dbg(dev, "Subdevice node '%s' found\n", node->name);
 		if (match)
-			component_match_add(dev, match, dev_match_of, node);
-		of_node_put(node);
+			component_match_add_release(dev, match, dev_release_of,
+						    dev_match_of, node);
 		count++;
 	}
 
Signature · 7 lines
2.1.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 6 lines · Liviu Dudau
Quoted 1 line · Russell King

Convert DT component matching to use component_match_add_release().

Hi Russell,

Any reason for not keeping the component_match_add() calls in the drivers?

Sorry, I don't understand your comment.

If we kept component_match_add() in these drivers, then this patch would not exist, because there wouldn't be any changes to the drivers.

Quoted 1 line

Planning to remove it?

Possibly in the longer term, but at the moment there are drivers where the match data that is passed does not need any release functionality eg, data allocated with devm_k*alloc(), or

	component_match_add(dev->parent, match, dss_component_compare, dev);

There are some new cases that need converting which have cropped up during the last merge window, and I expect this to be an on-going educational point for driver authors, so I'm not too bothered about capturing all existing cases in this patch.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
reviewer
#5 lore raw
In reply to Russell King

Hi Russell,

Quoted 21 lines · Russell King

Convert DT component matching to use component_match_add_release().

---
  drivers/gpu/drm/arm/hdlcd_drv.c             | 10 ++++++++--
  drivers/gpu/drm/armada/armada_drv.c         |  9 +++++++--
  drivers/gpu/drm/drm_of.c                    | 13 +++++++++----
  drivers/gpu/drm/msm/msm_drv.c               |  8 +++++++-
  drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 13 ++++++++++---
  drivers/gpu/drm/sti/sti_drv.c               |  9 +++++++--
  drivers/gpu/drm/tilcdc/tilcdc_external.c    |  9 +++++++--
  7 files changed, 55 insertions(+), 16 deletions(-)
drivers/gpu/drm/arm/hdlcd_drv.c +0 -0
index b987c63ba8d6..bbde48c4f550 100644
@@ -443,11 +443,16 @@ static const struct component_master_ops hdlcd_master_ops = {
  	.unbind		= hdlcd_drm_unbind,
  };
 

drivers/gpu/drm/arm/hdlcd_drv.c static const struct component_master_ops hdlcd_master_ops = { · line 454

Quoted 10 lines
drivers/gpu/drm/arm/hdlcd_drv.c +5 -1
-static int compare_dev(struct device *dev, void *data)
+static int compare_of(struct device *dev, void *data)
  {
  	return dev->of_node == data;
  }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}

Considering that there's 7 identical copies of this function in this patch alone, perhaps there's some mileage in defining it commonly as a static __maybe_unused default_release_of() in component.h or drm_of.h (and maybe default_compare_of() similarly)?

(Apologies if there's already been some strong argument against that which I've not seen, but it seems like a reasonable thing to do.)

Robin.

Quoted 198 lines
drivers/gpu/drm/arm/hdlcd_drv.c +3 -1
+
  static int hdlcd_probe(struct platform_device *pdev)
  {
  	struct device_node *port, *ep;
@@ -474,7 +479,8 @@ static int hdlcd_probe(struct platform_device *pdev)
  		return -EAGAIN;
  	}
 
-	component_match_add(&pdev->dev, &match, compare_dev, port);
+	component_match_add_release(&pdev->dev, &match, release_of,
+				    compare_of, port);
 
  	return component_master_add_with_match(&pdev->dev, &hdlcd_master_ops,
  					       match);
drivers/gpu/drm/armada/armada_drv.c +7 -2
index 439824a61aa5..6ca2aa36515e 100644
@@ -232,6 +232,11 @@ static int compare_of(struct device *dev, void *data)
  	return dev->of_node == data;
  }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
  static int compare_dev_name(struct device *dev, void *data)
  {
  	const char *name = data;
@@ -255,8 +260,8 @@ static void armada_add_endpoints(struct device *dev,
  			continue;
  		}
 
-		component_match_add(dev, match, compare_of, remote);
-		of_node_put(remote);
+		component_match_add_release(dev, match, release_of,
+					    compare_of, remote);
  	}
  }
 
drivers/gpu/drm/drm_of.c +9 -4
index bc98bb94264d..5d183479d7d6 100644
@@ -6,6 +6,11 @@
  #include <drm/drm_crtc.h>
  #include <drm/drm_of.h>
 
+static void drm_release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
  /**
   * drm_crtc_port_mask - find the mask of a registered CRTC by port OF node
   * @dev: DRM device
@@ -101,8 +106,8 @@ int drm_of_component_probe(struct device *dev,
  			continue;
  		}
 
-		component_match_add(dev, &match, compare_of, port);
-		of_node_put(port);
+		component_match_add_release(dev, &match, drm_release_of,
+					    compare_of, port);
  	}
 
  	if (i == 0) {
@@ -140,8 +145,8 @@ int drm_of_component_probe(struct device *dev,
  				continue;
  			}
 
-			component_match_add(dev, &match, compare_of, remote);
-			of_node_put(remote);
+			component_match_add_release(dev, &match, drm_release_of,
+						    compare_of, remote);
  		}
  		of_node_put(port);
  	}
drivers/gpu/drm/msm/msm_drv.c +7 -1
index 9c654092ef78..1f7de47d817e 100644
@@ -805,6 +805,11 @@ static int compare_of(struct device *dev, void *data)
  	return dev->of_node == data;
  }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
  static int add_components(struct device *dev, struct component_match **matchptr,
  		const char *name)
  {
@@ -818,7 +823,8 @@ static int add_components(struct device *dev, struct component_match **matchptr,
  		if (!node)
  			break;
 
-		component_match_add(dev, matchptr, compare_of, node);
+		component_match_add_release(dev, matchptr, release_of,
+					    compare_of, node);
  	}
 
  	return 0;
drivers/gpu/drm/rockchip/rockchip_drm_drv.c +10 -3
index a409d1f703cb..f5a68fc031ed 100644
@@ -421,6 +421,11 @@ static int compare_of(struct device *dev, void *data)
  	return dev->of_node == np;
  }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
  static void rockchip_add_endpoints(struct device *dev,
  				   struct component_match **match,
  				   struct device_node *port)
@@ -439,8 +444,8 @@ static void rockchip_add_endpoints(struct device *dev,
  			continue;
  		}
 
-		component_match_add(dev, match, compare_of, remote);
-		of_node_put(remote);
+		component_match_add_release(dev, match, release_of,
+					    compare_of, remote);
  	}
  }
 
@@ -518,7 +523,9 @@ static int rockchip_drm_platform_probe(struct platform_device *pdev)
  			is_support_iommu = false;
  		}
 
-		component_match_add(dev, &match, compare_of, port->parent);
+		of_node_get(port->parent);
+		component_match_add_release(dev, &match, release_of,
+					    compare_of, port->parent);
  		of_node_put(port);
  	}
 
drivers/gpu/drm/sti/sti_drv.c +7 -2
index 872495e72294..4ee6fa4f1beb 100644
@@ -346,6 +346,11 @@ static int compare_of(struct device *dev, void *data)
  	return dev->of_node == data;
  }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
  static int sti_bind(struct device *dev)
  {
  	return drm_platform_init(&sti_driver, to_platform_device(dev));
@@ -375,8 +380,8 @@ static int sti_platform_probe(struct platform_device *pdev)
  	child_np = of_get_next_available_child(node, NULL);
 
  	while (child_np) {
-		component_match_add(dev, &match, compare_of, child_np);
-		of_node_put(child_np);
+		component_match_add_release(dev, &match, release_of,
+					    compare_of, child_np);
  		child_np = of_get_next_available_child(node, child_np);
  	}
 
drivers/gpu/drm/tilcdc/tilcdc_external.c +7 -2
index 03acb4f99982..7e11b5ecdd4a 100644
@@ -135,6 +135,11 @@ static int dev_match_of(struct device *dev, void *data)
  	return dev->of_node == data;
  }
 
+static void dev_release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}
+
  int tilcdc_get_external_components(struct device *dev,
  				   struct component_match **match)
  {
@@ -152,8 +157,8 @@ int tilcdc_get_external_components(struct device *dev,
 
  		dev_dbg(dev, "Subdevice node '%s' found\n", node->name);
  		if (match)
-			component_match_add(dev, match, dev_match_of, node);
-		of_node_put(node);
+			component_match_add_release(dev, match, dev_release_of,
+						    dev_match_of, node);
  		count++;
  	}
 
maintainer
#3 lore raw
In reply to Russell King - ARM Linux
Quoted 9 lines · Russell King - ARM Linux
Quoted 6 lines · Liviu Dudau
Quoted 1 line · Russell King

Convert DT component matching to use component_match_add_release().

Hi Russell,

Any reason for not keeping the component_match_add() calls in the drivers?

Sorry, I don't understand your comment.

As in: component_match_add() already exists as a macro that calls component_match_add_release(), but with a NULL release function. If it were to be changed to pass a default release_of() function then most of the drivers would not have to change, right? It is just one point of view and I was curious if there was a reason not to choose it, as it would have (probably) generated a smaller delta?

Quoted 10 lines

If we kept component_match_add() in these drivers, then this patch would not exist, because there wouldn't be any changes to the drivers.

Quoted 1 line

Planning to remove it?

Possibly in the longer term, but at the moment there are drivers where the match data that is passed does not need any release functionality eg, data allocated with devm_k*alloc(), or

Quoted 6 lines
	component_match_add(dev->parent, match, dss_component_compare, dev);

There are some new cases that need converting which have cropped up during the last merge window, and I expect this to be an on-going educational point for driver authors, so I'm not too bothered about capturing all existing cases in this patch.

Understood. Using managed allocators is definitely a strong point in favor of having the component_match_add() function with a NULL release() hook.

Best regards,
Liviu

Quoted 6 lines
Signature · 4 lines
-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
#4 lore raw
Quoted 9 lines · Liviu Dudau
Quoted 8 lines · Russell King - ARM Linux
Quoted 6 lines · Liviu Dudau
Quoted 1 line · Russell King

Convert DT component matching to use component_match_add_release().

Hi Russell,

Any reason for not keeping the component_match_add() calls in the drivers?

Quoted 8 lines
Quoted 1 line

Sorry, I don't understand your comment.

As in: component_match_add() already exists as a macro that calls component_match_add_release(), but with a NULL release function. If it were to be changed to pass a default release_of() function then most of the drivers would not have to change, right? It is just one point of view and I was curious if there was a reason not to choose it, as it would have (probably) generated a smaller delta?

And what should the calls that don't pass a DT node be called? What happens to new users who aren't passing a DT node but use component_match_add() ?

What you're suggesting sound totally insane to me: you're making the change a flag-day: component_match_add() currently takes anything as the data pointer and users can pass anything that their compare function can handle - and changing that to a function which can only take a device_node. That means all non-DT users of that function need to change at the same time.

Flag days are really bad news in kernel development (or any distributed development project), and I won't generate a patch which causes a flag day to occur - especially not one which impacts a large number of users.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#6 lore raw
In reply to Robin Murphy
Quoted 40 lines · Robin Murphy

Hi Russell,

Quoted 21 lines · Russell King

Convert DT component matching to use component_match_add_release().

---
 drivers/gpu/drm/arm/hdlcd_drv.c             | 10 ++++++++--
 drivers/gpu/drm/armada/armada_drv.c         |  9 +++++++--
 drivers/gpu/drm/drm_of.c                    | 13 +++++++++----
 drivers/gpu/drm/msm/msm_drv.c               |  8 +++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 13 ++++++++++---
 drivers/gpu/drm/sti/sti_drv.c               |  9 +++++++--
 drivers/gpu/drm/tilcdc/tilcdc_external.c    |  9 +++++++--
 7 files changed, 55 insertions(+), 16 deletions(-)
drivers/gpu/drm/arm/hdlcd_drv.c +0 -0
index b987c63ba8d6..bbde48c4f550 100644
@@ -443,11 +443,16 @@ static const struct component_master_ops hdlcd_master_ops = {
 	.unbind		= hdlcd_drm_unbind,
 };
 

drivers/gpu/drm/arm/hdlcd_drv.c static const struct component_master_ops hdlcd_master_ops = { · line 454

Quoted 10 lines
drivers/gpu/drm/arm/hdlcd_drv.c +5 -1
-static int compare_dev(struct device *dev, void *data)
+static int compare_of(struct device *dev, void *data)
 {
 	return dev->of_node == data;
 }
 
+static void release_of(struct device *dev, void *data)
+{
+	of_node_put(data);
+}

Considering that there's 7 identical copies of this function in this patch alone, perhaps there's some mileage in defining it commonly as a static __maybe_unused default_release_of() in component.h or drm_of.h (and maybe default_compare_of() similarly)?

Quoted 2 lines

(Apologies if there's already been some strong argument against that which I've not seen, but it seems like a reasonable thing to do.)

What we could do is extract out the common bits of OF-component matching into drivers/of/of_component.c and make the whole thing a tad better. I'll send a v2 series threaded to this message.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#7 lore raw

PATCH v2 1/3 of: add common OF-based component functionality

Add common OF-based component functionality for matching devices by device node, and releasing the device node at the appropraite time.

---
 drivers/of/Makefile          |  2 +-
 drivers/of/of_component.c    | 41 +++++++++++++++++++++++++++++++++++++++++
 include/linux/of_component.h | 14 ++++++++++++++
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 drivers/of/of_component.c
 create mode 100644 include/linux/of_component.h
drivers/of/Makefile +1 -1
index d7efd9d458aa..6a4a5e2c0839 100644
@@ -1,4 +1,4 @@
-obj-y = base.o device.o platform.o
+obj-y = base.o of_component.o device.o platform.o
 obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
 obj-$(CONFIG_OF_FLATTREE) += fdt.o
 obj-$(CONFIG_OF_EARLY_FLATTREE) += fdt_address.o
drivers/of/of_component.c new file +41 -0

41 lines not on this page · raw message

include/linux/of_component.h new file +14 -0
new file mode 100644
index 000000000000..a8170ba3b786
@@ -0,0 +1,14 @@
+#ifndef __LINUX_COMPONENT_OF_H
+#define __LINUX_COMPONENT_OF_H
+
+struct component_match;
+struct device;
+struct device_node;
+
+void component_match_add_of_compare(struct device *master,
+	struct component_match **matchptr,
+	int (*compare)(struct device *, void *), struct device_node *node);
+void component_match_add_of(struct device *master,
+	struct component_match **matchptr, struct device_node *node);
+
+#endif
Signature · 1 line
2.1.0
#14 lore raw

PATCH v2 2/3 drm: convert DT component matching to component_match_add_release()

In reply to Russell King - ARM Linux

Convert DT component matching to use component_match_add_release().

---
 drivers/gpu/drm/arm/hdlcd_drv.c             |  9 +++------
 drivers/gpu/drm/armada/armada_drv.c         |  8 ++------
 drivers/gpu/drm/drm_of.c                    |  6 ++++--
 drivers/gpu/drm/etnaviv/etnaviv_drv.c       | 11 ++---------
 drivers/gpu/drm/msm/msm_drv.c               |  8 ++------
 drivers/gpu/drm/msm/msm_drv.h               |  1 +
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 12 +++---------
 drivers/gpu/drm/sti/sti_drv.c               |  9 ++-------
 drivers/gpu/drm/tilcdc/tilcdc_external.c    |  8 ++------
 9 files changed, 21 insertions(+), 51 deletions(-)
drivers/gpu/drm/arm/hdlcd_drv.c +3 -6
index b987c63ba8d6..f00845c25795 100644
@@ -14,6 +14,7 @@
 #include <linux/clk.h>
 #include <linux/component.h>
 #include <linux/list.h>
+#include <linux/of_component.h>
 #include <linux/of_graph.h>
 #include <linux/of_reserved_mem.h>
 #include <linux/pm_runtime.h>
@@ -443,11 +444,6 @@ static const struct component_master_ops hdlcd_master_ops = {
 	.unbind		= hdlcd_drm_unbind,
 };
 
-static int compare_dev(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 static int hdlcd_probe(struct platform_device *pdev)
 {
 	struct device_node *port, *ep;
@@ -474,7 +470,8 @@ static int hdlcd_probe(struct platform_device *pdev)
 		return -EAGAIN;
 	}
 
-	component_match_add(&pdev->dev, &match, compare_dev, port);
+	component_match_add_of(&pdev->dev, &match, port);
+	of_node_put(port);
 
 	return component_master_add_with_match(&pdev->dev, &hdlcd_master_ops,
 					       match);
drivers/gpu/drm/armada/armada_drv.c +2 -6
index 439824a61aa5..f2716d20c257 100644
@@ -9,6 +9,7 @@
 #include <linux/component.h>
 #include <linux/module.h>
 #include <linux/of_graph.h>
+#include <linux/of_component.h>
 #include <drm/drmP.h>
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_of.h>
@@ -227,11 +228,6 @@ static void armada_drm_unbind(struct device *dev)
 	drm_put_dev(dev_get_drvdata(dev));
 }
 
-static int compare_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 static int compare_dev_name(struct device *dev, void *data)
 {
 	const char *name = data;
@@ -255,7 +251,7 @@ static void armada_add_endpoints(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, match, compare_of, remote);
+		component_match_add_of(dev, match, remote);
 		of_node_put(remote);
 	}
 }
drivers/gpu/drm/drm_of.c +4 -2
index bc98bb94264d..d13fc633aeea 100644
@@ -1,6 +1,7 @@
 #include <linux/component.h>
 #include <linux/export.h>
 #include <linux/list.h>
+#include <linux/of_component.h>
 #include <linux/of_graph.h>
 #include <drm/drmP.h>
 #include <drm/drm_crtc.h>
@@ -101,7 +102,7 @@ int drm_of_component_probe(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, &match, compare_of, port);
+		component_match_add_of(dev, &match, compare_of, port);
 		of_node_put(port);
 	}
 
@@ -140,7 +141,8 @@ int drm_of_component_probe(struct device *dev,
 				continue;
 			}
 
-			component_match_add(dev, &match, compare_of, remote);
+			component_match_add_of_compare(dev, &match, compare_of,
+						       remote);
 			of_node_put(remote);
 		}
 		of_node_put(port);
drivers/gpu/drm/etnaviv/etnaviv_drv.c +2 -9
index 3d4f56df8359..a0e0764a6269 100644
@@ -15,6 +15,7 @@
  */
 
 #include <linux/component.h>
+#include <linux/of_component.h>
 #include <linux/of_platform.h>
 
 #include "etnaviv_drv.h"
@@ -606,13 +607,6 @@ static const struct component_master_ops etnaviv_master_ops = {
 	.unbind = etnaviv_unbind,
 };
 
-static int compare_of(struct device *dev, void *data)
-{
-	struct device_node *np = data;
-
-	return dev->of_node == np;
-}
-
 static int compare_str(struct device *dev, void *data)
 {
 	return !strcmp(dev_name(dev), data);
@@ -635,8 +629,7 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)
 			if (!core_node)
 				break;
 
-			component_match_add(&pdev->dev, &match, compare_of,
-					    core_node);
+			component_match_add_of(&pdev->dev, &match, core_node);
 			of_node_put(core_node);
 		}
 	} else if (dev->platform_data) {
drivers/gpu/drm/msm/msm_drv.c +2 -6
index 9c654092ef78..5293aa775c5a 100644
@@ -800,11 +800,6 @@ static const struct dev_pm_ops msm_pm_ops = {
  * NOTE: duplication of the same code as exynos or imx (or probably any other).
  * so probably some room for some helpers
  */
-static int compare_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 static int add_components(struct device *dev, struct component_match **matchptr,
 		const char *name)
 {
@@ -818,7 +813,8 @@ static int add_components(struct device *dev, struct component_match **matchptr,
 		if (!node)
 			break;
 
-		component_match_add(dev, matchptr, compare_of, node);
+		component_match_add_of(dev, matchptr, node);
+		of_node_put(node);
 	}
 
 	return 0;
drivers/gpu/drm/msm/msm_drv.h +1 -0
index 5b2963f32291..66dafecaf115 100644
@@ -30,6 +30,7 @@
 #include <linux/list.h>
 #include <linux/iommu.h>
 #include <linux/types.h>
+#include <linux/of_component.h>
 #include <linux/of_graph.h>
 #include <linux/of_device.h>
 #include <asm/sizes.h>
drivers/gpu/drm/rockchip/rockchip_drm_drv.c +3 -9
index a409d1f703cb..84c50f6770c3 100644
@@ -22,6 +22,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/pm_runtime.h>
 #include <linux/module.h>
+#include <linux/of_component.h>
 #include <linux/of_graph.h>
 #include <linux/component.h>
 
@@ -414,13 +415,6 @@ static const struct dev_pm_ops rockchip_drm_pm_ops = {
 				rockchip_drm_sys_resume)
 };
 
-static int compare_of(struct device *dev, void *data)
-{
-	struct device_node *np = data;
-
-	return dev->of_node == np;
-}
-
 static void rockchip_add_endpoints(struct device *dev,
 				   struct component_match **match,
 				   struct device_node *port)
@@ -439,7 +433,7 @@ static void rockchip_add_endpoints(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, match, compare_of, remote);
+		component_match_add_of(dev, match, remote);
 		of_node_put(remote);
 	}
 }
@@ -518,7 +512,7 @@ static int rockchip_drm_platform_probe(struct platform_device *pdev)
 			is_support_iommu = false;
 		}
 
-		component_match_add(dev, &match, compare_of, port->parent);
+		component_match_add_of(dev, &match, port->parent);
 		of_node_put(port);
 	}
 
drivers/gpu/drm/sti/sti_drv.c +2 -7
index 872495e72294..aeb2787c9bd4 100644
@@ -10,6 +10,7 @@
 #include <linux/debugfs.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of_component.h>
 #include <linux/of_platform.h>
 
 #include <drm/drm_atomic.h>
@@ -341,11 +342,6 @@ static struct drm_driver sti_driver = {
 	.minor = DRIVER_MINOR,
 };
 
-static int compare_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 static int sti_bind(struct device *dev)
 {
 	return drm_platform_init(&sti_driver, to_platform_device(dev));
@@ -375,8 +371,7 @@ static int sti_platform_probe(struct platform_device *pdev)
 	child_np = of_get_next_available_child(node, NULL);
 
 	while (child_np) {
-		component_match_add(dev, &match, compare_of, child_np);
-		of_node_put(child_np);
+		component_match_add_of(dev, &match, child_np);
 		child_np = of_get_next_available_child(node, child_np);
 	}
 
drivers/gpu/drm/tilcdc/tilcdc_external.c +2 -6
index 03acb4f99982..1b3fd9fa4bef 100644
@@ -9,6 +9,7 @@
  */
 
 #include <linux/component.h>
+#include <linux/of_component.h>
 #include <linux/of_graph.h>
 
 #include "tilcdc_drv.h"
@@ -130,11 +131,6 @@ void tilcdc_remove_external_encoders(struct drm_device *dev)
 						 priv->connector_funcs[i]);
 }
 
-static int dev_match_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 int tilcdc_get_external_components(struct device *dev,
 				   struct component_match **match)
 {
@@ -152,7 +148,7 @@ int tilcdc_get_external_components(struct device *dev,
 
 		dev_dbg(dev, "Subdevice node '%s' found\n", node->name);
 		if (match)
-			component_match_add(dev, match, dev_match_of, node);
+			component_match_add_of(dev, match, node);
 		of_node_put(node);
 		count++;
 	}
Signature · 1 line
2.1.0
#19 lore raw

PATCH v2 3/3 iommu: convert DT component matching to component_match_add_release()

In reply to Russell King - ARM Linux

Convert DT component matching to use component_match_add_release().

---
 drivers/iommu/mtk_iommu.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iommu/mtk_iommu.c +6 -8
index c3043d8754e3..71cf62af4e24 100644
@@ -24,6 +24,7 @@
 #include <linux/iopoll.h>
 #include <linux/list.h>
 #include <linux/of_address.h>
+#include <linux/of_component.h>
 #include <linux/of_iommu.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
@@ -552,11 +553,6 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)
 	return 0;
 }
 
-static int compare_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 static int mtk_iommu_bind(struct device *dev)
 {
 	struct mtk_iommu_data *data = dev_get_drvdata(dev);
@@ -630,17 +626,19 @@ static int mtk_iommu_probe(struct platform_device *pdev)
 			continue;
 
 		plarbdev = of_find_device_by_node(larbnode);
-		of_node_put(larbnode);
 		if (!plarbdev) {
 			plarbdev = of_platform_device_create(
 						larbnode, NULL,
 						platform_bus_type.dev_root);
-			if (!plarbdev)
+			if (!plarbdev) {
+				of_node_put(larbnode);
 				return -EPROBE_DEFER;
+			}
 		}
 		data->smi_imu.larb_imu[i].dev = &plarbdev->dev;
 
-		component_match_add(dev, &match, compare_of, larbnode);
+		component_match_add_of(dev, &match, larbnode);
+		of_node_put(larbnode);
 	}
 
 	platform_set_drvdata(pdev, data);
Signature · 1 line
2.1.0
maintainer Acked-by on v2 2/3
#15 lore raw
In reply to Russell King

Am Freitag, den 03.06.2016, 15:21 +0100 schrieb Russell King:

Quoted 8 lines

Convert DT component matching to use component_match_add_release().

---
 drivers/gpu/drm/arm/hdlcd_drv.c             |  9 +++------
 drivers/gpu/drm/armada/armada_drv.c         |  8 ++------
 drivers/gpu/drm/drm_of.c                    |  6 ++++--
 drivers/gpu/drm/etnaviv/etnaviv_drv.c       | 11 ++---------

For the etnaviv part:

maintainer Reviewed-by on v2 3/3
#20 lore raw

Re: [PATCH v2 3/3] iommu: convert DT component matching to component_match_add_release()

In reply to Russell King
Quoted 3 lines · Russell King

Convert DT component matching to use component_match_add_release().

Quoted 52 lines
---
  drivers/iommu/mtk_iommu.c | 14 ++++++--------
  1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iommu/mtk_iommu.c +6 -8
index c3043d8754e3..71cf62af4e24 100644
@@ -24,6 +24,7 @@
  #include <linux/iopoll.h>
  #include <linux/list.h>
  #include <linux/of_address.h>
+#include <linux/of_component.h>
  #include <linux/of_iommu.h>
  #include <linux/of_irq.h>
  #include <linux/of_platform.h>
@@ -552,11 +553,6 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)
  	return 0;
  }
 
-static int compare_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
  static int mtk_iommu_bind(struct device *dev)
  {
  	struct mtk_iommu_data *data = dev_get_drvdata(dev);
@@ -630,17 +626,19 @@ static int mtk_iommu_probe(struct platform_device *pdev)
  			continue;
 
  		plarbdev = of_find_device_by_node(larbnode);
-		of_node_put(larbnode);
  		if (!plarbdev) {
  			plarbdev = of_platform_device_create(
  						larbnode, NULL,
  						platform_bus_type.dev_root);
-			if (!plarbdev)
+			if (!plarbdev) {
+				of_node_put(larbnode);
  				return -EPROBE_DEFER;
+			}
  		}
  		data->smi_imu.larb_imu[i].dev = &plarbdev->dev;
 
-		component_match_add(dev, &match, compare_of, larbnode);
+		component_match_add_of(dev, &match, larbnode);
+		of_node_put(larbnode);
  	}
 
  	platform_set_drvdata(pdev, data);
#9 lore raw

Re: [PATCH v2 1/3] of: add common OF-based component functionality

In reply to a message not in the archive
Quoted 8 lines · Russell King

Add common OF-based component functionality for matching devices by device node, and releasing the device node at the appropraite time.

---
 drivers/of/Makefile          |  2 +-
 drivers/of/of_component.c    | 41 +++++++++++++++++++++++++++++++++++++++++
 include/linux/of_component.h | 14 ++++++++++++++

I'd prefer this to go into drivers/base/component.c. That's the general direction we've been moving.

I'd expect this would cause some build failures unless the cases you converted all depend on CONFIG_OF.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: [PATCH v2 1/3] of: add common OF-based component functionality

Quoted 4 lines · Rob Herring
Quoted 3 lines · Russell King

Add common OF-based component functionality for matching devices by device node, and releasing the device node at the appropraite time.

Quoted 8 lines
Quoted 5 lines
---
 drivers/of/Makefile          |  2 +-
 drivers/of/of_component.c    | 41 +++++++++++++++++++++++++++++++++++++++++
 include/linux/of_component.h | 14 ++++++++++++++

I'd prefer this to go into drivers/base/component.c. That's the general direction we've been moving.

I'd prefer not to, I don't want to turn the component helpers into something OF specific. They aren't OF specific.

Quoted 2 lines

I'd expect this would cause some build failures unless the cases you converted all depend on CONFIG_OF.

Okay, I'll stick with v1 then, and the duplication that v1 involves.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#12 lore raw

Re: [PATCH v2 1/3] of: add common OF-based component functionality

In reply to a message not in the archive

On Fri, Jun 03, 2016 at 03:21:19PM +0100, Russell King wrote:
[...]

Quoted 1 line
drivers/of/of_component.c +0 -0

[...]

drivers/of/of_component.c line 32

Quoted 4 lines
drivers/of/of_component.c +4 -0
+static void component_compare_of(struct device *dev, void *data)
+{
+	return dev->of_node == data;
+}

The return statement here doesn't match the return value. Didn't GCC complain about this?

Thierry

#13 lore raw

Re: [PATCH v2 1/3] of: add common OF-based component functionality

Quoted 11 lines · Thierry Reding

On Fri, Jun 03, 2016 at 03:21:19PM +0100, Russell King wrote:
[...]

Quoted 1 line
drivers/of/of_component.c +0 -0

[...]

drivers/of/of_component.c line 32

Quoted 4 lines
drivers/of/of_component.c +4 -0
+static void component_compare_of(struct device *dev, void *data)
+{
+	return dev->of_node == data;
+}

The return statement here doesn't match the return value. Didn't GCC complain about this?

I didn't build-test it, because I wanted people's opinions on it first (building means rebuilding my entire tree...)

Anyway, the patch series is dead because I'm not prepared to make the changes which Rob mentioned, so we're back to v1 instead.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#11 lore raw

Re: [PATCH v2 1/3] of: add common OF-based component functionality

In reply to Russell King - ARM Linux
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Rob Herring
Quoted 8 lines · Russell King

Add common OF-based component functionality for matching devices by device node, and releasing the device node at the appropraite time.

---
 drivers/of/Makefile          |  2 +-
 drivers/of/of_component.c    | 41 +++++++++++++++++++++++++++++++++++++++++
 include/linux/of_component.h | 14 ++++++++++++++
Quoted 5 lines
Quoted 2 lines

I'd prefer this to go into drivers/base/component.c. That's the general direction we've been moving.

I'd prefer not to, I don't want to turn the component helpers into something OF specific. They aren't OF specific.

Fine, not enough code to argue about...

Quoted 4 lines
Quoted 2 lines

I'd expect this would cause some build failures unless the cases you converted all depend on CONFIG_OF.

Okay, I'll stick with v1 then, and the duplication that v1 involves.

Why? You don't want to add empty functions? Seems like good clean-up.

Rob

Acked-by
#17 lore raw
In reply to a message not in the archive
Quoted 40 lines · Russell King

Convert DT component matching to use component_match_add_release().

---
 drivers/gpu/drm/arm/hdlcd_drv.c             |  9 +++------
 drivers/gpu/drm/armada/armada_drv.c         |  8 ++------
 drivers/gpu/drm/drm_of.c                    |  6 ++++--
 drivers/gpu/drm/etnaviv/etnaviv_drv.c       | 11 ++---------
 drivers/gpu/drm/msm/msm_drv.c               |  8 ++------
 drivers/gpu/drm/msm/msm_drv.h               |  1 +
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 12 +++---------
 drivers/gpu/drm/sti/sti_drv.c               |  9 ++-------
 drivers/gpu/drm/tilcdc/tilcdc_external.c    |  8 ++------
 9 files changed, 21 insertions(+), 51 deletions(-)
drivers/gpu/drm/arm/hdlcd_drv.c +1 -5
index b987c63ba8d6..f00845c25795 100644
@@ -14,6 +14,7 @@
 #include <linux/clk.h>
 #include <linux/component.h>
 #include <linux/list.h>
+#include <linux/of_component.h>
 #include <linux/of_graph.h>
 #include <linux/of_reserved_mem.h>
 #include <linux/pm_runtime.h>
@@ -443,11 +444,6 @@ static const struct component_master_ops hdlcd_master_ops = {
 	.unbind		= hdlcd_drm_unbind,
 };
 
-static int compare_dev(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 static int hdlcd_probe(struct platform_device *pdev)
 {
 	struct device_node *port, *ep;

drivers/gpu/drm/arm/hdlcd_drv.c static int hdlcd_probe(struct platform_device *pdev) · line 477

Quoted 9 lines
drivers/gpu/drm/arm/hdlcd_drv.c +2 -1
@@ -474,7 +470,8 @@ static int hdlcd_probe(struct platform_device *pdev)
 		return -EAGAIN;
 	}
 
-	component_match_add(&pdev->dev, &match, compare_dev, port);
+	component_match_add_of(&pdev->dev, &match, port);
+	of_node_put(port);
 
 	return component_master_add_with_match(&pdev->dev, &hdlcd_master_ops,
 					       match);

For the HDLCD part of v2:

Quoted 252 lines
drivers/gpu/drm/armada/armada_drv.c +2 -6
index 439824a61aa5..f2716d20c257 100644
@@ -9,6 +9,7 @@
 #include <linux/component.h>
 #include <linux/module.h>
 #include <linux/of_graph.h>
+#include <linux/of_component.h>
 #include <drm/drmP.h>
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_of.h>
@@ -227,11 +228,6 @@ static void armada_drm_unbind(struct device *dev)
 	drm_put_dev(dev_get_drvdata(dev));
 }
 
-static int compare_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 static int compare_dev_name(struct device *dev, void *data)
 {
 	const char *name = data;
@@ -255,7 +251,7 @@ static void armada_add_endpoints(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, match, compare_of, remote);
+		component_match_add_of(dev, match, remote);
 		of_node_put(remote);
 	}
 }
drivers/gpu/drm/drm_of.c +4 -2
index bc98bb94264d..d13fc633aeea 100644
@@ -1,6 +1,7 @@
 #include <linux/component.h>
 #include <linux/export.h>
 #include <linux/list.h>
+#include <linux/of_component.h>
 #include <linux/of_graph.h>
 #include <drm/drmP.h>
 #include <drm/drm_crtc.h>
@@ -101,7 +102,7 @@ int drm_of_component_probe(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, &match, compare_of, port);
+		component_match_add_of(dev, &match, compare_of, port);
 		of_node_put(port);
 	}
 
@@ -140,7 +141,8 @@ int drm_of_component_probe(struct device *dev,
 				continue;
 			}
 
-			component_match_add(dev, &match, compare_of, remote);
+			component_match_add_of_compare(dev, &match, compare_of,
+						       remote);
 			of_node_put(remote);
 		}
 		of_node_put(port);
drivers/gpu/drm/etnaviv/etnaviv_drv.c +2 -9
index 3d4f56df8359..a0e0764a6269 100644
@@ -15,6 +15,7 @@
  */
 
 #include <linux/component.h>
+#include <linux/of_component.h>
 #include <linux/of_platform.h>
 
 #include "etnaviv_drv.h"
@@ -606,13 +607,6 @@ static const struct component_master_ops etnaviv_master_ops = {
 	.unbind = etnaviv_unbind,
 };
 
-static int compare_of(struct device *dev, void *data)
-{
-	struct device_node *np = data;
-
-	return dev->of_node == np;
-}
-
 static int compare_str(struct device *dev, void *data)
 {
 	return !strcmp(dev_name(dev), data);
@@ -635,8 +629,7 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)
 			if (!core_node)
 				break;
 
-			component_match_add(&pdev->dev, &match, compare_of,
-					    core_node);
+			component_match_add_of(&pdev->dev, &match, core_node);
 			of_node_put(core_node);
 		}
 	} else if (dev->platform_data) {
drivers/gpu/drm/msm/msm_drv.c +2 -6
index 9c654092ef78..5293aa775c5a 100644
@@ -800,11 +800,6 @@ static const struct dev_pm_ops msm_pm_ops = {
  * NOTE: duplication of the same code as exynos or imx (or probably any other).
  * so probably some room for some helpers
  */
-static int compare_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 static int add_components(struct device *dev, struct component_match **matchptr,
 		const char *name)
 {
@@ -818,7 +813,8 @@ static int add_components(struct device *dev, struct component_match **matchptr,
 		if (!node)
 			break;
 
-		component_match_add(dev, matchptr, compare_of, node);
+		component_match_add_of(dev, matchptr, node);
+		of_node_put(node);
 	}
 
 	return 0;
drivers/gpu/drm/msm/msm_drv.h +1 -0
index 5b2963f32291..66dafecaf115 100644
@@ -30,6 +30,7 @@
 #include <linux/list.h>
 #include <linux/iommu.h>
 #include <linux/types.h>
+#include <linux/of_component.h>
 #include <linux/of_graph.h>
 #include <linux/of_device.h>
 #include <asm/sizes.h>
drivers/gpu/drm/rockchip/rockchip_drm_drv.c +3 -9
index a409d1f703cb..84c50f6770c3 100644
@@ -22,6 +22,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/pm_runtime.h>
 #include <linux/module.h>
+#include <linux/of_component.h>
 #include <linux/of_graph.h>
 #include <linux/component.h>
 
@@ -414,13 +415,6 @@ static const struct dev_pm_ops rockchip_drm_pm_ops = {
 				rockchip_drm_sys_resume)
 };
 
-static int compare_of(struct device *dev, void *data)
-{
-	struct device_node *np = data;
-
-	return dev->of_node == np;
-}
-
 static void rockchip_add_endpoints(struct device *dev,
 				   struct component_match **match,
 				   struct device_node *port)
@@ -439,7 +433,7 @@ static void rockchip_add_endpoints(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, match, compare_of, remote);
+		component_match_add_of(dev, match, remote);
 		of_node_put(remote);
 	}
 }
@@ -518,7 +512,7 @@ static int rockchip_drm_platform_probe(struct platform_device *pdev)
 			is_support_iommu = false;
 		}
 
-		component_match_add(dev, &match, compare_of, port->parent);
+		component_match_add_of(dev, &match, port->parent);
 		of_node_put(port);
 	}
 
drivers/gpu/drm/sti/sti_drv.c +2 -7
index 872495e72294..aeb2787c9bd4 100644
@@ -10,6 +10,7 @@
 #include <linux/debugfs.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of_component.h>
 #include <linux/of_platform.h>
 
 #include <drm/drm_atomic.h>
@@ -341,11 +342,6 @@ static struct drm_driver sti_driver = {
 	.minor = DRIVER_MINOR,
 };
 
-static int compare_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 static int sti_bind(struct device *dev)
 {
 	return drm_platform_init(&sti_driver, to_platform_device(dev));
@@ -375,8 +371,7 @@ static int sti_platform_probe(struct platform_device *pdev)
 	child_np = of_get_next_available_child(node, NULL);
 
 	while (child_np) {
-		component_match_add(dev, &match, compare_of, child_np);
-		of_node_put(child_np);
+		component_match_add_of(dev, &match, child_np);
 		child_np = of_get_next_available_child(node, child_np);
 	}
 
drivers/gpu/drm/tilcdc/tilcdc_external.c +2 -6
index 03acb4f99982..1b3fd9fa4bef 100644
@@ -9,6 +9,7 @@
  */
 
 #include <linux/component.h>
+#include <linux/of_component.h>
 #include <linux/of_graph.h>
 
 #include "tilcdc_drv.h"
@@ -130,11 +131,6 @@ void tilcdc_remove_external_encoders(struct drm_device *dev)
 						 priv->connector_funcs[i]);
 }
 
-static int dev_match_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 int tilcdc_get_external_components(struct device *dev,
 				   struct component_match **match)
 {
@@ -152,7 +148,7 @@ int tilcdc_get_external_components(struct device *dev,
 
 		dev_dbg(dev, "Subdevice node '%s' found\n", node->name);
 		if (match)
-			component_match_add(dev, match, dev_match_of, node);
+			component_match_add_of(dev, match, node);
 		of_node_put(node);
 		count++;
 	}
Signature · 1 line
2.1.0
Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#18 lore raw
In reply to a message not in the archive
Quoted 41 lines · Russell King

Convert DT component matching to use component_match_add_release().

---
  drivers/gpu/drm/arm/hdlcd_drv.c             |  9 +++------
  drivers/gpu/drm/armada/armada_drv.c         |  8 ++------
  drivers/gpu/drm/drm_of.c                    |  6 ++++--
  drivers/gpu/drm/etnaviv/etnaviv_drv.c       | 11 ++---------
  drivers/gpu/drm/msm/msm_drv.c               |  8 ++------
  drivers/gpu/drm/msm/msm_drv.h               |  1 +
  drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 12 +++---------
  drivers/gpu/drm/sti/sti_drv.c               |  9 ++-------
  drivers/gpu/drm/tilcdc/tilcdc_external.c    |  8 ++------
  9 files changed, 21 insertions(+), 51 deletions(-)
drivers/gpu/drm/sti/sti_drv.c +1 -5
index 872495e72294..aeb2787c9bd4 100644
@@ -10,6 +10,7 @@
  #include <linux/debugfs.h>
  #include <linux/kernel.h>
  #include <linux/module.h>
+#include <linux/of_component.h>
  #include <linux/of_platform.h>
 
  #include <drm/drm_atomic.h>
@@ -341,11 +342,6 @@ static struct drm_driver sti_driver = {
  	.minor = DRIVER_MINOR,
  };
 
-static int compare_of(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
  static int sti_bind(struct device *dev)
  {
  	return drm_platform_init(&sti_driver, to_platform_device(dev));

drivers/gpu/drm/sti/sti_drv.c static int sti_platform_probe(struct platform_device *pdev) · line 377

Quoted 9 lines
drivers/gpu/drm/sti/sti_drv.c +1 -2
@@ -375,8 +371,7 @@ static int sti_platform_probe(struct platform_device *pdev)
  	child_np = of_get_next_available_child(node, NULL);
 
  	while (child_np) {
-		component_match_add(dev, &match, compare_of, child_np);
-		of_node_put(child_np);
+		component_match_add_of(dev, &match, child_np);
  		child_np = of_get_next_available_child(node, child_np);
  	}
 

Hi Russel,

Ok for the sti driver.

maintainer Applied
#21 lore raw

Re: [PATCH v2 3/3] iommu: convert DT component matching to component_match_add_release()

In reply to Russell King
Quoted 6 lines · Russell King

Convert DT component matching to use component_match_add_release().

---
 drivers/iommu/mtk_iommu.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Applied, thanks.