Skip to content

Commit 3ad8173

Browse files
robclarktdz
authored andcommitted
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: Rob Clark <robdclark@chromium.org> Reviewed-by: Steven Price <steven.price@arm.com> Signed-off-by: Steven Price <steven.price@arm.com> Link: https://patchwork.freedesktop.org/patch/msgid/20230123154831.3191821-1-robdclark@gmail.com (cherry picked from commit d023d6f) Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
1 parent 76b1d90 commit 3ad8173

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

drivers/gpu/drm/drm_gem_shmem_helper.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem,
415415
}
416416
EXPORT_SYMBOL(drm_gem_shmem_vunmap);
417417

418-
static struct drm_gem_shmem_object *
418+
static int
419419
drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
420420
struct drm_device *dev, size_t size,
421421
uint32_t *handle)
@@ -425,7 +425,7 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
425425

426426
shmem = drm_gem_shmem_create(dev, size);
427427
if (IS_ERR(shmem))
428-
return shmem;
428+
return PTR_ERR(shmem);
429429

430430
/*
431431
* 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,
434434
ret = drm_gem_handle_create(file_priv, &shmem->base, handle);
435435
/* drop reference from allocate - handle holds it now. */
436436
drm_gem_object_put(&shmem->base);
437-
if (ret)
438-
return ERR_PTR(ret);
439437

440-
return shmem;
438+
return ret;
441439
}
442440

443441
/* 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,
520518
struct drm_mode_create_dumb *args)
521519
{
522520
u32 min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
523-
struct drm_gem_shmem_object *shmem;
524521

525522
if (!args->pitch || !args->size) {
526523
args->pitch = min_pitch;
@@ -533,9 +530,7 @@ int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
533530
args->size = PAGE_ALIGN(args->pitch * args->height);
534531
}
535532

536-
shmem = drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
537-
538-
return PTR_ERR_OR_ZERO(shmem);
533+
return drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
539534
}
540535
EXPORT_SYMBOL_GPL(drm_gem_shmem_dumb_create);
541536

0 commit comments

Comments
 (0)