Skip to content

Commit 1b561d3

Browse files
sudeep-hollactmarinas
authored andcommitted
arm64: acpi: Fix possible memory leak of ffh_ctxt
Allocated 'ffh_ctxt' memory leak is possible if the SMCCC version and conduit checks fail and -EOPNOTSUPP is returned without freeing the allocated memory. Fix the same by moving the allocation after the SMCCC version and conduit checks. Fixes: 1d280ce ("arm64: Add architecture specific ACPI FFH Opregion callbacks") Cc: <[email protected]> # 6.2.x Cc: Will Deacon <[email protected]> Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Suggested-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/[email protected]/ Signed-off-by: Sudeep Holla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 060a2c9 commit 1b561d3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/arm64/kernel/acpi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,6 @@ int acpi_ffh_address_space_arch_setup(void *handler_ctxt, void **region_ctxt)
435435
enum arm_smccc_conduit conduit;
436436
struct acpi_ffh_data *ffh_ctxt;
437437

438-
ffh_ctxt = kzalloc(sizeof(*ffh_ctxt), GFP_KERNEL);
439-
if (!ffh_ctxt)
440-
return -ENOMEM;
441-
442438
if (arm_smccc_get_version() < ARM_SMCCC_VERSION_1_2)
443439
return -EOPNOTSUPP;
444440

@@ -448,6 +444,10 @@ int acpi_ffh_address_space_arch_setup(void *handler_ctxt, void **region_ctxt)
448444
return -EOPNOTSUPP;
449445
}
450446

447+
ffh_ctxt = kzalloc(sizeof(*ffh_ctxt), GFP_KERNEL);
448+
if (!ffh_ctxt)
449+
return -ENOMEM;
450+
451451
if (conduit == SMCCC_CONDUIT_SMC) {
452452
ffh_ctxt->invoke_ffh_fn = __arm_smccc_smc;
453453
ffh_ctxt->invoke_ffh64_fn = arm_smccc_1_2_smc;

0 commit comments

Comments
 (0)