Skip to content

Commit e3cfabc

Browse files
committed
ACPI: EC: Simplify acpi_ec_add()
First, notice that if the device ID in acpi_ec_add() is equal to ACPI_ECDT_HID, boot_ec_is_ecdt must be set, because this means that the device object passed to acpi_ec_add() comes from acpi_ec_ecdt_start() which fails if boot_ec_is_ecdt is unset. Accordingly, boot_ec_is_ecdt need not be set again in that case, so drop that redundant update of it from the code. Next, ec->handle must be a valid ACPI handle right before returning 0 from acpi_ec_add(), because it either is the handle of the device object passed to that function, or it is the boot EC handle coming from acpi_ec_ecdt_start() which fails if it cannot find a valid handle for the boot EC. Moreover, the object with that handle is regarded as a valid representation of the EC in all cases, so there is no reason to avoid the _DEP list update walk if that handle is the boot EC handle. Accordingly, drop the dep_update local variable from acpi_ec_add() and call acpi_walk_dep_device_list() for ec->handle unconditionally before returning 0 from it. Finally, the ec local variable in acpi_ec_add() need not be initialized to NULL and the status local variable declaration can be moved to the block in which it is used, so change the code in accordance with these observations. Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 7247f0c commit e3cfabc

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

drivers/acpi/ec.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,19 +1605,18 @@ static bool acpi_ec_ecdt_get_handle(acpi_handle *phandle)
16051605

16061606
static int acpi_ec_add(struct acpi_device *device)
16071607
{
1608-
struct acpi_ec *ec = NULL;
1609-
bool dep_update = true;
1610-
acpi_status status;
1608+
struct acpi_ec *ec;
16111609
int ret;
16121610

16131611
strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
16141612
strcpy(acpi_device_class(device), ACPI_EC_CLASS);
16151613

16161614
if (!strcmp(acpi_device_hid(device), ACPI_ECDT_HID)) {
1617-
boot_ec_is_ecdt = true;
1615+
/* Fast path: this device corresponds to the boot EC. */
16181616
ec = boot_ec;
1619-
dep_update = false;
16201617
} else {
1618+
acpi_status status;
1619+
16211620
ec = acpi_ec_alloc();
16221621
if (!ec)
16231622
return -ENOMEM;
@@ -1660,10 +1659,9 @@ static int acpi_ec_add(struct acpi_device *device)
16601659
ret = !!request_region(ec->command_addr, 1, "EC cmd");
16611660
WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr);
16621661

1663-
if (dep_update) {
1664-
/* Reprobe devices depending on the EC */
1665-
acpi_walk_dep_device_list(ec->handle);
1666-
}
1662+
/* Reprobe devices depending on the EC */
1663+
acpi_walk_dep_device_list(ec->handle);
1664+
16671665
acpi_handle_debug(ec->handle, "enumerated.\n");
16681666
return 0;
16691667

0 commit comments

Comments
 (0)