History

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.

Andy Shevchenko committed 7 years ago

Commit 817b4d61 parent 79a3aaa3 files · +31 −2Browse files

Unified · Split

3 files
  1. drivers/acpi/utils.c +22 −2
  2. include/acpi/acpi_bus.h +3 −0
  3. include/linux/acpi.h +6 −0
drivers/acpi/utils.c+22−2
@@ -739,6 +739,7 @@ EXPORT_SYMBOL(acpi_dev_found); · 738 unmodified lines
739739
740740 struct acpi_dev_match_info {
741741 const char *dev_name;
742+ struct acpi_device *adev;
742743 struct acpi_device_id hid[2];
743744 const char *uid;
744745 s64 hrv;
@@ -759,6 +760,7 @@ static int acpi_dev_match_cb(struct device *dev, void *data) · 14 unmodified lines
759760 return 0;
760761
761762 match->dev_name = acpi_dev_name(adev);
763+ match->adev = adev;
762764
763765 if (match->hrv == -1)
764766 return 1;
@@ -806,16 +808,34 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) · 41 unmodified lines
806808 EXPORT_SYMBOL(acpi_dev_present);
807809
808810 /**
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
810812 * @hid: Hardware ID of the device.
811813 * @uid: Unique ID of the device, pass NULL to not check _UID
812814 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
813815 *
814− * Return device name if a matching device was present
816+ * Return the first match of ACPI device if a matching device was present
815817 * at the moment of invocation, or NULL otherwise.
816818 *
819+ * The caller is responsible to call put_device() on the returned device.
820+ *
817821 * See additional information in acpi_dev_present() as well.
818822 */
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 */
819839 const char *
820840 acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)
821841 {
include/acpi/acpi_bus.h+3−0
@@ -91,6 +91,9 @@ acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev, · 90 unmodified lines
9191 bool acpi_dev_found(const char *hid);
9292 bool acpi_dev_present(const char *hid, const char *uid, s64 hrv);
9393
94+struct acpi_device *
95+acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
96+
9497 const char *
9598 acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv);
9699
include/linux/acpi.h+6−0
@@ -669,6 +669,12 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) · 668 unmodified lines
669669 return false;
670670 }
671671
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+
672678 static inline const char *
673679 acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)
674680 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t