Add a wrapper to driver_find_device() to search for a device
by the of_node pointer, reusing the generic match function.
Also convert the existing users to make use of the new helper.

Cc: Lee Jones <[email protected]>
Cc: Thor Thayer <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Acked-by: Thor Thayer <[email protected]>
Signed-off-by: Suzuki K Poulose <[email protected]>
---
 drivers/amba/tegra-ahb.c    | 11 +----------
 drivers/mfd/altera-sysmgr.c | 14 ++------------
 include/linux/device.h      | 13 +++++++++++++
 3 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c
index aa64eec..57d3b2e 100644
--- a/drivers/amba/tegra-ahb.c
+++ b/drivers/amba/tegra-ahb.c
@@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, 
u32 value, u32 offset)
 }
 
 #ifdef CONFIG_TEGRA_IOMMU_SMMU
-static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
-{
-       struct tegra_ahb *ahb = dev_get_drvdata(dev);
-       const struct device_node *dn = data;
-
-       return (ahb->dev->of_node == dn) ? 1 : 0;
-}
-
 int tegra_ahb_enable_smmu(struct device_node *dn)
 {
        struct device *dev;
        u32 val;
        struct tegra_ahb *ahb;
 
-       dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
-                                tegra_ahb_match_by_smmu);
+       dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
        if (!dev)
                return -EPROBE_DEFER;
        ahb = dev_get_drvdata(dev);
diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c
index 2ee14d8..d2a13a5 100644
--- a/drivers/mfd/altera-sysmgr.c
+++ b/drivers/mfd/altera-sysmgr.c
@@ -88,16 +88,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
 };
 
 /**
- * sysmgr_match_phandle
- * Matching function used by driver_find_device().
- * Return: True if match is found, otherwise false.
- */
-static int sysmgr_match_phandle(struct device *dev, const void *data)
-{
-       return dev->of_node == (const struct device_node *)data;
-}
-
-/**
  * altr_sysmgr_regmap_lookup_by_phandle
  * Find the sysmgr previous configured in probe() and return regmap property.
  * Return: regmap if found or error if not found.
@@ -117,8 +107,8 @@ struct regmap *altr_sysmgr_regmap_lookup_by_phandle(struct 
device_node *np,
        if (!sysmgr_np)
                return ERR_PTR(-ENODEV);
 
-       dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
-                                (void *)sysmgr_np, sysmgr_match_phandle);
+       dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
+                                           (void *)sysmgr_np);
        of_node_put(sysmgr_np);
        if (!dev)
                return ERR_PTR(-EPROBE_DEFER);
diff --git a/include/linux/device.h b/include/linux/device.h
index 0d3958e..f929671 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -437,6 +437,19 @@ static inline struct device 
*driver_find_device_by_name(struct device_driver *dr
        return driver_find_device(drv, NULL, name, device_match_name);
 }
 
+/**
+ * driver_find_device_by_of_node- device iterator for locating a particular 
device
+ * by of_node pointer.
+ * @driver: the driver we're iterating
+ * @np: of_node pointer to match.
+ */
+static inline struct device *
+driver_find_device_by_of_node(struct device_driver *drv,
+                             const struct device_node *np)
+{
+       return driver_find_device(drv, NULL, np, device_match_of_node);
+}
+
 void driver_deferred_probe_add(struct device *dev);
 int driver_deferred_probe_check_state(struct device *dev);
 
-- 
2.7.4

Reply via email to