Skip to content

Commit

Permalink
drm/virtio: Fix memory leak in virtio_gpu_object_create()
Browse files Browse the repository at this point in the history
The virtio_gpu_object_shmem_init() will alloc memory and save it in
@ents, so when virtio_gpu_array_alloc() fails, this memory should be
freed, this patch fixes it.

Fixes: e7fef09 ("drm/virtio: Simplify error handling of virtio_gpu_object_create()")
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221109091905.55451-1-xiujianfeng@huawei.com
  • Loading branch information
Xiu Jianfeng authored and digetx committed Jan 2, 2023
1 parent 3b754ed commit a764da4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/gpu/drm/virtio/virtgpu_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
struct virtio_gpu_object_array *objs = NULL;
struct drm_gem_shmem_object *shmem_obj;
struct virtio_gpu_object *bo;
struct virtio_gpu_mem_entry *ents;
struct virtio_gpu_mem_entry *ents = NULL;
unsigned int nents;
int ret;

Expand All @@ -210,7 +210,7 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
ret = -ENOMEM;
objs = virtio_gpu_array_alloc(1);
if (!objs)
goto err_put_id;
goto err_free_entry;
virtio_gpu_array_add_obj(objs, &bo->base.base);

ret = virtio_gpu_array_lock_resv(objs);
Expand Down Expand Up @@ -239,6 +239,8 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,

err_put_objs:
virtio_gpu_array_put_free(objs);
err_free_entry:
kvfree(ents);
err_put_id:
virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle);
err_free_gem:
Expand Down

0 comments on commit a764da4

Please sign in to comment.