Skip to contentSkip to conversation

ACPI: PCC: Fix memory leak in address space setup

PATCH In review Rafael Mendonca 2 participants 3 messages Sep 9, 2022 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: PCC: Fix memory leak in address space setup

The allocated memory for the pcc_data struct doesn't get freed under an error path in pcc_mbox_request_channel() or acpi_os_ioremap().

Fixes 77e2a04745ff8 ("ACPI: PCC: Implement OperationRegion handler for the PCC Type 3 subtype")
---
 drivers/acpi/acpi_pcc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/acpi_pcc.c +2 -0
index a12b55d81209..fe5ab0fdc3bf 100644
@@ -63,6 +63,7 @@ acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,
 	if (IS_ERR(data->pcc_chan)) {
 		pr_err("Failed to find PCC channel for subspace %d\n",
 		       ctx->subspace_id);
+		kfree(data);
 		return AE_NOT_FOUND;
 	}
 
@@ -72,6 +73,7 @@ acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,
 	if (!data->pcc_comm_addr) {
 		pr_err("Failed to ioremap PCC comm region mem for %d\n",
 		       ctx->subspace_id);
+		kfree(data);
 		return AE_NO_MEMORY;
 	}
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 22 lines · Rafael Mendonca

The allocated memory for the pcc_data struct doesn't get freed under an error path in pcc_mbox_request_channel() or acpi_os_ioremap().

Fixes 77e2a04745ff8 ("ACPI: PCC: Implement OperationRegion handler for the PCC Type 3 subtype")
---
 drivers/acpi/acpi_pcc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/acpi_pcc.c +1 -0
index a12b55d81209..fe5ab0fdc3bf 100644
@@ -63,6 +63,7 @@ acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,
 	if (IS_ERR(data->pcc_chan)) {
 		pr_err("Failed to find PCC channel for subspace %d\n",
 		       ctx->subspace_id);
+		kfree(data);
 		return AE_NOT_FOUND;
 	}
 

drivers/acpi/acpi_pcc.c acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function, · line 75

Quoted 3 lines
drivers/acpi/acpi_pcc.c +0 -0
@@ -72,6 +73,7 @@ acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,
 	if (!data->pcc_comm_addr) {
 		pr_err("Failed to ioremap PCC comm region mem for %d\n",
 		       ctx->subspace_id);

I was wondering if pcc_mbox_free_channel() should be called here as well in case of acpi_os_ioremap() failure.

Quoted 7 lines
drivers/acpi/acpi_pcc.c +1 -0
+		kfree(data);
 		return AE_NO_MEMORY;
 	}
 
Signature · 1 line
2.34.1
#2 lore raw
Quoted 22 lines · Rafael Mendonca
Quoted 21 lines · Rafael Mendonca

The allocated memory for the pcc_data struct doesn't get freed under an error path in pcc_mbox_request_channel() or acpi_os_ioremap().

Fixes 77e2a04745ff8 ("ACPI: PCC: Implement OperationRegion handler for the PCC Type 3 subtype")
---
 drivers/acpi/acpi_pcc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/acpi_pcc.c +1 -0
index a12b55d81209..fe5ab0fdc3bf 100644
@@ -63,6 +63,7 @@ acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,
 	if (IS_ERR(data->pcc_chan)) {
 		pr_err("Failed to find PCC channel for subspace %d\n",
 		       ctx->subspace_id);
+		kfree(data);
 		return AE_NOT_FOUND;
 	}
 
Quoted 8 lines

drivers/acpi/acpi_pcc.c acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function, · line 75

Quoted 4 lines
drivers/acpi/acpi_pcc.c +0 -0
@@ -72,6 +73,7 @@ acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,
 	if (!data->pcc_comm_addr) {
 		pr_err("Failed to ioremap PCC comm region mem for %d\n",
 		       ctx->subspace_id);

I was wondering if pcc_mbox_free_channel() should be called here as well in case of acpi_os_ioremap() failure.

Yes please. There are not modules and shouldn't matter much but it is good to have it for correctness.

Thanks for finding and fixing this. Also please add the fixes tag in next version.

Fixes 77e2a04745ff ("ACPI: PCC: Implement OperationRegion handler for the PCC Type 3 subtype")
Signature · 2 lines
Regards,
Sudeep