[v2,27/36] drivers: Add a generic helper to match device by fwnode handle
diff mbox series

Message ID 1555344260-12375-28-git-send-email-suzuki.poulose@arm.com
State Superseded
Headers show
Series
  • coresight: Support for ACPI bindings
Related show

Commit Message

Suzuki K Poulose April 15, 2019, 4:04 p.m. UTC
Make the device_fwnode_match() a generic helper to match device
by fwnode handle for use with bus_find_device(). This will be
also used by coresight.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/devcon.c    | 5 -----
 drivers/base/property.c  | 6 ++++++
 include/linux/property.h | 1 +
 3 files changed, 7 insertions(+), 5 deletions(-)

Comments

Rafael J. Wysocki April 16, 2019, 10:20 a.m. UTC | #1
On Mon, Apr 15, 2019 at 6:06 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> Make the device_fwnode_match() a generic helper to match device
> by fwnode handle for use with bus_find_device(). This will be
> also used by coresight.
>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Can you resend this with a CC to linux-acpi@vger.kernel.org, please?

There's some device properties material for 5.2 collected already and
it would be good to keep all that together.

> ---
>  drivers/base/devcon.c    | 5 -----
>  drivers/base/property.c  | 6 ++++++
>  include/linux/property.h | 1 +
>  3 files changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
> index 04db9ae..f4a9e30 100644
> --- a/drivers/base/devcon.c
> +++ b/drivers/base/devcon.c
> @@ -107,11 +107,6 @@ static struct bus_type *generic_match_buses[] = {
>         NULL,
>  };
>
> -static int device_fwnode_match(struct device *dev, void *fwnode)
> -{
> -       return dev_fwnode(dev) == fwnode;
> -}
> -
>  static void *device_connection_fwnode_match(struct device_connection *con)
>  {
>         struct bus_type *bus;
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index 8b91ab3..d10d923 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
> @@ -25,6 +25,12 @@ struct fwnode_handle *dev_fwnode(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(dev_fwnode);
>
> +int device_fwnode_match(struct device *dev, void *fwnode)
> +{
> +       return dev_fwnode(dev) == fwnode;
> +}
> +EXPORT_SYMBOL_GPL(device_fwnode_match);
> +
>  /**
>   * device_property_present - check if a property of a device is present
>   * @dev: Device whose property is being checked
> diff --git a/include/linux/property.h b/include/linux/property.h
> index 65d3420..c8fd3d42 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -34,6 +34,7 @@ enum dev_dma_attr {
>  };
>
>  struct fwnode_handle *dev_fwnode(struct device *dev);
> +int device_fwnode_match(struct device *dev, void *fwnode);
>
>  bool device_property_present(struct device *dev, const char *propname);
>  int device_property_read_u8_array(struct device *dev, const char *propname,
> --
> 2.7.4
>
Suzuki K Poulose April 16, 2019, 10:34 a.m. UTC | #2
Hi Rafael

On 04/16/2019 11:20 AM, Rafael J. Wysocki wrote:
> On Mon, Apr 15, 2019 at 6:06 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>>
>> Make the device_fwnode_match() a generic helper to match device
>> by fwnode handle for use with bus_find_device(). This will be
>> also used by coresight.
>>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
>> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> 
> Can you resend this with a CC to linux-acpi@vger.kernel.org, please?
> 
> There's some device properties material for 5.2 collected already and
> it would be good to keep all that together.
> 

Sure, will do. Btw, I have a question w.r.t the match function.

We have :


class_find_device(struct class *class, struct device *start,
                   const void *data,
                   int (*match)(struct device *, const void *))
and

bus_find_device(struct bus_type *bus,
                 struct device *start, void *data,
                 int (*match)(struct device *dev, void *data))

Just because the "match" has slightly different constraint for the
data (i.e, const void * vs void *), we can't reuse the same match
function for class_find_device. Do you think we should converge the
types to reuse the same match every where (Of course in a separate
patch series) ?

Cheers
Suzuki
Rafael J. Wysocki April 16, 2019, 10:45 a.m. UTC | #3
On Tue, Apr 16, 2019 at 12:31 PM Suzuki K Poulose
<suzuki.poulose@arm.com> wrote:
>
> Hi Rafael
>
> On 04/16/2019 11:20 AM, Rafael J. Wysocki wrote:
> > On Mon, Apr 15, 2019 at 6:06 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
> >>
> >> Make the device_fwnode_match() a generic helper to match device
> >> by fwnode handle for use with bus_find_device(). This will be
> >> also used by coresight.
> >>
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> >> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> >
> > Can you resend this with a CC to linux-acpi@vger.kernel.org, please?
> >
> > There's some device properties material for 5.2 collected already and
> > it would be good to keep all that together.
> >
>
> Sure, will do. Btw, I have a question w.r.t the match function.
>
> We have :
>
>
> class_find_device(struct class *class, struct device *start,
>                    const void *data,
>                    int (*match)(struct device *, const void *))
> and
>
> bus_find_device(struct bus_type *bus,
>                  struct device *start, void *data,
>                  int (*match)(struct device *dev, void *data))
>
> Just because the "match" has slightly different constraint for the
> data (i.e, const void * vs void *), we can't reuse the same match
> function for class_find_device. Do you think we should converge the
> types to reuse the same match every where (Of course in a separate
> patch series) ?

AFAICS, (void *) pointers can be passed to functions taking (const
void *) arguments, so yes, it looks like that could be consolidated
and it also would be a valuable cleanup IMO.

Patch
diff mbox series

diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
index 04db9ae..f4a9e30 100644
--- a/drivers/base/devcon.c
+++ b/drivers/base/devcon.c
@@ -107,11 +107,6 @@  static struct bus_type *generic_match_buses[] = {
 	NULL,
 };
 
-static int device_fwnode_match(struct device *dev, void *fwnode)
-{
-	return dev_fwnode(dev) == fwnode;
-}
-
 static void *device_connection_fwnode_match(struct device_connection *con)
 {
 	struct bus_type *bus;
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 8b91ab3..d10d923 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -25,6 +25,12 @@  struct fwnode_handle *dev_fwnode(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(dev_fwnode);
 
+int device_fwnode_match(struct device *dev, void *fwnode)
+{
+	return dev_fwnode(dev) == fwnode;
+}
+EXPORT_SYMBOL_GPL(device_fwnode_match);
+
 /**
  * device_property_present - check if a property of a device is present
  * @dev: Device whose property is being checked
diff --git a/include/linux/property.h b/include/linux/property.h
index 65d3420..c8fd3d42 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -34,6 +34,7 @@  enum dev_dma_attr {
 };
 
 struct fwnode_handle *dev_fwnode(struct device *dev);
+int device_fwnode_match(struct device *dev, void *fwnode);
 
 bool device_property_present(struct device *dev, const char *propname);
 int device_property_read_u8_array(struct device *dev, const char *propname,