Commit 3ad8173b authored by Rob Clark's avatar Rob Clark Committed by Thomas Zimmermann

drm/shmem: Cleanup drm_gem_shmem_create_with_handle()

Once we create the handle, the handle owns the reference.  Currently
nothing was doing anything with the shmem ptr after the handle was
created, but let's change drm_gem_shmem_create_with_handle() to not
return the pointer, so-as to not encourage problematic use of this
function in the future.  As a bonus, it makes the code a bit cleaner.
Signed-off-by: default avatarRob Clark <robdclark@chromium.org>
Reviewed-by: default avatarSteven Price <steven.price@arm.com>
Signed-off-by: default avatarSteven Price <steven.price@arm.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230123154831.3191821-1-robdclark@gmail.com
(cherry picked from commit d023d6f7)
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
parent 76b1d904
...@@ -415,7 +415,7 @@ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem, ...@@ -415,7 +415,7 @@ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem,
} }
EXPORT_SYMBOL(drm_gem_shmem_vunmap); EXPORT_SYMBOL(drm_gem_shmem_vunmap);
static struct drm_gem_shmem_object * static int
drm_gem_shmem_create_with_handle(struct drm_file *file_priv, drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
struct drm_device *dev, size_t size, struct drm_device *dev, size_t size,
uint32_t *handle) uint32_t *handle)
...@@ -425,7 +425,7 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv, ...@@ -425,7 +425,7 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
shmem = drm_gem_shmem_create(dev, size); shmem = drm_gem_shmem_create(dev, size);
if (IS_ERR(shmem)) if (IS_ERR(shmem))
return shmem; return PTR_ERR(shmem);
/* /*
* Allocate an id of idr table where the obj is registered * Allocate an id of idr table where the obj is registered
...@@ -434,10 +434,8 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv, ...@@ -434,10 +434,8 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
ret = drm_gem_handle_create(file_priv, &shmem->base, handle); ret = drm_gem_handle_create(file_priv, &shmem->base, handle);
/* drop reference from allocate - handle holds it now. */ /* drop reference from allocate - handle holds it now. */
drm_gem_object_put(&shmem->base); drm_gem_object_put(&shmem->base);
if (ret)
return ERR_PTR(ret);
return shmem; return ret;
} }
/* Update madvise status, returns true if not purged, else /* Update madvise status, returns true if not purged, else
...@@ -520,7 +518,6 @@ int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev, ...@@ -520,7 +518,6 @@ int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
struct drm_mode_create_dumb *args) struct drm_mode_create_dumb *args)
{ {
u32 min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8); u32 min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
struct drm_gem_shmem_object *shmem;
if (!args->pitch || !args->size) { if (!args->pitch || !args->size) {
args->pitch = min_pitch; args->pitch = min_pitch;
...@@ -533,9 +530,7 @@ int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev, ...@@ -533,9 +530,7 @@ int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
args->size = PAGE_ALIGN(args->pitch * args->height); args->size = PAGE_ALIGN(args->pitch * args->height);
} }
shmem = drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle); return drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
return PTR_ERR_OR_ZERO(shmem);
} }
EXPORT_SYMBOL_GPL(drm_gem_shmem_dumb_create); EXPORT_SYMBOL_GPL(drm_gem_shmem_dumb_create);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment