[Intel-gfx] [PATCH v2 6/9] drm/i915/gvt: Fix a memory leak in cmd_parser.c
Zhi Wang
zhi.a.wang at intel.com
Tue Sep 12 05:39:31 UTC 2017
The pointer points to the original memory can never take the return value
of krealloc().
Signed-off-by: Zhi Wang <zhi.a.wang at intel.com>
---
drivers/gpu/drm/i915/gvt/cmd_parser.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/i915/gvt/cmd_parser.c b/drivers/gpu/drm/i915/gvt/cmd_parser.c
index 2c0ccbb..22d33be 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;
}
--
2.7.4
More information about the Intel-gfx
mailing list