[PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps

Rafael J. Wysocki posted 1 patch 1 month, 3 weeks ago
drivers/acpi/acpi_platform.c |   39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
[PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Rafael J. Wysocki 1 month, 3 weeks ago
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

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: ab06eb920401 ("ACPI: scan: Register platform devices for fixed event buttons")
Reported-by: Julien <julien82453@gmail.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>
---

v2 -> v3:
   * Use resource_union() and adjust code and comment (Andy)
   * Include ioport.h directly

v1 -> v2:
   * Add the expanded resource instead of and not in addition to the other
     overlapping one (Sashiko)

---
 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
@@ -12,6 +12,7 @@
 #include <linux/bits.h>
 #include <linux/device.h>
 #include <linux/err.h>
+#include <linux/ioport.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/dma-mapping.h>
@@ -71,6 +72,36 @@ static struct notifier_block acpi_platfo
 	.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 to avoid 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,
 	const struct resource *src, struct resource *dest)
 {
@@ -151,10 +182,14 @@ 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) {
+				count = acpi_platform_adjust_resources(adev,
+								       rentry->res,
+								       resources,
+								       count);
 				acpi_platform_fill_resource(adev, rentry->res,
 							    &resources[count++]);
-
+			}
 			acpi_dev_free_resource_list(&resource_list);
 		}
 	}
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Nathan Chancellor 1 month, 1 week ago
Hi Rafael,

On Fri, Aug 07, 2026 at 12:22:37PM +0200, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> 
> 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: ab06eb920401 ("ACPI: scan: Register platform devices for fixed event buttons")
> Reported-by: Julien <julien82453@gmail.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>

I bisected the following kernel message that I see on one of my aarch64
test machines to this change in -next as commit f234fdaae1ca ("ACPI:
scan: Avoid registering platform devices with resource overlaps"):

  arm-cmn ARMHC600:00: probe with driver arm-cmn failed with error -22

Is this expected? If not, what information would be helpful for debugging this?

  # bad: [e6664f2b33db9b6811eb4cec109f06cb2b4f458d] Add linux-next specific files for 20260817
  # good: [8d3ae59288f1e7d58d76558a6ee96d533bc5019f] Linux 7.2
  git bisect start 'e6664f2b33db9b6811eb4cec109f06cb2b4f458d' '8d3ae59288f1e7d58d76558a6ee96d533bc5019f'
  # bad: [86de7a3c48ad4465719822b6bfa176c136302e77] Merge branch 'master' of https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
  git bisect bad 86de7a3c48ad4465719822b6bfa176c136302e77
  # good: [984aee09cb35477fd7a27fa151e9f8c5a8cb99f9] Merge branch 'xtensa-for-next' of https://github.com/jcmvbkbc/linux-xtensa.git
  git bisect good 984aee09cb35477fd7a27fa151e9f8c5a8cb99f9
  # bad: [d353ba3f585141b91427fb87023e19c1f9ec85cd] Merge branch 'linux-next' of https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
  git bisect bad d353ba3f585141b91427fb87023e19c1f9ec85cd
  # good: [8bb759cc24c375a265eb6bf2f7c90eb2be20f535] Merge branch 'next' of https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git
  git bisect good 8bb759cc24c375a265eb6bf2f7c90eb2be20f535
  # good: [cdcbf4b274cf62bb9c9f589309315870ddf7250f] Merge branch 'docs-next' of git://git.lwn.net/linux.git
  git bisect good cdcbf4b274cf62bb9c9f589309315870ddf7250f
  # good: [edd0dd59aca038b7f32cf893170928d4a3b2297e] platform: int3472: discrete: Support multiple HIDs per GPIO map entry
  git bisect good edd0dd59aca038b7f32cf893170928d4a3b2297e
  # bad: [cb0428d1dfe236fe8ac926d120a0eb47cdca532e] Merge branch 'pm' into linux-next
  git bisect bad cb0428d1dfe236fe8ac926d120a0eb47cdca532e
  # good: [0c4067b3ff3c8b46076001449f566c4a4f58ede4] Merge branch 'pm-cpuidle'
  git bisect good 0c4067b3ff3c8b46076001449f566c4a4f58ede4
  # good: [02859a576afde166daceffdfb8eefc540fbfff9b] Merge branch 'acpi-irqchip'
  git bisect good 02859a576afde166daceffdfb8eefc540fbfff9b
  # bad: [79ba234b396b0fdcb3a82dd8aa872348f4069aae] Merge branch 'acpi-video'
  git bisect bad 79ba234b396b0fdcb3a82dd8aa872348f4069aae
  # good: [b0572550d83d84fa4d7e9088164ac528c5d82996] Merge back ACPI video bus driver changes for 7.3
  git bisect good b0572550d83d84fa4d7e9088164ac528c5d82996
  # good: [e61487226b7df39e5f4683b036ee6aa7a5039d7b] ACPI: APEI: Handle repeated SEA error storms
  git bisect good e61487226b7df39e5f4683b036ee6aa7a5039d7b
  # bad: [79a0aabd5d800a428ebd412ac1a996a686b53c34] Merge branches 'acpi-scan', 'acpi-pci', 'acpi-tad' and 'acpi-apei'
  git bisect bad 79a0aabd5d800a428ebd412ac1a996a686b53c34
  # good: [a3df8bbe0a704fa5c1609b9666b594f350558fe0] ACPI: TAD: Add locking around AML evaluations
  git bisect good a3df8bbe0a704fa5c1609b9666b594f350558fe0
  # good: [fa608d2875b57fac792a9e1c11aa1da91737f04a] ACPI: PCI: Avoid misleading _OSC messages for non-PCIe host bridges without _OSC
  git bisect good fa608d2875b57fac792a9e1c11aa1da91737f04a
  # bad: [f234fdaae1cad8c39265e7ca0a14633076ec7154] ACPI: scan: Avoid registering platform devices with resource overlaps
  git bisect bad f234fdaae1cad8c39265e7ca0a14633076ec7154
  # first 'bad' commit: [f234fdaae1cad8c39265e7ca0a14633076ec7154] ACPI: scan: Avoid registering platform devices with resource overlaps

-- 
Cheers,
Nathan
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Rafael J. Wysocki (Intel) 1 month, 1 week ago
Hi Nathan,

On Wed, Aug 19, 2026 at 2:37 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> Hi Rafael,
>
> On Fri, Aug 07, 2026 at 12:22:37PM +0200, Rafael J. Wysocki wrote:
> > From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> >
> > 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: ab06eb920401 ("ACPI: scan: Register platform devices for fixed event buttons")
> > Reported-by: Julien <julien82453@gmail.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>
>
> I bisected the following kernel message that I see on one of my aarch64
> test machines to this change in -next as commit f234fdaae1ca ("ACPI:
> scan: Avoid registering platform devices with resource overlaps"):
>
>   arm-cmn ARMHC600:00: probe with driver arm-cmn failed with error -22
>
> Is this expected? If not, what information would be helpful for debugging this?

No, it is not.

First, please send a boot log from the failing machine.

Second, I think we may need the acpidump output from it.
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Rafael J. Wysocki (Intel) 1 month, 1 week ago
On Wed, Aug 19, 2026 at 12:18 PM Rafael J. Wysocki (Intel)
<rafael@kernel.org> wrote:
>
> Hi Nathan,
>
> On Wed, Aug 19, 2026 at 2:37 AM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > Hi Rafael,
> >
> > On Fri, Aug 07, 2026 at 12:22:37PM +0200, Rafael J. Wysocki wrote:
> > > From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> > >
> > > 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: ab06eb920401 ("ACPI: scan: Register platform devices for fixed event buttons")
> > > Reported-by: Julien <julien82453@gmail.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>
> >
> > I bisected the following kernel message that I see on one of my aarch64
> > test machines to this change in -next as commit f234fdaae1ca ("ACPI:
> > scan: Avoid registering platform devices with resource overlaps"):
> >
> >   arm-cmn ARMHC600:00: probe with driver arm-cmn failed with error -22
> >
> > Is this expected? If not, what information would be helpful for debugging this?
>
> No, it is not.
>
> First, please send a boot log from the failing machine.
>
> Second, I think we may need the acpidump output from it.

So looking at the driver code, it expects to get two resources and it
is confused when it gets just one, so most likely arm_cmn_get_root()
fails.

I guess what happens is that originally one of the resources is within
the other one completely (or the creation of the platform device would
fail), which is kind of valid, so resource_overlaps() returns true for
them, and they get merged.  This means that
acpi_platform_adjust_resources() needs to look for partial overlaps
only.

I'll send a patch to adjust it later today.
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Andy Shevchenko 1 month, 1 week ago
On Tue, Aug 18, 2026 at 05:37:52PM -0700, Nathan Chancellor wrote:
> On Fri, Aug 07, 2026 at 12:22:37PM +0200, Rafael J. Wysocki wrote:
> > 
> > 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: ab06eb920401 ("ACPI: scan: Register platform devices for fixed event buttons")
> > Reported-by: Julien <julien82453@gmail.com>
> > Closes: https://lore.kernel.org/linux-integrity/CAJOGg3z6LJPDsdPNBxajgy8_wQxfhYBRxe4EiurZf3kPU5A5Bw@mail.gmail.com/ [1]
> 
> I bisected the following kernel message that I see on one of my aarch64
> test machines to this change in -next as commit f234fdaae1ca ("ACPI:
> scan: Avoid registering platform devices with resource overlaps"):
> 
>   arm-cmn ARMHC600:00: probe with driver arm-cmn failed with error -22
> 
> Is this expected? If not, what information would be helpful for debugging this?

Looks like a mess in _CRS. You can share dsdt.dsl to see if the resource
conflict is visible from there.

Does anything stop working?

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Rafael J. Wysocki (Intel) 1 month, 1 week ago
On Wed, Aug 19, 2026 at 9:46 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Tue, Aug 18, 2026 at 05:37:52PM -0700, Nathan Chancellor wrote:
> > On Fri, Aug 07, 2026 at 12:22:37PM +0200, Rafael J. Wysocki wrote:
> > >
> > > 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: ab06eb920401 ("ACPI: scan: Register platform devices for fixed event buttons")
> > > Reported-by: Julien <julien82453@gmail.com>
> > > Closes: https://lore.kernel.org/linux-integrity/CAJOGg3z6LJPDsdPNBxajgy8_wQxfhYBRxe4EiurZf3kPU5A5Bw@mail.gmail.com/ [1]
> >
> > I bisected the following kernel message that I see on one of my aarch64
> > test machines to this change in -next as commit f234fdaae1ca ("ACPI:
> > scan: Avoid registering platform devices with resource overlaps"):
> >
> >   arm-cmn ARMHC600:00: probe with driver arm-cmn failed with error -22
> >
> > Is this expected? If not, what information would be helpful for debugging this?
>
> Looks like a mess in _CRS. You can share dsdt.dsl to see if the resource
> conflict is visible from there.

Well, so long as the device is defined in the DSDT.

>
> Does anything stop working?

Apparently, a driver is not probing any more ...
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Andy Shevchenko 1 month, 1 week ago
On Wed, Aug 19, 2026 at 12:35:50PM +0200, Rafael J. Wysocki (Intel) wrote:
> On Wed, Aug 19, 2026 at 9:46 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Tue, Aug 18, 2026 at 05:37:52PM -0700, Nathan Chancellor wrote:

...

> > Does anything stop working?
> 
> Apparently, a driver is not probing any more ...

Yes, but it might be (however quite unlikely) the new message of the same
state of affairs (for example, driver wasn't probed, but silently).
Nevertheless, I assume that this driver is kinda critical and this is not
just a message.

-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Jarkko Sakkinen 1 month, 2 weeks ago
On Fri, Aug 07, 2026 at 12:22:37PM +0200, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> 
> 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: ab06eb920401 ("ACPI: scan: Register platform devices for fixed event buttons")
> Reported-by: Julien <julien82453@gmail.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>
> ---
> 
> v2 -> v3:
>    * Use resource_union() and adjust code and comment (Andy)
>    * Include ioport.h directly
> 
> v1 -> v2:
>    * Add the expanded resource instead of and not in addition to the other
>      overlapping one (Sashiko)
> 
> ---
>  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
> @@ -12,6 +12,7 @@
>  #include <linux/bits.h>
>  #include <linux/device.h>
>  #include <linux/err.h>
> +#include <linux/ioport.h>
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/dma-mapping.h>
> @@ -71,6 +72,36 @@ static struct notifier_block acpi_platfo
>  	.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 to avoid 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,
>  	const struct resource *src, struct resource *dest)
>  {
> @@ -151,10 +182,14 @@ 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) {
> +				count = acpi_platform_adjust_resources(adev,
> +								       rentry->res,
> +								       resources,
> +								       count);
>  				acpi_platform_fill_resource(adev, rentry->res,
>  							    &resources[count++]);
> -
> +			}
>  			acpi_dev_free_resource_list(&resource_list);
>  		}
>  	}
> 
> 
> 

Applied to my tree I'll just run some tests.

BR, Jarkko
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Rafael J. Wysocki (Intel) 1 month, 2 weeks ago
On Mon, Aug 10, 2026 at 5:35 PM Jarkko Sakkinen <jarkko@kernel.org> wrote:
>
> On Fri, Aug 07, 2026 at 12:22:37PM +0200, Rafael J. Wysocki wrote:
> > From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> >
> > 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: ab06eb920401 ("ACPI: scan: Register platform devices for fixed event buttons")
> > Reported-by: Julien <julien82453@gmail.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>
> > ---
> >
> > v2 -> v3:
> >    * Use resource_union() and adjust code and comment (Andy)
> >    * Include ioport.h directly
> >
> > v1 -> v2:
> >    * Add the expanded resource instead of and not in addition to the other
> >      overlapping one (Sashiko)
> >
> > ---
> >  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
> > @@ -12,6 +12,7 @@
> >  #include <linux/bits.h>
> >  #include <linux/device.h>
> >  #include <linux/err.h>
> > +#include <linux/ioport.h>
> >  #include <linux/kernel.h>
> >  #include <linux/module.h>
> >  #include <linux/dma-mapping.h>
> > @@ -71,6 +72,36 @@ static struct notifier_block acpi_platfo
> >       .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 to avoid 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,
> >       const struct resource *src, struct resource *dest)
> >  {
> > @@ -151,10 +182,14 @@ 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) {
> > +                             count = acpi_platform_adjust_resources(adev,
> > +                                                                    rentry->res,
> > +                                                                    resources,
> > +                                                                    count);
> >                               acpi_platform_fill_resource(adev, rentry->res,
> >                                                           &resources[count++]);
> > -
> > +                     }
> >                       acpi_dev_free_resource_list(&resource_list);
> >               }
> >       }
> >
> >
> >
>
> Applied to my tree I'll just run some tests.

Well, I've applied it too because I have material that depends on it.

I guess it won't be a big deal if it goes in from two different places.
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Andy Shevchenko 1 month, 3 weeks ago
On Fri, Aug 07, 2026 at 12:22:37PM +0200, Rafael J. Wysocki wrote:

> 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.

...

>    * Use resource_union() and adjust code and comment (Andy)

Thanks, LGTM now,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> +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)))

Can also be

	if (!(resource_type(new_res) & (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)) {

Wondering why we don't have the resource type checks in resource_overlaps(),
but we have in resource_contains(). Ilpo, do you know?

> +			i++;
> +			continue;
> +		}
> +
> +		dev_info(&adev->dev, "%pR expanded to avoid 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;
> +}

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Rafael J. Wysocki (Intel) 1 month, 2 weeks ago
On Sat, Aug 8, 2026 at 10:04 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Fri, Aug 07, 2026 at 12:22:37PM +0200, Rafael J. Wysocki wrote:
>
> > 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.
>
> ...
>
> >    * Use resource_union() and adjust code and comment (Andy)
>
> Thanks, LGTM now,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks!

> > +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)))
>
> Can also be
>
>         if (!(resource_type(new_res) & (IORESOURCE_IO | IORESOURCE_MEM)))

It could, but it would add a redundant "bitwise and" with the type mask.

I guess the compiler can be expected to optimize it away, but if it
doesn't get optimized away, it's just pure useless overhead.

> > +             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)) {
>
> Wondering why we don't have the resource type checks in resource_overlaps(),

Yeah, it looks like a missing piece.

> but we have in resource_contains(). Ilpo, do you know?
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Paul Menzel 1 month, 3 weeks ago
Dear Rafael,


Thank you for the patch.

Am 07.08.26 um 12:22 schrieb Rafael J. Wysocki:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> 
> 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].

Reading the diff, it might be useful to paste the log warning already here:

     tpm_crb_acpi MSFT0101:00: [Firmware Bug]: Bad ACPI memory layout

> 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: ab06eb920401 ("ACPI: scan: Register platform devices for fixed event buttons")
> Reported-by: Julien <julien82453@gmail.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>
> ---
> 
> v2 -> v3:
>     * Use resource_union() and adjust code and comment (Andy)
>     * Include ioport.h directly
> 
> v1 -> v2:
>     * Add the expanded resource instead of and not in addition to the other
>       overlapping one (Sashiko)
> 
> ---
>   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
> @@ -12,6 +12,7 @@
>   #include <linux/bits.h>
>   #include <linux/device.h>
>   #include <linux/err.h>
> +#include <linux/ioport.h>
>   #include <linux/kernel.h>
>   #include <linux/module.h>
>   #include <linux/dma-mapping.h>
> @@ -71,6 +72,36 @@ static struct notifier_block acpi_platfo
>   	.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 to avoid overlap\n", new_res);

Maybe more normal user understandable:

     %pR expanded to fit all resources to avoid overlap

For the record, Julian reported that now the lines below are logged:

     MSFT0101:00: [mem 0xfed40000-0xfed4103f] expanded to avoid overlap
     tpm_crb_acpi MSFT0101:00: [Firmware Bug]: Bad ACPI memory layout

> +		/*
> +		 * 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,
>   	const struct resource *src, struct resource *dest)
>   {
> @@ -151,10 +182,14 @@ 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) {
> +				count = acpi_platform_adjust_resources(adev,
> +								       rentry->res,
> +								       resources,
> +								       count);
>   				acpi_platform_fill_resource(adev, rentry->res,
>   							    &resources[count++]);
> -
> +			}
>   			acpi_dev_free_resource_list(&resource_list);
>   		}
>   	}

Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>


Kind regards,

Paul
Re: [PATCH v3] ACPI: scan: Avoid registering platform devices with resource overlaps
Posted by Rafael J. Wysocki (Intel) 1 month, 3 weeks ago
On Fri, Aug 7, 2026 at 2:57 PM Paul Menzel <pmenzel@molgen.mpg.de> wrote:
>
> Dear Rafael,
>
>
> Thank you for the patch.
>
> Am 07.08.26 um 12:22 schrieb Rafael J. Wysocki:
> > From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> >
> > 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].
>
> Reading the diff, it might be useful to paste the log warning already here:
>
>      tpm_crb_acpi MSFT0101:00: [Firmware Bug]: Bad ACPI memory layout

It's there in the message pointed to by the Closes: tag though.

> > 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: ab06eb920401 ("ACPI: scan: Register platform devices for fixed event buttons")
> > Reported-by: Julien <julien82453@gmail.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>
> > ---
> >
> > v2 -> v3:
> >     * Use resource_union() and adjust code and comment (Andy)
> >     * Include ioport.h directly
> >
> > v1 -> v2:
> >     * Add the expanded resource instead of and not in addition to the other
> >       overlapping one (Sashiko)
> >
> > ---
> >   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
> > @@ -12,6 +12,7 @@
> >   #include <linux/bits.h>
> >   #include <linux/device.h>
> >   #include <linux/err.h>
> > +#include <linux/ioport.h>
> >   #include <linux/kernel.h>
> >   #include <linux/module.h>
> >   #include <linux/dma-mapping.h>
> > @@ -71,6 +72,36 @@ static struct notifier_block acpi_platfo
> >       .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 to avoid overlap\n", new_res);
>
> Maybe more normal user understandable:
>
>      %pR expanded to fit all resources to avoid overlap

What about "expanded due to overlap"?  I'd prefer it to be shorter
because the resource printout takes up some message space already.

> For the record, Julian reported that now the lines below are logged:
>
>      MSFT0101:00: [mem 0xfed40000-0xfed4103f] expanded to avoid overlap
>      tpm_crb_acpi MSFT0101:00: [Firmware Bug]: Bad ACPI memory layout

Right, and the second one comes from the driver binding to the device.

> > +             /*
> > +              * 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,
> >       const struct resource *src, struct resource *dest)
> >   {
> > @@ -151,10 +182,14 @@ 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) {
> > +                             count = acpi_platform_adjust_resources(adev,
> > +                                                                    rentry->res,
> > +                                                                    resources,
> > +                                                                    count);
> >                               acpi_platform_fill_resource(adev, rentry->res,
> >                                                           &resources[count++]);
> > -
> > +                     }
> >                       acpi_dev_free_resource_list(&resource_list);
> >               }
> >       }
>
> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>

Thank you!