Skip to content

Commit

Permalink
drm/gem-shmem: When drm_gem_object_init failed, should release object
Browse files Browse the repository at this point in the history
when goto err_free, the object had init, so it should be release when fail.

Signed-off-by: ChunyouTang <tangchunyou@163.com>
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20221119064131.364-1-tangchunyou@163.com
  • Loading branch information
tangchunyou authored and Thomas Zimmermann committed Nov 21, 2022
1 parent e3ddd2d commit 7df34a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
19 changes: 16 additions & 3 deletions drivers/gpu/drm/drm_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ void drm_gem_private_object_init(struct drm_device *dev,
}
EXPORT_SYMBOL(drm_gem_private_object_init);

/**
* drm_gem_private_object_fini - Finalize a failed drm_gem_object
* @obj: drm_gem_object
*
* Uninitialize an already allocated GEM object when it initialized failed
*/
void drm_gem_private_object_fini(struct drm_gem_object *obj)
{
WARN_ON(obj->dma_buf);

dma_resv_fini(&obj->_resv);
}
EXPORT_SYMBOL(drm_gem_private_object_fini);

/**
* drm_gem_object_handle_free - release resources bound to userspace handles
* @obj: GEM object to clean up.
Expand Down Expand Up @@ -930,12 +944,11 @@ drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
void
drm_gem_object_release(struct drm_gem_object *obj)
{
WARN_ON(obj->dma_buf);

if (obj->filp)
fput(obj->filp);

dma_resv_fini(&obj->_resv);
drm_gem_private_object_fini(obj);

drm_gem_free_mmap_offset(obj);
drm_gem_lru_remove(obj);
}
Expand Down
4 changes: 3 additions & 1 deletion drivers/gpu/drm/drm_gem_shmem_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ __drm_gem_shmem_create(struct drm_device *dev, size_t size, bool private)
} else {
ret = drm_gem_object_init(dev, obj, size);
}
if (ret)
if (ret) {
drm_gem_private_object_fini(obj);
goto err_free;
}

ret = drm_gem_create_mmap_offset(obj);
if (ret)
Expand Down
1 change: 1 addition & 0 deletions include/drm/drm_gem.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ int drm_gem_object_init(struct drm_device *dev,
struct drm_gem_object *obj, size_t size);
void drm_gem_private_object_init(struct drm_device *dev,
struct drm_gem_object *obj, size_t size);
void drm_gem_private_object_fini(struct drm_gem_object *obj);
void drm_gem_vm_open(struct vm_area_struct *vma);
void drm_gem_vm_close(struct vm_area_struct *vma);
int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
Expand Down

0 comments on commit 7df34a6

Please sign in to comment.