ACPI: Rework acpi_get_child() to be more efficient
Observe that acpi_get_child() doesn't need to use the helper struct acpi_find_child structure and change it to work without it. Also, using acpi_get_object_info() to get the output of _ADR for the given device is overkill, because that function does much more than just evaluating _ADR (let alone the additional memory allocation done by it). Moreover, acpi_get_child() doesn't need to loop any more once it has found a matching handle, so make it stop in that case. To prevent the results from changing, make it use do_acpi_find_child() as a post-order callback. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
949db153b6
commit
33f767d767
1 changed files with 12 additions and 21 deletions
|
@ -95,40 +95,31 @@ static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get device's handler per its address under its parent */
|
static acpi_status do_acpi_find_child(acpi_handle handle, u32 lvl_not_used,
|
||||||
struct acpi_find_child {
|
void *addr_p, void **ret_p)
|
||||||
acpi_handle handle;
|
|
||||||
u64 address;
|
|
||||||
};
|
|
||||||
|
|
||||||
static acpi_status
|
|
||||||
do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
|
|
||||||
{
|
{
|
||||||
|
unsigned long long addr;
|
||||||
acpi_status status;
|
acpi_status status;
|
||||||
struct acpi_device_info *info;
|
|
||||||
struct acpi_find_child *find = context;
|
|
||||||
|
|
||||||
status = acpi_get_object_info(handle, &info);
|
status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &addr);
|
||||||
if (ACPI_SUCCESS(status)) {
|
if (ACPI_SUCCESS(status) && addr == *((u64 *)addr_p)) {
|
||||||
if ((info->address == find->address)
|
*ret_p = handle;
|
||||||
&& (info->valid & ACPI_VALID_ADR))
|
return AE_CTRL_TERMINATE;
|
||||||
find->handle = handle;
|
|
||||||
kfree(info);
|
|
||||||
}
|
}
|
||||||
return AE_OK;
|
return AE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
acpi_handle acpi_get_child(acpi_handle parent, u64 address)
|
acpi_handle acpi_get_child(acpi_handle parent, u64 address)
|
||||||
{
|
{
|
||||||
struct acpi_find_child find = { NULL, address };
|
void *ret = NULL;
|
||||||
|
|
||||||
if (!parent)
|
if (!parent)
|
||||||
return NULL;
|
return NULL;
|
||||||
acpi_walk_namespace(ACPI_TYPE_DEVICE, parent,
|
|
||||||
1, do_acpi_find_child, NULL, &find, NULL);
|
|
||||||
return find.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
acpi_walk_namespace(ACPI_TYPE_DEVICE, parent, 1, NULL,
|
||||||
|
do_acpi_find_child, &address, &ret);
|
||||||
|
return (acpi_handle)ret;
|
||||||
|
}
|
||||||
EXPORT_SYMBOL(acpi_get_child);
|
EXPORT_SYMBOL(acpi_get_child);
|
||||||
|
|
||||||
static int acpi_bind_one(struct device *dev, acpi_handle handle)
|
static int acpi_bind_one(struct device *dev, acpi_handle handle)
|
||||||
|
|
Loading…
Add table
Reference in a new issue