Skip to content

Commit 81eeb2f

Browse files
andy-shevrafaeljw
authored andcommitted
ACPI: utils: Document for_each_acpi_dev_match() macro
The macro requires to call acpi_dev_put() on each iteration. Due to this it doesn't tolerate sudden disappearence of the devices. Document all these nuances to prevent users blindly call it without understanding the possible issues. While at it, add the note to the acpi_dev_get_next_match_dev() and advertise acpi_dev_put() instead of put_device() in the whole family of the helper functions. Fixes: bf263f6 ("media: ACPI / bus: Add acpi_dev_get_next_match_dev() and helper macro") Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent d434405 commit 81eeb2f

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

drivers/acpi/utils.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,11 @@ EXPORT_SYMBOL(acpi_dev_present);
832832
* Return the next match of ACPI device if another matching device was present
833833
* at the moment of invocation, or NULL otherwise.
834834
*
835-
* The caller is responsible to call put_device() on the returned device.
835+
* FIXME: The function does not tolerate the sudden disappearance of @adev, e.g.
836+
* in the case of a hotplug event. That said, the caller should ensure that
837+
* this will never happen.
838+
*
839+
* The caller is responsible for invoking acpi_dev_put() on the returned device.
836840
*
837841
* See additional information in acpi_dev_present() as well.
838842
*/
@@ -861,7 +865,7 @@ EXPORT_SYMBOL(acpi_dev_get_next_match_dev);
861865
* Return the first match of ACPI device if a matching device was present
862866
* at the moment of invocation, or NULL otherwise.
863867
*
864-
* The caller is responsible to call put_device() on the returned device.
868+
* The caller is responsible for invoking acpi_dev_put() on the returned device.
865869
*
866870
* See additional information in acpi_dev_present() as well.
867871
*/

include/acpi/acpi_bus.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,20 @@ acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const cha
689689
struct acpi_device *
690690
acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
691691

692+
/**
693+
* for_each_acpi_dev_match - iterate over ACPI devices that matching the criteria
694+
* @adev: pointer to the matching ACPI device, NULL at the end of the loop
695+
* @hid: Hardware ID of the device.
696+
* @uid: Unique ID of the device, pass NULL to not check _UID
697+
* @hrv: Hardware Revision of the device, pass -1 to not check _HRV
698+
*
699+
* The caller is responsible for invoking acpi_dev_put() on the returned device.
700+
*
701+
* FIXME: Due to above requirement there is a window that may invalidate @adev
702+
* and next iteration will use a dangling pointer, e.g. in the case of a
703+
* hotplug event. That said, the caller should ensure that this will never
704+
* happen.
705+
*/
692706
#define for_each_acpi_dev_match(adev, hid, uid, hrv) \
693707
for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv); \
694708
adev; \

0 commit comments

Comments
 (0)