]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
platform/x86/amd: hfi: Fix pcct_tbl leak in amd_hfi_metadata_parser()
authorZhen Ni <zhen.ni@easystack.cn>
Fri, 22 Aug 2025 08:33:29 +0000 (16:33 +0800)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 25 Aug 2025 11:07:02 +0000 (14:07 +0300)
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>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
Link: https://lore.kernel.org/r/20250822083329.710857-1-zhen.ni@easystack.cn
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/amd/hfi/hfi.c

index 4f56149b37742892f5e1d0347b29892270c4b121..a465ac6f607eacf11e4517f4ea3a904d16c8fdb0 100644 (file)
@@ -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;