Skip to content

Commit cca8a7e

Browse files
djrscallyrafaeljw
authored andcommitted
ACPI: scan: Add acpi_dev_get_next_consumer_dev()
In commit b83e2b3 ("ACPI: scan: Add function to fetch dependent of ACPI device") we added a means of fetching the first device to declare itself dependent on another ACPI device in the _DEP method. One assumption in that patch was that there would only be a single consuming device, but this has not held. Replace that function with a new function that fetches the next consumer of a supplier device. Where no "previous" consumer is passed in, it behaves identically to the original function. Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Daniel Scally <djrscally@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 9837895 commit cca8a7e

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

drivers/acpi/scan.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,9 +2235,22 @@ static int acpi_bus_attach(struct acpi_device *device, void *first_pass)
22352235
return 0;
22362236
}
22372237

2238-
static int acpi_dev_get_first_consumer_dev_cb(struct acpi_dep_data *dep, void *data)
2238+
static int acpi_dev_get_next_consumer_dev_cb(struct acpi_dep_data *dep, void *data)
22392239
{
2240-
struct acpi_device *adev;
2240+
struct acpi_device **adev_p = data;
2241+
struct acpi_device *adev = *adev_p;
2242+
2243+
/*
2244+
* If we're passed a 'previous' consumer device then we need to skip
2245+
* any consumers until we meet the previous one, and then NULL @data
2246+
* so the next one can be returned.
2247+
*/
2248+
if (adev) {
2249+
if (dep->consumer == adev->handle)
2250+
*adev_p = NULL;
2251+
2252+
return 0;
2253+
}
22412254

22422255
adev = acpi_get_acpi_dev(dep->consumer);
22432256
if (adev) {
@@ -2368,25 +2381,32 @@ bool acpi_dev_ready_for_enumeration(const struct acpi_device *device)
23682381
EXPORT_SYMBOL_GPL(acpi_dev_ready_for_enumeration);
23692382

23702383
/**
2371-
* acpi_dev_get_first_consumer_dev - Return ACPI device dependent on @supplier
2384+
* acpi_dev_get_next_consumer_dev - Return the next adev dependent on @supplier
23722385
* @supplier: Pointer to the dependee device
2386+
* @start: Pointer to the current dependent device
23732387
*
2374-
* Returns the first &struct acpi_device which declares itself dependent on
2388+
* Returns the next &struct acpi_device which declares itself dependent on
23752389
* @supplier via the _DEP buffer, parsed from the acpi_dep_list.
23762390
*
2377-
* The caller is responsible for putting the reference to adev when it is no
2378-
* longer needed.
2391+
* If the returned adev is not passed as @start to this function, the caller is
2392+
* responsible for putting the reference to adev when it is no longer needed.
23792393
*/
2380-
struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier)
2394+
struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier,
2395+
struct acpi_device *start)
23812396
{
2382-
struct acpi_device *adev = NULL;
2397+
struct acpi_device *adev = start;
23832398

23842399
acpi_walk_dep_device_list(supplier->handle,
2385-
acpi_dev_get_first_consumer_dev_cb, &adev);
2400+
acpi_dev_get_next_consumer_dev_cb, &adev);
2401+
2402+
acpi_dev_put(start);
2403+
2404+
if (adev == start)
2405+
return NULL;
23862406

23872407
return adev;
23882408
}
2389-
EXPORT_SYMBOL_GPL(acpi_dev_get_first_consumer_dev);
2409+
EXPORT_SYMBOL_GPL(acpi_dev_get_next_consumer_dev);
23902410

23912411
/**
23922412
* acpi_bus_scan - Add ACPI device node objects in a given namespace scope.

drivers/platform/x86/intel/int3472/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int skl_int3472_get_sensor_adev_and_name(struct device *dev,
6262
struct acpi_device *sensor;
6363
int ret = 0;
6464

65-
sensor = acpi_dev_get_first_consumer_dev(adev);
65+
sensor = acpi_dev_get_next_consumer_dev(adev, NULL);
6666
if (!sensor) {
6767
dev_err(dev, "INT3472 seems to have no dependents.\n");
6868
return -ENODEV;

include/acpi/acpi_bus.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,9 @@ bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const ch
742742

743743
void acpi_dev_clear_dependencies(struct acpi_device *supplier);
744744
bool acpi_dev_ready_for_enumeration(const struct acpi_device *device);
745-
struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier);
745+
struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier,
746+
struct acpi_device *start);
747+
746748
struct acpi_device *
747749
acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
748750
struct acpi_device *

0 commit comments

Comments
 (0)