Skip to content

Commit

Permalink
habanalabs: Fix memory leak in error flow of context initialization
Browse files Browse the repository at this point in the history
Add a missing free of the cs_pending array in the error flow of context
initialization.

Fixes: c16d45f ("habanalabs: Use pending CS amount per ASIC")

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
  • Loading branch information
Tomer Tayar authored and Oded Gabbay committed Jul 24, 2020
1 parent 644883e commit 94f8be9
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions drivers/misc/habanalabs/common/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,36 +138,38 @@ int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx)
rc = hl_mmu_ctx_init(ctx);
if (rc) {
dev_err(hdev->dev, "Failed to init mmu ctx module\n");
goto mem_ctx_err;
goto err_free_cs_pending;
}
} else {
ctx->asid = hl_asid_alloc(hdev);
if (!ctx->asid) {
dev_err(hdev->dev, "No free ASID, failed to create context\n");
return -ENOMEM;
rc = -ENOMEM;
goto err_free_cs_pending;
}

rc = hl_vm_ctx_init(ctx);
if (rc) {
dev_err(hdev->dev, "Failed to init mem ctx module\n");
rc = -ENOMEM;
goto mem_ctx_err;
goto err_asid_free;
}

rc = hdev->asic_funcs->ctx_init(ctx);
if (rc) {
dev_err(hdev->dev, "ctx_init failed\n");
goto ctx_init_err;
goto err_vm_ctx_fini;
}
}

return 0;

ctx_init_err:
err_vm_ctx_fini:
hl_vm_ctx_fini(ctx);
mem_ctx_err:
if (ctx->asid != HL_KERNEL_ASID_ID)
hl_asid_free(hdev, ctx->asid);
err_asid_free:
hl_asid_free(hdev, ctx->asid);
err_free_cs_pending:
kfree(ctx->cs_pending);

return rc;
}
Expand Down

0 comments on commit 94f8be9

Please sign in to comment.