diff mbox

drm/i915/gvt: fix memory leak of a cmd_entry struct on error exit path

Message ID 20180410123312.24631-1-colin.king@canonical.com (mailing list archive)
State New, archived
Headers show

Commit Message

Colin King April 10, 2018, 12:33 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The error exit path when a duplicate is found does not kfree and cmd_entry
struct and hence there is a small memory leak.  Fix this by kfree'ing it.

Detected by CoverityScan, CID#1370198 ("Resource Leak")

Fixes: be1da7070aea ("drm/i915/gvt: vGPU command scanner")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/i915/gvt/cmd_parser.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Chris Wilson April 10, 2018, 1:16 p.m. UTC | #1
Quoting Colin King (2018-04-10 13:33:12)
> From: Colin Ian King <colin.king@canonical.com>
> 
> The error exit path when a duplicate is found does not kfree and cmd_entry
> struct and hence there is a small memory leak.  Fix this by kfree'ing it.
> 
> Detected by CoverityScan, CID#1370198 ("Resource Leak")
> 
> Fixes: be1da7070aea ("drm/i915/gvt: vGPU command scanner")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/gpu/drm/i915/gvt/cmd_parser.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/cmd_parser.c b/drivers/gpu/drm/i915/gvt/cmd_parser.c
> index d85939bd7b47..3b6d26c44e37 100644
> --- a/drivers/gpu/drm/i915/gvt/cmd_parser.c
> +++ b/drivers/gpu/drm/i915/gvt/cmd_parser.c
> @@ -2864,6 +2864,7 @@ static int init_cmd_table(struct intel_gvt *gvt)
>                 if (info) {
>                         gvt_err("%s %s duplicated\n", e->info->name,
>                                         info->name);
> +                       kfree(e);

e kzalloc'ed moments above, not yet added to any lists, so fine to use
kfree.

Alternatively, the find_cmd_entry_any_ring() could be moved ahead of the
kzalloc as this function must be externally serialised.

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/gvt/cmd_parser.c b/drivers/gpu/drm/i915/gvt/cmd_parser.c
index d85939bd7b47..3b6d26c44e37 100644
--- a/drivers/gpu/drm/i915/gvt/cmd_parser.c
+++ b/drivers/gpu/drm/i915/gvt/cmd_parser.c
@@ -2864,6 +2864,7 @@  static int init_cmd_table(struct intel_gvt *gvt)
 		if (info) {
 			gvt_err("%s %s duplicated\n", e->info->name,
 					info->name);
+			kfree(e);
 			return -EEXIST;
 		}