mirror of https://gitee.com/openkylin/linux.git
Merge branch 'acpi-scan' into acpi-messages
This commit is contained in:
commit
c888065119
|
@ -578,29 +578,31 @@ static void acpi_scan_drop_device(acpi_handle handle, void *context)
|
|||
mutex_unlock(&acpi_device_del_lock);
|
||||
}
|
||||
|
||||
static int acpi_get_device_data(acpi_handle handle, struct acpi_device **device,
|
||||
void (*callback)(void *))
|
||||
static struct acpi_device *handle_to_device(acpi_handle handle,
|
||||
void (*callback)(void *))
|
||||
{
|
||||
struct acpi_device *adev = NULL;
|
||||
acpi_status status;
|
||||
|
||||
if (!device)
|
||||
return -EINVAL;
|
||||
|
||||
*device = NULL;
|
||||
|
||||
status = acpi_get_data_full(handle, acpi_scan_drop_device,
|
||||
(void **)device, callback);
|
||||
if (ACPI_FAILURE(status) || !*device) {
|
||||
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
|
||||
handle));
|
||||
return -ENODEV;
|
||||
(void **)&adev, callback);
|
||||
if (ACPI_FAILURE(status) || !adev) {
|
||||
acpi_handle_debug(handle, "No context!\n");
|
||||
return NULL;
|
||||
}
|
||||
return 0;
|
||||
return adev;
|
||||
}
|
||||
|
||||
int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
|
||||
{
|
||||
return acpi_get_device_data(handle, device, NULL);
|
||||
if (!device)
|
||||
return -EINVAL;
|
||||
|
||||
*device = handle_to_device(handle, NULL);
|
||||
if (!*device)
|
||||
return -ENODEV;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(acpi_bus_get_device);
|
||||
|
||||
|
@ -612,10 +614,7 @@ static void get_acpi_device(void *dev)
|
|||
|
||||
struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
|
||||
{
|
||||
struct acpi_device *adev = NULL;
|
||||
|
||||
acpi_get_device_data(handle, &adev, get_acpi_device);
|
||||
return adev;
|
||||
return handle_to_device(handle, get_acpi_device);
|
||||
}
|
||||
|
||||
void acpi_bus_put_acpi_device(struct acpi_device *adev)
|
||||
|
@ -623,12 +622,23 @@ void acpi_bus_put_acpi_device(struct acpi_device *adev)
|
|||
put_device(&adev->dev);
|
||||
}
|
||||
|
||||
static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id)
|
||||
{
|
||||
struct acpi_device_bus_id *acpi_device_bus_id;
|
||||
|
||||
/* Find suitable bus_id and instance number in acpi_bus_id_list. */
|
||||
list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
|
||||
if (!strcmp(acpi_device_bus_id->bus_id, dev_id))
|
||||
return acpi_device_bus_id;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int acpi_device_add(struct acpi_device *device,
|
||||
void (*release)(struct device *))
|
||||
{
|
||||
struct acpi_device_bus_id *acpi_device_bus_id;
|
||||
int result;
|
||||
struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
|
||||
int found = 0;
|
||||
|
||||
if (device->handle) {
|
||||
acpi_status status;
|
||||
|
@ -654,38 +664,26 @@ int acpi_device_add(struct acpi_device *device,
|
|||
INIT_LIST_HEAD(&device->del_list);
|
||||
mutex_init(&device->physical_node_lock);
|
||||
|
||||
new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
|
||||
if (!new_bus_id) {
|
||||
pr_err(PREFIX "Memory allocation error\n");
|
||||
result = -ENOMEM;
|
||||
goto err_detach;
|
||||
}
|
||||
|
||||
mutex_lock(&acpi_device_lock);
|
||||
/*
|
||||
* Find suitable bus_id and instance number in acpi_bus_id_list
|
||||
* If failed, create one and link it into acpi_bus_id_list
|
||||
*/
|
||||
list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
|
||||
if (!strcmp(acpi_device_bus_id->bus_id,
|
||||
acpi_device_hid(device))) {
|
||||
acpi_device_bus_id->instance_no++;
|
||||
found = 1;
|
||||
kfree(new_bus_id);
|
||||
break;
|
||||
|
||||
acpi_device_bus_id = acpi_device_bus_id_match(acpi_device_hid(device));
|
||||
if (acpi_device_bus_id) {
|
||||
acpi_device_bus_id->instance_no++;
|
||||
} else {
|
||||
acpi_device_bus_id = kzalloc(sizeof(*acpi_device_bus_id),
|
||||
GFP_KERNEL);
|
||||
if (!acpi_device_bus_id) {
|
||||
result = -ENOMEM;
|
||||
goto err_unlock;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
acpi_device_bus_id = new_bus_id;
|
||||
acpi_device_bus_id->bus_id =
|
||||
kstrdup_const(acpi_device_hid(device), GFP_KERNEL);
|
||||
if (!acpi_device_bus_id->bus_id) {
|
||||
pr_err(PREFIX "Memory allocation error for bus id\n");
|
||||
kfree(acpi_device_bus_id);
|
||||
result = -ENOMEM;
|
||||
goto err_free_new_bus_id;
|
||||
goto err_unlock;
|
||||
}
|
||||
|
||||
acpi_device_bus_id->instance_no = 0;
|
||||
list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
|
||||
}
|
||||
dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
|
||||
|
@ -695,10 +693,12 @@ int acpi_device_add(struct acpi_device *device,
|
|||
|
||||
if (device->wakeup.flags.valid)
|
||||
list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
|
||||
|
||||
mutex_unlock(&acpi_device_lock);
|
||||
|
||||
if (device->parent)
|
||||
device->dev.parent = &device->parent->dev;
|
||||
|
||||
device->dev.bus = &acpi_bus_type;
|
||||
device->dev.release = release;
|
||||
result = device_add(&device->dev);
|
||||
|
@ -714,20 +714,19 @@ int acpi_device_add(struct acpi_device *device,
|
|||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
err:
|
||||
mutex_lock(&acpi_device_lock);
|
||||
|
||||
if (device->parent)
|
||||
list_del(&device->node);
|
||||
|
||||
list_del(&device->wakeup_list);
|
||||
|
||||
err_free_new_bus_id:
|
||||
if (!found)
|
||||
kfree(new_bus_id);
|
||||
|
||||
err_unlock:
|
||||
mutex_unlock(&acpi_device_lock);
|
||||
|
||||
err_detach:
|
||||
acpi_detach_data(device->handle, acpi_scan_drop_device);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue