]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
drm/i915/gvt: Fix a memory leak in cmd_parser.c
authorZhi Wang <zhi.a.wang@intel.com>
Sun, 10 Sep 2017 13:36:21 +0000 (21:36 +0800)
committerZhenyu Wang <zhenyuw@linux.intel.com>
Thu, 16 Nov 2017 03:46:50 +0000 (11:46 +0800)
The pointer points to the original memory can never take the return value
of krealloc().

Signed-off-by: Zhi Wang <zhi.a.wang@intel.com>
drivers/gpu/drm/i915/gvt/cmd_parser.c

index 701a3c6f16696f9615ff52d7d81b2589d31bb99f..9405a214760c8301aa79f81b8df418f81ad60aeb 100644 (file)
@@ -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;
        }