Linux ACPI
 help / color / mirror / Atom feed
* [PATCH v2] PCI/ACPI: Check the found handle in acpi_get_rc_resources()
@ 2026-11-15  9:12 lirongqing
  2026-11-15 17:06 ` Rafael J. Wysocki (Intel)
  0 siblings, 1 reply; 3+ messages in thread
From: lirongqing @ 2026-11-15  9:12 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown, Bjorn Helgaas, linux-acpi,
	linux-pci, linux-kernel
  Cc: Li RongQing

From: Li RongQing <lirongqing@baidu.com>

acpi_get_devices() returns AE_OK even when the namespace walk finishes
without a match, in which case the return_value argument is not written.
The caller passes an uninitialized acpi_handle and hands it to
acpi_fetch_acpi_dev(), which dereferences it as an ACPI node.

Initialize the handle and reject a missing match.

Fixes: 169de969c018 ("PCI/ACPI: Provide acpi_get_rc_resources() for ARM64 platform")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
Diff with v1: add fixes tag

 drivers/pci/pci-acpi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index e260089..e90e749 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -82,7 +82,7 @@ int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment,
 {
 	struct acpi_device *adev;
 	acpi_status status;
-	acpi_handle handle;
+	acpi_handle handle = NULL;
 	int ret;
 
 	status = acpi_get_devices(hid, acpi_match_rc, &segment, &handle);
@@ -92,6 +92,9 @@ int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment,
 		return -ENODEV;
 	}
 
+	if (!handle)
+		return -ENODEV;
+
 	adev = acpi_fetch_acpi_dev(handle);
 	if (!adev)
 		return -ENODEV;
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] PCI/ACPI: Check the found handle in acpi_get_rc_resources()
  2026-11-15  9:12 [PATCH v2] PCI/ACPI: Check the found handle in acpi_get_rc_resources() lirongqing
@ 2026-11-15 17:06 ` Rafael J. Wysocki (Intel)
  2026-11-16  3:05   ` 答复: [外部邮件] " Li,Rongqing
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-15 17:06 UTC (permalink / raw)
  To: lirongqing
  Cc: Rafael J . Wysocki, Len Brown, Bjorn Helgaas, linux-acpi,
	linux-pci, linux-kernel

On Sun, Nov 15, 2026 at 10:12 AM lirongqing <lirongqing@baidu.com> wrote:
>
> From: Li RongQing <lirongqing@baidu.com>
>
> acpi_get_devices() returns AE_OK even when the namespace walk finishes
> without a match, in which case the return_value argument is not written.
> The caller passes an uninitialized acpi_handle and hands it to
> acpi_fetch_acpi_dev(), which dereferences it as an ACPI node.
>
> Initialize the handle and reject a missing match.
>
> Fixes: 169de969c018 ("PCI/ACPI: Provide acpi_get_rc_resources() for ARM64 platform")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> Diff with v1: add fixes tag
>
>  drivers/pci/pci-acpi.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
> index e260089..e90e749 100644
> --- a/drivers/pci/pci-acpi.c
> +++ b/drivers/pci/pci-acpi.c
> @@ -82,7 +82,7 @@ int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment,
>  {
>         struct acpi_device *adev;
>         acpi_status status;
> -       acpi_handle handle;
> +       acpi_handle handle = NULL;
>         int ret;
>
>         status = acpi_get_devices(hid, acpi_match_rc, &segment, &handle);
> @@ -92,6 +92,9 @@ int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment,
>                 return -ENODEV;
>         }
>
> +       if (!handle)
> +               return -ENODEV;

acpi_fetch_acpi_dev() will return NULL if handle is NULL, won't it?

> +
>         adev = acpi_fetch_acpi_dev(handle);
>         if (!adev)
>                 return -ENODEV;
> --

^ permalink raw reply	[flat|nested] 3+ messages in thread

* 答复: [外部邮件] Re: [PATCH v2] PCI/ACPI: Check the found handle in acpi_get_rc_resources()
  2026-11-15 17:06 ` Rafael J. Wysocki (Intel)
@ 2026-11-16  3:05   ` Li,Rongqing
  0 siblings, 0 replies; 3+ messages in thread
From: Li,Rongqing @ 2026-11-16  3:05 UTC (permalink / raw)
  To: Rafael J. Wysocki (Intel)
  Cc: Len Brown, Bjorn Helgaas, linux-acpi@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org

> > From: Li RongQing <lirongqing@baidu.com>
> >
> > acpi_get_devices() returns AE_OK even when the namespace walk finishes
> > without a match, in which case the return_value argument is not written.
> > The caller passes an uninitialized acpi_handle and hands it to
> > acpi_fetch_acpi_dev(), which dereferences it as an ACPI node.
> >
> > Initialize the handle and reject a missing match.
> >
> > Fixes: 169de969c018 ("PCI/ACPI: Provide acpi_get_rc_resources() for
> > ARM64 platform")
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> > ---
> > Diff with v1: add fixes tag
> >
> >  drivers/pci/pci-acpi.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index
> > e260089..e90e749 100644
> > --- a/drivers/pci/pci-acpi.c
> > +++ b/drivers/pci/pci-acpi.c
> > @@ -82,7 +82,7 @@ int acpi_get_rc_resources(struct device *dev, const
> > char *hid, u16 segment,  {
> >         struct acpi_device *adev;
> >         acpi_status status;
> > -       acpi_handle handle;
> > +       acpi_handle handle = NULL;
> >         int ret;
> >
> >         status = acpi_get_devices(hid, acpi_match_rc, &segment,
> > &handle); @@ -92,6 +92,9 @@ int acpi_get_rc_resources(struct device
> *dev, const char *hid, u16 segment,
> >                 return -ENODEV;
> >         }
> >
> > +       if (!handle)
> > +               return -ENODEV;
> 
> acpi_fetch_acpi_dev() will return NULL if handle is NULL, won't it?
> 

Agreed that acpi_fetch_acpi_dev(NULL) is safe today — acpi_get_data_full() rejects NULL up front. But that safety is incidental, not contractual: the handle layer doesn't uniformly reject NULL (acpi_ns_validate_handle() even maps it to the root node), so relying on it makes the fix fragile to future changes. The explicit check states the "no match ⇒ -ENODEV" intent directly and costs 3 lines. If you prefer the minimal diff, I can drop it — the initialization alone is also correct. 

Thanks


[Li,Rongqing] 


> > +
> >         adev = acpi_fetch_acpi_dev(handle);
> >         if (!adev)
> >                 return -ENODEV;
> > --

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-16  3:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15  9:12 [PATCH v2] PCI/ACPI: Check the found handle in acpi_get_rc_resources() lirongqing
2026-11-15 17:06 ` Rafael J. Wysocki (Intel)
2026-11-16  3:05   ` 答复: [外部邮件] " Li,Rongqing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox