diff options
| author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2019-03-18 16:00:54 -0400 |
|---|---|---|
| committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2019-04-01 04:55:56 -0400 |
| commit | 817b4d64da036f5559297a2fdb82b8b14f4ffdcd (patch) | |
| tree | fa02639adb2da258699965d4e2c222d38f0edca5 | |
| parent | 79a3aaa7b82e3106be97842dedfd8429248896e6 (diff) | |
ACPI / utils: Introduce acpi_dev_get_first_match_dev() helper
The acpi_dev_get_first_match_name() is missing put_device() call
and thus keeping reference counting unbalanced.
In order to fix the issue introduce a new helper to convert existing users
one-by-one to a better API.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
| -rw-r--r-- | drivers/acpi/utils.c | 24 | ||||
| -rw-r--r-- | include/acpi/acpi_bus.h | 3 | ||||
| -rw-r--r-- | include/linux/acpi.h | 6 |
3 files changed, 31 insertions, 2 deletions
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index c4b06cc075f9..5a2bae2b6c3a 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c | |||
| @@ -739,6 +739,7 @@ EXPORT_SYMBOL(acpi_dev_found); | |||
| 739 | 739 | ||
| 740 | struct acpi_dev_match_info { | 740 | struct acpi_dev_match_info { |
| 741 | const char *dev_name; | 741 | const char *dev_name; |
| 742 | struct acpi_device *adev; | ||
| 742 | struct acpi_device_id hid[2]; | 743 | struct acpi_device_id hid[2]; |
| 743 | const char *uid; | 744 | const char *uid; |
| 744 | s64 hrv; | 745 | s64 hrv; |
| @@ -759,6 +760,7 @@ static int acpi_dev_match_cb(struct device *dev, void *data) | |||
| 759 | return 0; | 760 | return 0; |
| 760 | 761 | ||
| 761 | match->dev_name = acpi_dev_name(adev); | 762 | match->dev_name = acpi_dev_name(adev); |
| 763 | match->adev = adev; | ||
| 762 | 764 | ||
| 763 | if (match->hrv == -1) | 765 | if (match->hrv == -1) |
| 764 | return 1; | 766 | return 1; |
| @@ -806,16 +808,34 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) | |||
| 806 | EXPORT_SYMBOL(acpi_dev_present); | 808 | EXPORT_SYMBOL(acpi_dev_present); |
| 807 | 809 | ||
| 808 | /** | 810 | /** |
| 809 | * acpi_dev_get_first_match_name - Return name of first match of ACPI device | 811 | * acpi_dev_get_first_match_dev - Return the first match of ACPI device |
| 810 | * @hid: Hardware ID of the device. | 812 | * @hid: Hardware ID of the device. |
| 811 | * @uid: Unique ID of the device, pass NULL to not check _UID | 813 | * @uid: Unique ID of the device, pass NULL to not check _UID |
| 812 | * @hrv: Hardware Revision of the device, pass -1 to not check _HRV | 814 | * @hrv: Hardware Revision of the device, pass -1 to not check _HRV |
| 813 | * | 815 | * |
| 814 | * Return device name if a matching device was present | 816 | * Return the first match of ACPI device if a matching device was present |
| 815 | * at the moment of invocation, or NULL otherwise. | 817 | * at the moment of invocation, or NULL otherwise. |
| 816 | * | 818 | * |
| 819 | * The caller is responsible to call put_device() on the returned device. | ||
| 820 | * | ||
| 817 | * See additional information in acpi_dev_present() as well. | 821 | * See additional information in acpi_dev_present() as well. |
| 818 | */ | 822 | */ |
| 823 | struct acpi_device * | ||
| 824 | acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv) | ||
| 825 | { | ||
| 826 | struct acpi_dev_match_info match = {}; | ||
| 827 | struct device *dev; | ||
| 828 | |||
| 829 | strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id)); | ||
| 830 | match.uid = uid; | ||
| 831 | match.hrv = hrv; | ||
| 832 | |||
| 833 | dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb); | ||
| 834 | return dev ? match.adev : NULL; | ||
| 835 | } | ||
| 836 | EXPORT_SYMBOL(acpi_dev_get_first_match_dev); | ||
| 837 | |||
| 838 | /* DEPRECATED, use acpi_dev_get_first_match_dev() instead */ | ||
| 819 | const char * | 839 | const char * |
| 820 | acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv) | 840 | acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv) |
| 821 | { | 841 | { |
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 0300374101cd..2063e9e2f384 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h | |||
| @@ -91,6 +91,9 @@ acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev, | |||
| 91 | bool acpi_dev_found(const char *hid); | 91 | bool acpi_dev_found(const char *hid); |
| 92 | bool acpi_dev_present(const char *hid, const char *uid, s64 hrv); | 92 | bool acpi_dev_present(const char *hid, const char *uid, s64 hrv); |
| 93 | 93 | ||
| 94 | struct acpi_device * | ||
| 95 | acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv); | ||
| 96 | |||
| 94 | const char * | 97 | const char * |
| 95 | acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv); | 98 | acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv); |
| 96 | 99 | ||
diff --git a/include/linux/acpi.h b/include/linux/acpi.h index d5dcebd7aad3..3e1d16b00513 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h | |||
| @@ -669,6 +669,12 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) | |||
| 669 | return false; | 669 | return false; |
| 670 | } | 670 | } |
| 671 | 671 | ||
| 672 | static inline struct acpi_device * | ||
| 673 | acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv) | ||
| 674 | { | ||
| 675 | return NULL; | ||
| 676 | } | ||
| 677 | |||
| 672 | static inline const char * | 678 | static inline const char * |
| 673 | acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv) | 679 | acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv) |
| 674 | { | 680 | { |
