mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 20:54:03 +02:00
ACPI: scan: Avoid registering platform devices with resource overlaps
If acpi_dev_get_resources() returns overlapping I/O or memory resources, the subsequent registration of a platform device 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:ab06eb9204("ACPI: scan: Register platform devices for fixed event buttons") Fixes:48fe2cddc8("tpm_crb: Convert ACPI driver to a platform one") Reported-by: Julien <julien82453@gmail.com> Tested-by: Julien <julien82453@gmail.com> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Closes: https://lore.kernel.org/linux-integrity/CAJOGg3z6LJPDsdPNBxajgy8_wQxfhYBRxe4EiurZf3kPU5A5Bw@mail.gmail.com/ [1] Cc: All applicable <stable@vger.kernel.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> [ rjw: Tweaked the new message ] Link: https://patch.msgid.link/12955541.O9o76ZdvQC@rafael.j.wysocki Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
075b74841b
commit
f234fdaae1
|
|
@ -12,6 +12,7 @@
|
||||||
#include <linux/bits.h>
|
#include <linux/bits.h>
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
|
#include <linux/ioport.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/dma-mapping.h>
|
#include <linux/dma-mapping.h>
|
||||||
|
|
@ -71,6 +72,36 @@ static struct notifier_block acpi_platform_notifier = {
|
||||||
.notifier_call = acpi_platform_device_remove_notify,
|
.notifier_call = acpi_platform_device_remove_notify,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static unsigned int acpi_platform_adjust_resources(struct acpi_device *adev,
|
||||||
|
struct resource *new_res,
|
||||||
|
struct resource *resources,
|
||||||
|
unsigned int count)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
if (!(new_res->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
|
||||||
|
return count;
|
||||||
|
|
||||||
|
for (i = 0; i < count; ) {
|
||||||
|
struct resource *res = &resources[i];
|
||||||
|
|
||||||
|
if (resource_type(new_res) != resource_type(res) ||
|
||||||
|
!resource_union(new_res, res, new_res)) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_info(&adev->dev, "%pR expanded due to overlap\n", new_res);
|
||||||
|
/*
|
||||||
|
* Eliminate the previously processed resource that overlapped
|
||||||
|
* with the new one because it is not necessary any more.
|
||||||
|
*/
|
||||||
|
memmove(res, res + 1, (--count - i) * sizeof(*res));
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
static void acpi_platform_fill_resource(struct acpi_device *adev,
|
static void acpi_platform_fill_resource(struct acpi_device *adev,
|
||||||
const struct resource *src, struct resource *dest)
|
const struct resource *src, struct resource *dest)
|
||||||
{
|
{
|
||||||
|
|
@ -151,10 +182,14 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
}
|
}
|
||||||
count = 0;
|
count = 0;
|
||||||
list_for_each_entry(rentry, &resource_list, node)
|
list_for_each_entry(rentry, &resource_list, node) {
|
||||||
|
count = acpi_platform_adjust_resources(adev,
|
||||||
|
rentry->res,
|
||||||
|
resources,
|
||||||
|
count);
|
||||||
acpi_platform_fill_resource(adev, rentry->res,
|
acpi_platform_fill_resource(adev, rentry->res,
|
||||||
&resources[count++]);
|
&resources[count++]);
|
||||||
|
}
|
||||||
acpi_dev_free_resource_list(&resource_list);
|
acpi_dev_free_resource_list(&resource_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user