}
 }
 
-static int acpi_ec_add(struct acpi_device *device)
+static struct acpi_ec *acpi_ec_alloc(void)
 {
-       struct acpi_ec *ec = NULL;
-       int ret;
-
-       strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
-       strcpy(acpi_device_class(device), ACPI_EC_CLASS);
+       struct acpi_ec *ec;
 
        /* Check for boot EC */
        if (boot_ec) {
                        first_ec = NULL;
        } else {
                ec = make_acpi_ec();
-               if (!ec)
-                       return -ENOMEM;
        }
+       return ec;
+}
+
+static int acpi_ec_add(struct acpi_device *device)
+{
+       struct acpi_ec *ec = NULL;
+       int ret;
+
+       strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
+       strcpy(acpi_device_class(device), ACPI_EC_CLASS);
+
+       ec = acpi_ec_alloc();
+       if (!ec)
+               return -ENOMEM;
        if (ec_parse_device(device->handle, 0, ec, NULL) !=
                AE_CTRL_TERMINATE) {
                        kfree(ec);
 int __init acpi_ec_dsdt_probe(void)
 {
        acpi_status status;
+       struct acpi_ec *ec;
+       int ret;
 
-       if (boot_ec)
-               return 0;
-
+       ec = acpi_ec_alloc();
+       if (!ec)
+               return -ENOMEM;
        /*
         * Finding EC from DSDT if there is no ECDT EC available. When this
         * function is invoked, ACPI tables have been fully loaded, we can
         * walk namespace now.
         */
-       boot_ec = make_acpi_ec();
-       if (!boot_ec)
-               return -ENOMEM;
        status = acpi_get_devices(ec_device_ids[0].id,
-                                 ec_parse_device, boot_ec, NULL);
-       if (ACPI_FAILURE(status) || !boot_ec->handle)
-               return -ENODEV;
-       if (!ec_install_handlers(boot_ec)) {
-               first_ec = boot_ec;
-               return 0;
+                                 ec_parse_device, ec, NULL);
+       if (ACPI_FAILURE(status) || !ec->handle) {
+               ret = -ENODEV;
+               goto error;
        }
-       return -EFAULT;
+       ret = ec_install_handlers(ec);
+
+error:
+       if (ret)
+               kfree(ec);
+       else
+               first_ec = boot_ec = ec;
+       return ret;
 }
 
 #if 0
 
 int __init acpi_ec_ecdt_probe(void)
 {
-       int ret = 0;
+       int ret;
        acpi_status status;
        struct acpi_table_ecdt *ecdt_ptr;
+       struct acpi_ec *ec;
 
-       boot_ec = make_acpi_ec();
-       if (!boot_ec)
+       ec = acpi_ec_alloc();
+       if (!ec)
                return -ENOMEM;
        /*
         * Generate a boot ec context
                 * MSI MS-171F
                 * https://bugzilla.kernel.org/show_bug.cgi?id=12461
                 */
-               boot_ec->command_addr = ecdt_ptr->data.address;
-               boot_ec->data_addr = ecdt_ptr->control.address;
+               ec->command_addr = ecdt_ptr->data.address;
+               ec->data_addr = ecdt_ptr->control.address;
        } else {
-               boot_ec->command_addr = ecdt_ptr->control.address;
-               boot_ec->data_addr = ecdt_ptr->data.address;
+               ec->command_addr = ecdt_ptr->control.address;
+               ec->data_addr = ecdt_ptr->data.address;
        }
-       boot_ec->gpe = ecdt_ptr->gpe;
-       boot_ec->handle = ACPI_ROOT_OBJECT;
-       ret = ec_install_handlers(boot_ec);
-       if (!ret)
-               first_ec = boot_ec;
+       ec->gpe = ecdt_ptr->gpe;
+       ec->handle = ACPI_ROOT_OBJECT;
+       ret = ec_install_handlers(ec);
 error:
-       if (ret) {
-               kfree(boot_ec);
-               boot_ec = NULL;
-       }
+       if (ret)
+               kfree(ec);
+       else
+               first_ec = boot_ec = ec;
        return ret;
 }