* [PATCH] habanalabs: Fix memory leak in error flow of context init
@ 2020-07-23 6:17 Tomer Tayar
2020-07-23 14:21 ` Oded Gabbay
0 siblings, 1 reply; 2+ messages in thread
From: Tomer Tayar @ 2020-07-23 6:17 UTC (permalink / raw)
To: oded.gabbay; +Cc: linux-kernel, SW_Drivers
Add a missing free of the cs_pending array in the error flow of context
init.
Fixes: 4b49c5b118b9 ("habanalabs: Use pending cs amount per asic")
Signed-off-by: Tomer Tayar <ttayar@habana.ai>
---
drivers/misc/habanalabs/common/context.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/misc/habanalabs/common/context.c b/drivers/misc/habanalabs/common/context.c
index b75a20364fad..3e375958e73b 100644
--- a/drivers/misc/habanalabs/common/context.c
+++ b/drivers/misc/habanalabs/common/context.c
@@ -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;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] habanalabs: Fix memory leak in error flow of context init
2020-07-23 6:17 [PATCH] habanalabs: Fix memory leak in error flow of context init Tomer Tayar
@ 2020-07-23 14:21 ` Oded Gabbay
0 siblings, 0 replies; 2+ messages in thread
From: Oded Gabbay @ 2020-07-23 14:21 UTC (permalink / raw)
To: Tomer Tayar; +Cc: Linux-Kernel@Vger. Kernel. Org, SW_Drivers
On Thu, Jul 23, 2020 at 9:18 AM Tomer Tayar <ttayar@habana.ai> wrote:
>
> Add a missing free of the cs_pending array in the error flow of context
> init.
>
> Fixes: 4b49c5b118b9 ("habanalabs: Use pending cs amount per asic")
>
> Signed-off-by: Tomer Tayar <ttayar@habana.ai>
> ---
> drivers/misc/habanalabs/common/context.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/misc/habanalabs/common/context.c b/drivers/misc/habanalabs/common/context.c
> index b75a20364fad..3e375958e73b 100644
> --- a/drivers/misc/habanalabs/common/context.c
> +++ b/drivers/misc/habanalabs/common/context.c
> @@ -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;
> }
> --
> 2.17.1
>
This patch is:
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-23 14:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 6:17 [PATCH] habanalabs: Fix memory leak in error flow of context init Tomer Tayar
2020-07-23 14:21 ` Oded Gabbay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).