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


Groups > linux.kernel > #1636433 > unrolled thread

[PATCH] [RFC] of/platform: Make of_dev_node_match() helper public

Started byGeert Uytterhoeven <geert+renesas@glider.be>
First post2017-05-05 17:00 +0200
Last post2017-05-05 21:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] [RFC] of/platform: Make of_dev_node_match() helper public Geert Uytterhoeven <geert+renesas@glider.be> - 2017-05-05 17:00 +0200
    Re: [PATCH] [RFC] of/platform: Make of_dev_node_match() helper public Rob Herring <robh+dt@kernel.org> - 2017-05-05 21:00 +0200
      Re: [PATCH] [RFC] of/platform: Make of_dev_node_match() helper public Geert Uytterhoeven <geert@linux-m68k.org> - 2017-05-05 21:20 +0200

#1636433 — [PATCH] [RFC] of/platform: Make of_dev_node_match() helper public

FromGeert Uytterhoeven <geert+renesas@glider.be>
Date2017-05-05 17:00 +0200
Subject[PATCH] [RFC] of/platform: Make of_dev_node_match() helper public
Message-ID<tDMS6-35I-13@gated-at.bofh.it>
Several drivers provide their own match functions, identical to
of_dev_node_match() in the OF platform core.

Reduce duplication by making of_dev_node_match() public.
To avoid conflicts, the duplicates in coresight and i2c must be removed
at the same time.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Is "of_dev_node_match()" a suitable name for a public API?
If another (non-conflicting) name is chosen, the conversion of coresight
and i2c can be moved into a separate patch.

TODO: Convert all other code using (non-const) match functions with
different names, but doing exactly the same.
---
 drivers/hwtracing/coresight/of_coresight.c | 5 -----
 drivers/i2c/i2c-core.c                     | 5 -----
 drivers/of/platform.c                      | 2 +-
 include/linux/of_platform.h                | 1 +
 4 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/hwtracing/coresight/of_coresight.c b/drivers/hwtracing/coresight/of_coresight.c
index 629e031b745651f1..62e8208759dbebc9 100644
--- a/drivers/hwtracing/coresight/of_coresight.c
+++ b/drivers/hwtracing/coresight/of_coresight.c
@@ -25,11 +25,6 @@
 #include <asm/smp_plat.h>
 
 
-static int of_dev_node_match(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 static struct device *
 of_coresight_get_endpoint_device(struct device_node *endpoint)
 {
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7a065c4260f30be4..d545ef4eba2c3571 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1830,11 +1830,6 @@ static void of_i2c_register_devices(struct i2c_adapter *adap)
 	of_node_put(bus);
 }
 
-static int of_dev_node_match(struct device *dev, void *data)
-{
-	return dev->of_node == data;
-}
-
 /* must call put_device() when done with returned i2c_client device */
 struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
 {
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 71fecc2debfc940a..5e70725ff6f984b4 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -37,7 +37,7 @@ const struct of_device_id of_default_bus_match_table[] = {
 	{} /* Empty terminated list */
 };
 
-static int of_dev_node_match(struct device *dev, void *data)
+int of_dev_node_match(struct device *dev, void *data)
 {
 	return dev->of_node == data;
 }
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index dc8224ae28d5d9e6..7346ba02553b4761 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -57,6 +57,7 @@ extern const struct of_device_id of_default_bus_match_table[];
 extern struct platform_device *of_device_alloc(struct device_node *np,
 					 const char *bus_id,
 					 struct device *parent);
+extern int of_dev_node_match(struct device *dev, void *data);
 extern struct platform_device *of_find_device_by_node(struct device_node *np);
 
 /* Platform devices and busses creation */
-- 
2.7.4

[toc] | [next] | [standalone]


#1636661

FromRob Herring <robh+dt@kernel.org>
Date2017-05-05 21:00 +0200
Message-ID<tDQCn-5yw-67@gated-at.bofh.it>
In reply to#1636433
On Fri, May 5, 2017 at 9:52 AM, Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> Several drivers provide their own match functions, identical to
> of_dev_node_match() in the OF platform core.
>
> Reduce duplication by making of_dev_node_match() public.
> To avoid conflicts, the duplicates in coresight and i2c must be removed
> at the same time.

I think you are down one level too far. At least the 2 users here are
just for calls to bus_find_device. We already have a function for that
with of_find_device_by_node at least for platform devices. Perhaps
rework that to be "struct device *of_find_bus_device_by_node(struct
bus_type *b, struct device_node *np)" and then wrappers for each bus
type. And perhaps make a class variant as well. However, we should
also consider if OF is the right level. Maybe it should be fwnode
functions?

Rob

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


#1636667

FromGeert Uytterhoeven <geert@linux-m68k.org>
Date2017-05-05 21:20 +0200
Message-ID<tDQVH-5Uw-5@gated-at.bofh.it>
In reply to#1636661
Hi Rob,

On Fri, May 5, 2017 at 8:50 PM, Rob Herring <robh+dt@kernel.org> wrote:
> On Fri, May 5, 2017 at 9:52 AM, Geert Uytterhoeven
> <geert+renesas@glider.be> wrote:
>> Several drivers provide their own match functions, identical to
>> of_dev_node_match() in the OF platform core.
>>
>> Reduce duplication by making of_dev_node_match() public.
>> To avoid conflicts, the duplicates in coresight and i2c must be removed
>> at the same time.
>
> I think you are down one level too far. At least the 2 users here are
> just for calls to bus_find_device. We already have a function for that

There are more of them, some used with driver_find_device().
class_find_device() need a slightly different version, as the data pointer
is const. E.g. drivers/spi/spi.c uses both variants...

device_find_child() can use the same callback.

> with of_find_device_by_node at least for platform devices. Perhaps
> rework that to be "struct device *of_find_bus_device_by_node(struct
> bus_type *b, struct device_node *np)" and then wrappers for each bus
> type. And perhaps make a class variant as well. However, we should
> also consider if OF is the right level. Maybe it should be fwnode
> functions?

There are only 2 of these:

$ git grep 'dev->fwnode == data'
drivers/iommu/arm-smmu-v3.c:    return dev->fwnode == data;
drivers/iommu/arm-smmu.c:       return dev->fwnode == data;
$

while you can find a few dozen of the OF callbacks.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web