* [PATCH v3] drm/shmem: Cleanup drm_gem_shmem_create_with_handle()
@ 2023-01-23 15:48 Rob Clark
2023-01-23 16:11 ` Steven Price
2023-02-01 10:35 ` Thomas Zimmermann
0 siblings, 2 replies; 3+ messages in thread
From: Rob Clark @ 2023-01-23 15:48 UTC (permalink / raw)
To: dri-devel
Cc: Steven Price, Rob Clark, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, open list
From: Rob Clark <robdclark@chromium.org>
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>
---
drivers/gpu/drm/drm_gem_shmem_helper.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index f21f47737817..42c496c5f92c 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -415,7 +415,7 @@ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem,
}
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,
struct drm_device *dev, size_t size,
uint32_t *handle)
@@ -425,7 +425,7 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
shmem = drm_gem_shmem_create(dev, size);
if (IS_ERR(shmem))
- return shmem;
+ return PTR_ERR(shmem);
/*
* 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,
ret = drm_gem_handle_create(file_priv, &shmem->base, handle);
/* drop reference from allocate - handle holds it now. */
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
@@ -520,7 +518,6 @@ int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
struct drm_mode_create_dumb *args)
{
u32 min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
- struct drm_gem_shmem_object *shmem;
if (!args->pitch || !args->size) {
args->pitch = min_pitch;
@@ -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);
}
- shmem = drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
-
- return PTR_ERR_OR_ZERO(shmem);
+ return drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
}
EXPORT_SYMBOL_GPL(drm_gem_shmem_dumb_create);
--
2.38.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] drm/shmem: Cleanup drm_gem_shmem_create_with_handle()
2023-01-23 15:48 [PATCH v3] drm/shmem: Cleanup drm_gem_shmem_create_with_handle() Rob Clark
@ 2023-01-23 16:11 ` Steven Price
2023-02-01 10:35 ` Thomas Zimmermann
1 sibling, 0 replies; 3+ messages in thread
From: Steven Price @ 2023-01-23 16:11 UTC (permalink / raw)
To: Rob Clark, dri-devel
Cc: Rob Clark, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Daniel Vetter, open list
On 23/01/2023 15:48, Rob Clark wrote:
> From: Rob Clark <robdclark@chromium.org>
>
> 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>
> ---
> drivers/gpu/drm/drm_gem_shmem_helper.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index f21f47737817..42c496c5f92c 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -415,7 +415,7 @@ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem,
> }
> 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,
> struct drm_device *dev, size_t size,
> uint32_t *handle)
> @@ -425,7 +425,7 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
>
> shmem = drm_gem_shmem_create(dev, size);
> if (IS_ERR(shmem))
> - return shmem;
> + return PTR_ERR(shmem);
>
> /*
> * 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,
> ret = drm_gem_handle_create(file_priv, &shmem->base, handle);
> /* drop reference from allocate - handle holds it now. */
> 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
> @@ -520,7 +518,6 @@ int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
> struct drm_mode_create_dumb *args)
> {
> u32 min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
> - struct drm_gem_shmem_object *shmem;
>
> if (!args->pitch || !args->size) {
> args->pitch = min_pitch;
> @@ -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);
> }
>
> - shmem = drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
> -
> - return PTR_ERR_OR_ZERO(shmem);
> + return drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
> }
> EXPORT_SYMBOL_GPL(drm_gem_shmem_dumb_create);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] drm/shmem: Cleanup drm_gem_shmem_create_with_handle()
2023-01-23 15:48 [PATCH v3] drm/shmem: Cleanup drm_gem_shmem_create_with_handle() Rob Clark
2023-01-23 16:11 ` Steven Price
@ 2023-02-01 10:35 ` Thomas Zimmermann
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Zimmermann @ 2023-02-01 10:35 UTC (permalink / raw)
To: Rob Clark, dri-devel; +Cc: Rob Clark, open list, Steven Price
[-- Attachment #1.1: Type: text/plain, Size: 2947 bytes --]
I have cherry-picked the patch into drm-misc-next-fixes.
Am 23.01.23 um 16:48 schrieb Rob Clark:
> From: Rob Clark <robdclark@chromium.org>
>
> 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>
> ---
> drivers/gpu/drm/drm_gem_shmem_helper.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index f21f47737817..42c496c5f92c 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -415,7 +415,7 @@ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem,
> }
> 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,
> struct drm_device *dev, size_t size,
> uint32_t *handle)
> @@ -425,7 +425,7 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
>
> shmem = drm_gem_shmem_create(dev, size);
> if (IS_ERR(shmem))
> - return shmem;
> + return PTR_ERR(shmem);
>
> /*
> * 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,
> ret = drm_gem_handle_create(file_priv, &shmem->base, handle);
> /* drop reference from allocate - handle holds it now. */
> 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
> @@ -520,7 +518,6 @@ int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
> struct drm_mode_create_dumb *args)
> {
> u32 min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
> - struct drm_gem_shmem_object *shmem;
>
> if (!args->pitch || !args->size) {
> args->pitch = min_pitch;
> @@ -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);
> }
>
> - shmem = drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
> -
> - return PTR_ERR_OR_ZERO(shmem);
> + return drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
> }
> EXPORT_SYMBOL_GPL(drm_gem_shmem_dumb_create);
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-01 10:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-23 15:48 [PATCH v3] drm/shmem: Cleanup drm_gem_shmem_create_with_handle() Rob Clark
2023-01-23 16:11 ` Steven Price
2023-02-01 10:35 ` Thomas Zimmermann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).