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
739 739
740struct acpi_dev_match_info {740struct 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) · 14 unmodified lines
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) · 41 unmodified lines
806EXPORT_SYMBOL(acpi_dev_present);808EXPORT_SYMBOL(acpi_dev_present);
807 809
808/**810/**
809 * acpi_dev_get_first_match_name - Return name of first match of ACPI device811 * 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 _UID813 * @uid: Unique ID of the device, pass NULL to not check _UID
812 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV814 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
813 *815 *
814 * Return device name if a matching device was present816 * 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 */
823struct acpi_device *
824acpi_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}
836EXPORT_SYMBOL(acpi_dev_get_first_match_dev);
837
838/* DEPRECATED, use acpi_dev_get_first_match_dev() instead */
819const char *839const char *
820acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)840acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)
821{841{
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
91bool acpi_dev_found(const char *hid);91bool acpi_dev_found(const char *hid);
92bool acpi_dev_present(const char *hid, const char *uid, s64 hrv);92bool acpi_dev_present(const char *hid, const char *uid, s64 hrv);
93 93
94struct acpi_device *
95acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
96
94const char *97const char *
95acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv);98acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv);
96 99
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
669 return false;669 return false;
670}670}
671 671
672static inline struct acpi_device *
673acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
674{
675 return NULL;
676}
677
672static inline const char *678static inline const char *
673acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)679acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)
674{680{

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