Skip to content

Commit 94a2d37

Browse files
MrVanjforissier
authored andcommitted
core: tee_mmu: avoid resource leak
If calloc fails, need to free the asid bit in g_asid. Signed-off-by: Peng Fan <[email protected]> Reviewed-by: Jens Wiklander <[email protected]>
1 parent 717935d commit 94a2d37

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

core/arch/arm/mm/tee_mmu.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ static TEE_Result tee_mmu_umap_set_vas(struct tee_mmu_info *mmu)
214214
TEE_Result tee_mmu_init(struct user_ta_ctx *utc)
215215
{
216216
uint32_t asid = 1;
217+
bool asid_allocated = false;
217218

218219
if (!utc->context) {
219220
utc->context = 1;
@@ -229,11 +230,15 @@ TEE_Result tee_mmu_init(struct user_ta_ctx *utc)
229230
return TEE_ERROR_GENERIC;
230231
}
231232
g_asid &= ~asid;
233+
asid_allocated = true;
232234
}
233235

234236
utc->mmu = calloc(1, sizeof(struct tee_mmu_info));
235-
if (!utc->mmu)
237+
if (!utc->mmu) {
238+
if (asid_allocated)
239+
g_asid |= asid;
236240
return TEE_ERROR_OUT_OF_MEMORY;
241+
}
237242
core_mmu_get_user_va_range(&utc->mmu->ta_private_vmem_start, NULL);
238243
return TEE_SUCCESS;
239244
}

0 commit comments

Comments
 (0)