stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] platform/x86/amd: hfi: Fix pcct_tbl leak in amd_hfi_metadata_parser()
@ 2025-08-22  8:33 Zhen Ni
  2025-08-22 18:22 ` Mario Limonciello
  2025-08-25 11:30 ` Ilpo Järvinen
  0 siblings, 2 replies; 3+ messages in thread
From: Zhen Ni @ 2025-08-22  8:33 UTC (permalink / raw)
  To: mario.limonciello, perry.yuan, hansg, ilpo.jarvinen
  Cc: platform-driver-x86, Zhen Ni, stable

Fix a permanent ACPI table memory leak when amd_hfi_metadata_parser()
fails due to invalid PCCT table length or memory allocation errors.

Fixes: d4e95ea7a78e ("platform/x86: hfi: Parse CPU core ranking data from shared memory")
Cc: stable@vger.kernel.org
Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
---
 drivers/platform/x86/amd/hfi/hfi.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index 4f56149b3774..a465ac6f607e 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -385,12 +385,16 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
 	amd_hfi_data->pcct_entry = pcct_entry;
 	pcct_ext = (struct acpi_pcct_ext_pcc_slave *)pcct_entry;
 
-	if (pcct_ext->length <= 0)
-		return -EINVAL;
+	if (pcct_ext->length <= 0) {
+		ret = -EINVAL;
+		goto out;
+	}
 
 	amd_hfi_data->shmem = devm_kzalloc(amd_hfi_data->dev, pcct_ext->length, GFP_KERNEL);
-	if (!amd_hfi_data->shmem)
-		return -ENOMEM;
+	if (!amd_hfi_data->shmem) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	pcc_chan->shmem_base_addr = pcct_ext->base_address;
 	pcc_chan->shmem_size = pcct_ext->length;
@@ -398,6 +402,8 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
 	/* parse the shared memory info from the PCCT table */
 	ret = amd_hfi_fill_metadata(amd_hfi_data);
 
+out:
+	/* Don't leak any ACPI memory */
 	acpi_put_table(pcct_tbl);
 
 	return ret;
-- 
2.20.1


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

* Re: [PATCH] platform/x86/amd: hfi: Fix pcct_tbl leak in amd_hfi_metadata_parser()
  2025-08-22  8:33 [PATCH] platform/x86/amd: hfi: Fix pcct_tbl leak in amd_hfi_metadata_parser() Zhen Ni
@ 2025-08-22 18:22 ` Mario Limonciello
  2025-08-25 11:30 ` Ilpo Järvinen
  1 sibling, 0 replies; 3+ messages in thread
From: Mario Limonciello @ 2025-08-22 18:22 UTC (permalink / raw)
  To: Zhen Ni, perry.yuan, hansg, ilpo.jarvinen; +Cc: platform-driver-x86, stable

On 8/22/2025 3:33 AM, Zhen Ni wrote:
> Fix a permanent ACPI table memory leak when amd_hfi_metadata_parser()
> fails due to invalid PCCT table length or memory allocation errors.
> 
> Fixes: d4e95ea7a78e ("platform/x86: hfi: Parse CPU core ranking data from shared memory")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>

Great catch, thanks.

Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>

> ---
>   drivers/platform/x86/amd/hfi/hfi.c | 14 ++++++++++----
>   1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
> index 4f56149b3774..a465ac6f607e 100644
> --- a/drivers/platform/x86/amd/hfi/hfi.c
> +++ b/drivers/platform/x86/amd/hfi/hfi.c
> @@ -385,12 +385,16 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
>   	amd_hfi_data->pcct_entry = pcct_entry;
>   	pcct_ext = (struct acpi_pcct_ext_pcc_slave *)pcct_entry;
>   
> -	if (pcct_ext->length <= 0)
> -		return -EINVAL;
> +	if (pcct_ext->length <= 0) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
>   
>   	amd_hfi_data->shmem = devm_kzalloc(amd_hfi_data->dev, pcct_ext->length, GFP_KERNEL);
> -	if (!amd_hfi_data->shmem)
> -		return -ENOMEM;
> +	if (!amd_hfi_data->shmem) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
>   
>   	pcc_chan->shmem_base_addr = pcct_ext->base_address;
>   	pcc_chan->shmem_size = pcct_ext->length;
> @@ -398,6 +402,8 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
>   	/* parse the shared memory info from the PCCT table */
>   	ret = amd_hfi_fill_metadata(amd_hfi_data);
>   
> +out:
> +	/* Don't leak any ACPI memory */
>   	acpi_put_table(pcct_tbl);
>   
>   	return ret;


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

* Re: [PATCH] platform/x86/amd: hfi: Fix pcct_tbl leak in amd_hfi_metadata_parser()
  2025-08-22  8:33 [PATCH] platform/x86/amd: hfi: Fix pcct_tbl leak in amd_hfi_metadata_parser() Zhen Ni
  2025-08-22 18:22 ` Mario Limonciello
@ 2025-08-25 11:30 ` Ilpo Järvinen
  1 sibling, 0 replies; 3+ messages in thread
From: Ilpo Järvinen @ 2025-08-25 11:30 UTC (permalink / raw)
  To: mario.limonciello, perry.yuan, hansg, Zhen Ni; +Cc: platform-driver-x86, stable

On Fri, 22 Aug 2025 16:33:29 +0800, Zhen Ni wrote:

> Fix a permanent ACPI table memory leak when amd_hfi_metadata_parser()
> fails due to invalid PCCT table length or memory allocation errors.
> 
> 


Thank you for your contribution, it has been applied to my local
review-ilpo-fixes branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-fixes branch only once I've pushed my
local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86/amd: hfi: Fix pcct_tbl leak in amd_hfi_metadata_parser()
      commit: d3a8ca2ebe6e3f2b1fb0e8e74f909d109a1d77c7

--
 i.


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

end of thread, other threads:[~2025-08-25 11:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-22  8:33 [PATCH] platform/x86/amd: hfi: Fix pcct_tbl leak in amd_hfi_metadata_parser() Zhen Ni
2025-08-22 18:22 ` Mario Limonciello
2025-08-25 11:30 ` Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).