Skip to contentSkip to conversation

drivers/acpi/processor_idle: check the return value of acpi_fetch_acpi_dev()

PATCH In review Li Zhong 2 participants 4 messages Aug 28, 2022 – Sep 10, 2022 ACPI

lore
Share & tools
lore

Li Zhong

author
#0 lore raw

PATCH 1/1 drivers/acpi/processor_idle: check the return value of acpi_fetch_acpi_dev()

The return value of acpi_fetch_acpi_dev() could be NULL, which will cause null pointer dereference if used in acpi_device_hid().

---
 drivers/acpi/processor_idle.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/processor_idle.c +2 -0
index 16a1663d02d4..519f8f741da3 100644
@@ -1117,6 +1117,8 @@ static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
 	status = acpi_get_parent(handle, &pr_ahandle);
 	while (ACPI_SUCCESS(status)) {
 		d = acpi_fetch_acpi_dev(pr_ahandle);
+		if (!d)
+			break;
 		handle = pr_ahandle;
 
 		if (strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID))
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Li Zhong

The return value of acpi_fetch_acpi_dev() could be NULL, which will cause null pointer dereference if used in acpi_device_hid().

That's true.

Quoted 10 lines
---
 drivers/acpi/processor_idle.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/processor_idle.c +0 -0
index 16a1663d02d4..519f8f741da3 100644

drivers/acpi/processor_idle.c static int acpi_processor_get_lpi_info(struct acpi_processor *pr) · line 1121

Quoted 5 lines
drivers/acpi/processor_idle.c +2 -0
@@ -1117,6 +1117,8 @@ static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
        status = acpi_get_parent(handle, &pr_ahandle);
        while (ACPI_SUCCESS(status)) {
                d = acpi_fetch_acpi_dev(pr_ahandle);
+               if (!d)
+                       break;

But shouldn't this be continue?

Quoted 6 lines
drivers/acpi/processor_idle.c +0 -1
                handle = pr_ahandle;
 
                if (strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID))
--

2.25.1

author
#2 lore raw
Quoted 13 lines · Rafael J. Wysocki
Quoted 3 lines · Li Zhong

The return value of acpi_fetch_acpi_dev() could be NULL, which will cause null pointer dereference if used in acpi_device_hid().

That's true.

Quoted 5 lines
---
 drivers/acpi/processor_idle.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 13 lines

drivers/acpi/processor_idle.c static int acpi_processor_get_lpi_info(struct acpi_processor *pr) · line 1121

Quoted 10 lines
drivers/acpi/processor_idle.c +2 -0
index 16a1663d02d4..519f8f741da3 100644
@@ -1117,6 +1117,8 @@ static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
        status = acpi_get_parent(handle, &pr_ahandle);
        while (ACPI_SUCCESS(status)) {
                d = acpi_fetch_acpi_dev(pr_ahandle);
+               if (!d)
+                       break;

But shouldn't this be continue?

I think here is break instead of continue because if we use continue, variable status will not change. Then the while condition will stay true and loop forever.

Quoted 6 lines
Quoted 6 lines
drivers/acpi/processor_idle.c +0 -1
                handle = pr_ahandle;
 
                if (strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID))
--

2.25.1

#3 lore raw
In reply to Li Zhong
Quoted 14 lines · Li Zhong

The return value of acpi_fetch_acpi_dev() could be NULL, which will cause null pointer dereference if used in acpi_device_hid().

---
 drivers/acpi/processor_idle.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/processor_idle.c +0 -0
index 16a1663d02d4..519f8f741da3 100644

drivers/acpi/processor_idle.c static int acpi_processor_get_lpi_info(struct acpi_processor *pr)

Quoted 9 lines
drivers/acpi/processor_idle.c +2 -1
@@ -1117,6 +1117,8 @@ static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
        status = acpi_get_parent(handle, &pr_ahandle);
        while (ACPI_SUCCESS(status)) {
                d = acpi_fetch_acpi_dev(pr_ahandle);
+               if (!d)
+                       break;
                handle = pr_ahandle;
 
                if (strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID))
--

Applied (with some edits in the subject and changelog) as 6.1 material, thanks!