return count;
 }
 
-static bool acpi_bus_scan_second_pass;
-
 static acpi_status acpi_bus_check_add(acpi_handle handle, bool check_dep,
                                      struct acpi_device **adev_p)
 {
                        return AE_OK;
 
                /* Bail out if there are dependencies. */
-               if (acpi_scan_check_dep(handle, check_dep) > 0) {
-                       acpi_bus_scan_second_pass = true;
+               if (acpi_scan_check_dep(handle, check_dep) > 0)
                        return AE_CTRL_DEPTH;
-               }
 
                fallthrough;
        case ACPI_TYPE_ANY:     /* for ACPI_ROOT_OBJECT */
        return true;
 }
 
+static void acpi_scan_delete_dep_data(struct acpi_dep_data *dep)
+{
+       list_del(&dep->node);
+       kfree(dep);
+}
+
 static int acpi_scan_clear_dep(struct acpi_dep_data *dep, void *data)
 {
        struct acpi_device *adev = acpi_get_acpi_dev(dep->consumer);
                        acpi_dev_put(adev);
        }
 
-       list_del(&dep->node);
-       kfree(dep);
+       if (dep->free_when_met)
+               acpi_scan_delete_dep_data(dep);
+       else
+               dep->met = true;
 
        return 0;
 }
 }
 EXPORT_SYMBOL_GPL(acpi_dev_get_next_consumer_dev);
 
+static void acpi_scan_postponed_branch(acpi_handle handle)
+{
+       struct acpi_device *adev = NULL;
+
+       if (ACPI_FAILURE(acpi_bus_check_add(handle, false, &adev)))
+               return;
+
+       acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
+                           acpi_bus_check_add_2, NULL, NULL, (void **)&adev);
+       acpi_bus_attach(adev, NULL);
+}
+
+static void acpi_scan_postponed(void)
+{
+       struct acpi_dep_data *dep, *tmp;
+
+       mutex_lock(&acpi_dep_list_lock);
+
+       list_for_each_entry_safe(dep, tmp, &acpi_dep_list, node) {
+               acpi_handle handle = dep->consumer;
+
+               /*
+                * In case there are multiple acpi_dep_list entries with the
+                * same consumer, skip the current entry if the consumer device
+                * object corresponding to it is present already.
+                */
+               if (!acpi_fetch_acpi_dev(handle)) {
+                       /*
+                        * Even though the lock is released here, tmp is
+                        * guaranteed to be valid, because none of the list
+                        * entries following dep is marked as "free when met"
+                        * and so they cannot be deleted.
+                        */
+                       mutex_unlock(&acpi_dep_list_lock);
+
+                       acpi_scan_postponed_branch(handle);
+
+                       mutex_lock(&acpi_dep_list_lock);
+               }
+
+               if (dep->met)
+                       acpi_scan_delete_dep_data(dep);
+               else
+                       dep->free_when_met = true;
+       }
+
+       mutex_unlock(&acpi_dep_list_lock);
+}
+
 /**
  * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
  * @handle: Root of the namespace scope to scan.
 {
        struct acpi_device *device = NULL;
 
-       acpi_bus_scan_second_pass = false;
-
        /* Pass 1: Avoid enumerating devices with missing dependencies. */
 
        if (ACPI_SUCCESS(acpi_bus_check_add(handle, true, &device)))
 
        acpi_bus_attach(device, (void *)true);
 
-       if (!acpi_bus_scan_second_pass)
-               return 0;
-
        /* Pass 2: Enumerate all of the remaining devices. */
 
-       device = NULL;
-
-       if (ACPI_SUCCESS(acpi_bus_check_add(handle, false, &device)))
-               acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
-                                   acpi_bus_check_add_2, NULL, NULL,
-                                   (void **)&device);
-
-       acpi_bus_attach(device, NULL);
+       acpi_scan_postponed();
 
        return 0;
 }