Skip to contentSkip to conversation

ACPICA: Fix memory leak caused by _CID repair function

PATCH In review Erik Kaneda 2 participants 3 messages Apr 28, 2021 – Apr 30, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPICA: Fix memory leak caused by _CID repair function

ACPICA commit 5fc4f4b87d6890d48d050ab279ed01f0132662ca

According to the ACPI spec, _CID returns a package containing hardware ID's. Each element of an ASL package contains a reference count from the parent package as well as the element itself.

Name (TEST, Package() {
"String object" // this package element has a reference count of 2
})

A memory leak was caused in the _CID repair function because it did not decrement the reference count created by the package. Fix the memory leak by calling acpi_ut_remove_reference on _CID package elements that represent a hardware ID (_HID).

---
 drivers/acpi/acpica/nsrepair2.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/acpica/nsrepair2.c +7 -0
index 14b71b41e845..38e10ab976e6 100644
@@ -379,6 +379,13 @@ acpi_ns_repair_CID(struct acpi_evaluate_info *info,
 
 			(*element_ptr)->common.reference_count =
 			    original_ref_count;
+
+			/*
+			 * The original_element holds a reference from the package object
+			 * that represents _HID. Since a new element was created by _HID,
+			 * remove the reference from the _CID package.
+			 */
+			acpi_ut_remove_reference(original_element);
 		}
 
 		element_ptr++;
Signature · 1 line
2.29.2
#1 lore raw

Shawn,

Could you test this patch using the setup that you used to report the crash?
https://github.com/acpica/acpica/commit/d095b337ae1f107ad66bec19a99b4d7affae2fc4

Thanks,
Erik

Quoted 56 lines

-----Original Message-----
From: Kaneda, Erik <[email protected]>
Sent: Wednesday, April 28, 2021 3:53 PM
To: Rafael J . Wysocki <[email protected]>; ACPI Devel Maling List <linux- [email protected]>; Shawn Guo <[email protected]>; Gordon Ross <[email protected]>
Cc: Moore; Moore, Robert <[email protected]>; Kaneda, Erik <[email protected]>
Subject: [RFT PATCH] ACPICA: Fix memory leak caused by _CID repair function

ACPICA commit 5fc4f4b87d6890d48d050ab279ed01f0132662ca

According to the ACPI spec, _CID returns a package containing hardware ID's. Each element of an ASL package contains a reference count from the parent package as well as the element itself.

Name (TEST, Package() {
"String object" // this package element has a reference count of 2
})

A memory leak was caused in the _CID repair function because it did not decrement the reference count created by the package. Fix the memory leak by calling acpi_ut_remove_reference on _CID package elements
that represent a hardware ID (_HID).

---
 drivers/acpi/acpica/nsrepair2.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/acpica/nsrepair2.c +3 -0
index 14b71b41e845..38e10ab976e6 100644
@@ -379,6 +379,13 @@ acpi_ns_repair_CID(struct acpi_evaluate_info *info,
 
 			(*element_ptr)->common.reference_count =
 			    original_ref_count;
+
+			/*
+			 * The original_element holds a reference from the

package object

drivers/acpi/acpica/nsrepair2.c +1 -0
+			 * that represents _HID. Since a new element was

created by _HID,

drivers/acpi/acpica/nsrepair2.c +3 -1
+			 * remove the reference from the _CID package.
+			 */
+			acpi_ut_remove_reference(original_element);
 		}
 
 		element_ptr++;
--

2.29.2

Tested-by on v1 1/1
#2 lore raw
In reply to Erik Kaneda
Quoted 10 lines · Erik Kaneda

ACPICA commit 5fc4f4b87d6890d48d050ab279ed01f0132662ca

According to the ACPI spec, _CID returns a package containing hardware ID's. Each element of an ASL package contains a reference count from the parent package as well as the element itself.

Name (TEST, Package() {
"String object" // this package element has a reference count of 2
})

Quoted 8 lines

A memory leak was caused in the _CID repair function because it did not decrement the reference count created by the package. Fix the memory leak by calling acpi_ut_remove_reference on _CID package elements that represent a hardware ID (_HID).

Tested on Snapdragon laptops, and nothing seems broken.