diff mbox series

[v5,13/15] ACPI / bus: Add acpi_dev_get_next_match_dev() and helper macro

Message ID 20210107132838.396641-14-djrscally@gmail.com
State Accepted
Commit bf263f64e804a74ace9bd37f49341d68a653e5e6
Headers show
Series None | expand

Commit Message

Daniel Scally Jan. 7, 2021, 1:28 p.m. UTC
To ensure we handle situations in which multiple sensors of the same
model (and therefore _HID) are present in a system, we need to be able
to iterate over devices matching a known _HID but unknown _UID and _HRV
 - add acpi_dev_get_next_match_dev() to accommodate that possibility and
change acpi_dev_get_first_match_dev() to simply call the new function
with a NULL starting point. Add an iterator macro for convenience.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Daniel Scally <djrscally@gmail.com>
---
Changes in v5:

	- Changed commit subject

 drivers/acpi/utils.c    | 30 ++++++++++++++++++++++++++----
 include/acpi/acpi_bus.h |  7 +++++++
 2 files changed, 33 insertions(+), 4 deletions(-)

Comments

Laurent Pinchart Jan. 9, 2021, 1:54 a.m. UTC | #1
Hi Rafael,

Could you please review this patch, and let us know (see question in the
cover letter) if it can be merged through the linux-media tree for v5.12
?

On Thu, Jan 07, 2021 at 01:28:36PM +0000, Daniel Scally wrote:
> To ensure we handle situations in which multiple sensors of the same

> model (and therefore _HID) are present in a system, we need to be able

> to iterate over devices matching a known _HID but unknown _UID and _HRV

>  - add acpi_dev_get_next_match_dev() to accommodate that possibility and

> change acpi_dev_get_first_match_dev() to simply call the new function

> with a NULL starting point. Add an iterator macro for convenience.

> 

> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>

> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Daniel Scally <djrscally@gmail.com>

> ---

> Changes in v5:

> 

> 	- Changed commit subject

> 

>  drivers/acpi/utils.c    | 30 ++++++++++++++++++++++++++----

>  include/acpi/acpi_bus.h |  7 +++++++

>  2 files changed, 33 insertions(+), 4 deletions(-)

> 

> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c

> index d5411a166685..ddca1550cce6 100644

> --- a/drivers/acpi/utils.c

> +++ b/drivers/acpi/utils.c

> @@ -843,12 +843,13 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)

>  EXPORT_SYMBOL(acpi_dev_present);

>  

>  /**

> - * acpi_dev_get_first_match_dev - Return the first match of ACPI device

> + * acpi_dev_get_next_match_dev - Return the next match of ACPI device

> + * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv

>   * @hid: Hardware ID of the device.

>   * @uid: Unique ID of the device, pass NULL to not check _UID

>   * @hrv: Hardware Revision of the device, pass -1 to not check _HRV

>   *

> - * Return the first match of ACPI device if a matching device was present

> + * Return the next match of ACPI device if another matching device was present

>   * at the moment of invocation, or NULL otherwise.

>   *

>   * The caller is responsible to call put_device() on the returned device.

> @@ -856,8 +857,9 @@ EXPORT_SYMBOL(acpi_dev_present);

>   * See additional information in acpi_dev_present() as well.

>   */

>  struct acpi_device *

> -acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)

> +acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv)

>  {

> +	struct device *start = adev ? &adev->dev : NULL;

>  	struct acpi_dev_match_info match = {};

>  	struct device *dev;

>  

> @@ -865,9 +867,29 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)

>  	match.uid = uid;

>  	match.hrv = hrv;

>  

> -	dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);

> +	dev = bus_find_device(&acpi_bus_type, start, &match, acpi_dev_match_cb);

>  	return dev ? to_acpi_device(dev) : NULL;

>  }

> +EXPORT_SYMBOL(acpi_dev_get_next_match_dev);

> +

> +/**

> + * acpi_dev_get_first_match_dev - Return the first match of ACPI device

> + * @hid: Hardware ID of the device.

> + * @uid: Unique ID of the device, pass NULL to not check _UID

> + * @hrv: Hardware Revision of the device, pass -1 to not check _HRV

> + *

> + * Return the first match of ACPI device if a matching device was present

> + * at the moment of invocation, or NULL otherwise.

> + *

> + * The caller is responsible to call put_device() on the returned device.

> + *

> + * See additional information in acpi_dev_present() as well.

> + */

> +struct acpi_device *

> +acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)

> +{

> +	return acpi_dev_get_next_match_dev(NULL, hid, uid, hrv);

> +}

>  EXPORT_SYMBOL(acpi_dev_get_first_match_dev);

>  

>  /*

> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h

> index 6d1879bf9440..02a716a0af5d 100644

> --- a/include/acpi/acpi_bus.h

> +++ b/include/acpi/acpi_bus.h

> @@ -683,9 +683,16 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)

>  

>  bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);

>  

> +struct acpi_device *

> +acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);

>  struct acpi_device *

>  acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);

>  

> +#define for_each_acpi_dev_match(adev, hid, uid, hrv)			\

> +	for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv);	\

> +	     adev;							\

> +	     adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv))

> +

>  static inline void acpi_dev_put(struct acpi_device *adev)

>  {

>  	put_device(&adev->dev);


-- 
Regards,

Laurent Pinchart
Rafael J. Wysocki Jan. 12, 2021, 7:25 p.m. UTC | #2
On Thu, Jan 7, 2021 at 2:31 PM Daniel Scally <djrscally@gmail.com> wrote:
>
> To ensure we handle situations in which multiple sensors of the same
> model (and therefore _HID) are present in a system, we need to be able
> to iterate over devices matching a known _HID but unknown _UID and _HRV
>  - add acpi_dev_get_next_match_dev() to accommodate that possibility and
> change acpi_dev_get_first_match_dev() to simply call the new function
> with a NULL starting point. Add an iterator macro for convenience.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Daniel Scally <djrscally@gmail.com>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> ---
> Changes in v5:
>
>         - Changed commit subject
>
>  drivers/acpi/utils.c    | 30 ++++++++++++++++++++++++++----
>  include/acpi/acpi_bus.h |  7 +++++++
>  2 files changed, 33 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
> index d5411a166685..ddca1550cce6 100644
> --- a/drivers/acpi/utils.c
> +++ b/drivers/acpi/utils.c
> @@ -843,12 +843,13 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
>  EXPORT_SYMBOL(acpi_dev_present);
>
>  /**
> - * acpi_dev_get_first_match_dev - Return the first match of ACPI device
> + * acpi_dev_get_next_match_dev - Return the next match of ACPI device
> + * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv
>   * @hid: Hardware ID of the device.
>   * @uid: Unique ID of the device, pass NULL to not check _UID
>   * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
>   *
> - * Return the first match of ACPI device if a matching device was present
> + * Return the next match of ACPI device if another matching device was present
>   * at the moment of invocation, or NULL otherwise.
>   *
>   * The caller is responsible to call put_device() on the returned device.
> @@ -856,8 +857,9 @@ EXPORT_SYMBOL(acpi_dev_present);
>   * See additional information in acpi_dev_present() as well.
>   */
>  struct acpi_device *
> -acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
> +acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv)
>  {
> +       struct device *start = adev ? &adev->dev : NULL;
>         struct acpi_dev_match_info match = {};
>         struct device *dev;
>
> @@ -865,9 +867,29 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
>         match.uid = uid;
>         match.hrv = hrv;
>
> -       dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
> +       dev = bus_find_device(&acpi_bus_type, start, &match, acpi_dev_match_cb);
>         return dev ? to_acpi_device(dev) : NULL;
>  }
> +EXPORT_SYMBOL(acpi_dev_get_next_match_dev);
> +
> +/**
> + * acpi_dev_get_first_match_dev - Return the first match of ACPI device
> + * @hid: Hardware ID of the device.
> + * @uid: Unique ID of the device, pass NULL to not check _UID
> + * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
> + *
> + * Return the first match of ACPI device if a matching device was present
> + * at the moment of invocation, or NULL otherwise.
> + *
> + * The caller is responsible to call put_device() on the returned device.
> + *
> + * See additional information in acpi_dev_present() as well.
> + */
> +struct acpi_device *
> +acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
> +{
> +       return acpi_dev_get_next_match_dev(NULL, hid, uid, hrv);
> +}
>  EXPORT_SYMBOL(acpi_dev_get_first_match_dev);
>
>  /*
> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
> index 6d1879bf9440..02a716a0af5d 100644
> --- a/include/acpi/acpi_bus.h
> +++ b/include/acpi/acpi_bus.h
> @@ -683,9 +683,16 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
>
>  bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
>
> +struct acpi_device *
> +acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
>  struct acpi_device *
>  acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
>
> +#define for_each_acpi_dev_match(adev, hid, uid, hrv)                   \
> +       for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv);        \
> +            adev;                                                      \
> +            adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv))
> +
>  static inline void acpi_dev_put(struct acpi_device *adev)
>  {
>         put_device(&adev->dev);
> --
> 2.25.1
>
Rafael J. Wysocki Jan. 12, 2021, 7:26 p.m. UTC | #3
Hi,

On Sat, Jan 9, 2021 at 2:55 AM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>

> Hi Rafael,

>

> Could you please review this patch, and let us know (see question in the

> cover letter)


Done, sorry for the delay.

> if it can be merged through the linux-media tree for v5.12

> ?


Yes, it can.

Thanks!
diff mbox series

Patch

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index d5411a166685..ddca1550cce6 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -843,12 +843,13 @@  bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
 EXPORT_SYMBOL(acpi_dev_present);
 
 /**
- * acpi_dev_get_first_match_dev - Return the first match of ACPI device
+ * acpi_dev_get_next_match_dev - Return the next match of ACPI device
+ * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv
  * @hid: Hardware ID of the device.
  * @uid: Unique ID of the device, pass NULL to not check _UID
  * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
  *
- * Return the first match of ACPI device if a matching device was present
+ * Return the next match of ACPI device if another matching device was present
  * at the moment of invocation, or NULL otherwise.
  *
  * The caller is responsible to call put_device() on the returned device.
@@ -856,8 +857,9 @@  EXPORT_SYMBOL(acpi_dev_present);
  * See additional information in acpi_dev_present() as well.
  */
 struct acpi_device *
-acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
+acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv)
 {
+	struct device *start = adev ? &adev->dev : NULL;
 	struct acpi_dev_match_info match = {};
 	struct device *dev;
 
@@ -865,9 +867,29 @@  acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
 	match.uid = uid;
 	match.hrv = hrv;
 
-	dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
+	dev = bus_find_device(&acpi_bus_type, start, &match, acpi_dev_match_cb);
 	return dev ? to_acpi_device(dev) : NULL;
 }
+EXPORT_SYMBOL(acpi_dev_get_next_match_dev);
+
+/**
+ * acpi_dev_get_first_match_dev - Return the first match of ACPI device
+ * @hid: Hardware ID of the device.
+ * @uid: Unique ID of the device, pass NULL to not check _UID
+ * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
+ *
+ * Return the first match of ACPI device if a matching device was present
+ * at the moment of invocation, or NULL otherwise.
+ *
+ * The caller is responsible to call put_device() on the returned device.
+ *
+ * See additional information in acpi_dev_present() as well.
+ */
+struct acpi_device *
+acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
+{
+	return acpi_dev_get_next_match_dev(NULL, hid, uid, hrv);
+}
 EXPORT_SYMBOL(acpi_dev_get_first_match_dev);
 
 /*
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 6d1879bf9440..02a716a0af5d 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -683,9 +683,16 @@  static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
 
 bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
 
+struct acpi_device *
+acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
 struct acpi_device *
 acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
 
+#define for_each_acpi_dev_match(adev, hid, uid, hrv)			\
+	for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv);	\
+	     adev;							\
+	     adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv))
+
 static inline void acpi_dev_put(struct acpi_device *adev)
 {
 	put_device(&adev->dev);