From: "Rafael J. Wysocki" <[email protected]>
If acpi_dev_get_resources() returns overlapping I/O or memory resources,
the subsequent registration of a platform devices will fail with -EBUSY
due to a resource conflict. This is reported to happen on Acer Aspire
ES1-572 [1].
Avoid that by adjusting resources returned by acpi_dev_get_resources()
to eliminate partial overlaps between them.
This has not been regarded as necessary before because putting
overlapping resources into the _CRS of one device is really pointless,
but now that the issue has been reported to actually happen in the
field, it needs to be done.
Fixes: 8e345c991c8c ("ACPI: Centralized processing of ACPI device resources")
Fixes: 48fe2cddc85c ("tpm_crb: Convert ACPI driver to a platform one")
Reported-by: Julien <[email protected]>
Tested-by: Julien <[email protected]>
Closes:
https://lore.kernel.org/linux-integrity/cajogg3z6ljpdsdpnbxajgy8_wqxfhybrxe4eiurzf3kpu5a...@mail.gmail.com/
[1]
Cc: All applicable <[email protected]>
Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/acpi/acpi_platform.c | 39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
--- a/drivers/acpi/acpi_platform.c
+++ b/drivers/acpi/acpi_platform.c
@@ -71,6 +71,39 @@ static struct notifier_block acpi_platfo
.notifier_call = acpi_platform_device_remove_notify,
};
+static void acpi_platform_adjust_resource(struct acpi_device *adev,
+ struct resource *new_res,
+ const struct resource *resources,
+ unsigned int count)
+{
+ unsigned int i;
+
+ if (!(new_res->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
+ return;
+
+ for (i = 0; i < count; i++) {
+ const struct resource *res = &resources[i];
+
+ if (resource_type(new_res) != resource_type(res))
+ continue;
+
+ if (!resource_overlaps(new_res, res))
+ continue;
+
+ dev_info(&adev->dev, "Adjusting %pR for %pR\n", new_res, res);
+ /*
+ * Extend the new resource to include the one that has been
+ * processed already to avoid resource insertion failures during
+ * platform device registration.
+ */
+ if (res->start < new_res->start)
+ new_res->start = res->start;
+
+ if (res->end > new_res->end)
+ new_res->end = res->end;
+ }
+}
+
static void acpi_platform_fill_resource(struct acpi_device *adev,
const struct resource *src, struct resource *dest)
{
@@ -151,10 +184,12 @@ struct platform_device *acpi_create_plat
return ERR_PTR(-ENOMEM);
}
count = 0;
- list_for_each_entry(rentry, &resource_list, node)
+ list_for_each_entry(rentry, &resource_list, node) {
+ acpi_platform_adjust_resource(adev, rentry->res,
+ resources, count);
acpi_platform_fill_resource(adev, rentry->res,
&resources[count++]);
-
+ }
acpi_dev_free_resource_list(&resource_list);
}
}