From: Zhi Wang Date: Sun, 10 Sep 2017 13:36:21 +0000 (+0800) Subject: drm/i915/gvt: Fix a memory leak in cmd_parser.c X-Git-Tag: Ubuntu-5.2.0-15.16~5065^2~31^2~12^2~43 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=bf4097ea5762bd90d836df9904594eb4822fefa7;p=mirror_ubuntu-eoan-kernel.git drm/i915/gvt: Fix a memory leak in cmd_parser.c The pointer points to the original memory can never take the return value of krealloc(). Signed-off-by: Zhi Wang --- diff --git a/drivers/gpu/drm/i915/gvt/cmd_parser.c b/drivers/gpu/drm/i915/gvt/cmd_parser.c index 701a3c6f1669..9405a214760c 100644 --- a/drivers/gpu/drm/i915/gvt/cmd_parser.c +++ b/drivers/gpu/drm/i915/gvt/cmd_parser.c @@ -2620,14 +2620,16 @@ static int shadow_workload_ring_buffer(struct intel_vgpu_workload *workload) gma_top = workload->rb_start + guest_rb_size; if (workload->rb_len > vgpu->reserve_ring_buffer_size[ring_id]) { - void *va = vgpu->reserve_ring_buffer_va[ring_id]; + void *va, *p; + /* realloc the new ring buffer if needed */ - vgpu->reserve_ring_buffer_va[ring_id] = - krealloc(va, workload->rb_len, GFP_KERNEL); - if (!vgpu->reserve_ring_buffer_va[ring_id]) { + va = vgpu->reserve_ring_buffer_va[ring_id]; + p = krealloc(va, workload->rb_len, GFP_KERNEL); + if (!p) { gvt_vgpu_err("fail to alloc reserve ring buffer\n"); return -ENOMEM; } + vgpu->reserve_ring_buffer_va[ring_id] = p; vgpu->reserve_ring_buffer_size[ring_id] = workload->rb_len; }