All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFT PATCH] ACPICA: Fix memory leak caused by _CID repair function
@ 2021-04-28 22:52 Erik Kaneda
  2021-04-29 17:29 ` Kaneda, Erik
  2021-04-30 13:22 ` Shawn Guo
  0 siblings, 2 replies; 3+ messages in thread
From: Erik Kaneda @ 2021-04-28 22:52 UTC (permalink / raw)
  To: Rafael J . Wysocki, ACPI Devel Maling List, Shawn Guo, Gordon Ross
  Cc: Moore, Robert, 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
})

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

Link: https://github.com/acpica/acpica/commit/5fc4f4b8

Signed-off-by: Erik Kaneda <erik.kaneda@intel.com>
---
 drivers/acpi/acpica/nsrepair2.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/acpi/acpica/nsrepair2.c b/drivers/acpi/acpica/nsrepair2.c
index 14b71b41e845..38e10ab976e6 100644
--- a/drivers/acpi/acpica/nsrepair2.c
+++ b/drivers/acpi/acpica/nsrepair2.c
@@ -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++;
-- 
2.29.2


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

* RE: [RFT PATCH] ACPICA: Fix memory leak caused by _CID repair function
  2021-04-28 22:52 [RFT PATCH] ACPICA: Fix memory leak caused by _CID repair function Erik Kaneda
@ 2021-04-29 17:29 ` Kaneda, Erik
  2021-04-30 13:22 ` Shawn Guo
  1 sibling, 0 replies; 3+ messages in thread
From: Kaneda, Erik @ 2021-04-29 17:29 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Moore, Robert, Rafael J . Wysocki, ACPI Devel Maling List, Gordon Ross

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

> -----Original Message-----
> From: Kaneda, Erik <erik.kaneda@intel.com>
> Sent: Wednesday, April 28, 2021 3:53 PM
> To: Rafael J . Wysocki <rafael@kernel.org>; ACPI Devel Maling List <linux-
> acpi@vger.kernel.org>; Shawn Guo <shawn.guo@linaro.org>; Gordon Ross
> <gordon.w.ross@gmail.com>
> Cc: Moore; Moore, Robert <robert.moore@intel.com>; Kaneda, Erik
> <erik.kaneda@intel.com>
> 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).
> 
> Link: https://github.com/acpica/acpica/commit/5fc4f4b8
> 
> Signed-off-by: Erik Kaneda <erik.kaneda@intel.com>
> ---
>  drivers/acpi/acpica/nsrepair2.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/acpi/acpica/nsrepair2.c b/drivers/acpi/acpica/nsrepair2.c
> index 14b71b41e845..38e10ab976e6 100644
> --- a/drivers/acpi/acpica/nsrepair2.c
> +++ b/drivers/acpi/acpica/nsrepair2.c
> @@ -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++;
> --
> 2.29.2


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

* Re: [RFT PATCH] ACPICA: Fix memory leak caused by _CID repair function
  2021-04-28 22:52 [RFT PATCH] ACPICA: Fix memory leak caused by _CID repair function Erik Kaneda
  2021-04-29 17:29 ` Kaneda, Erik
@ 2021-04-30 13:22 ` Shawn Guo
  1 sibling, 0 replies; 3+ messages in thread
From: Shawn Guo @ 2021-04-30 13:22 UTC (permalink / raw)
  To: Erik Kaneda
  Cc: Rafael J . Wysocki, ACPI Devel Maling List, Gordon Ross, Moore, Robert

On Wed, Apr 28, 2021 at 03:52:47PM -0700, Erik Kaneda wrote:
> 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).
> 
> Link: https://github.com/acpica/acpica/commit/5fc4f4b8
> 
> Signed-off-by: Erik Kaneda <erik.kaneda@intel.com>

Tested on Snapdragon laptops, and nothing seems broken.

Tested-by: Shawn Guo <shawn.guo@linaro.org>

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

end of thread, other threads:[~2021-04-30 13:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 22:52 [RFT PATCH] ACPICA: Fix memory leak caused by _CID repair function Erik Kaneda
2021-04-29 17:29 ` Kaneda, Erik
2021-04-30 13:22 ` Shawn Guo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.