dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Thomas Zimmermann <tzimmermann@suse.de>
Cc: jiayang5@huawei.com, airlied@linux.ie,
	butterflyhuangxx@gmail.com, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 2/3] drm/vram-helper: Integrate drm_gem_vram_init() into drm_gem_vram_create()
Date: Thu, 16 Jul 2020 22:04:28 +0200	[thread overview]
Message-ID: <20200716200428.GA2254583@ravnborg.org> (raw)
In-Reply-To: <20200714083238.28479-3-tzimmermann@suse.de>

Hi Thomas.

On Tue, Jul 14, 2020 at 10:32:37AM +0200, Thomas Zimmermann wrote:
> The drm_gem_vram_create() function is the only caller of the internal
> helepr drm_gem_vram_init(). Streamline the code by putting all code into
helper
> the create function.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
> ---
>  drivers/gpu/drm/drm_gem_vram_helper.c | 75 ++++++++++-----------------
>  1 file changed, 28 insertions(+), 47 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
> index 8dfb7458a34b..af767d3da5da 100644
> --- a/drivers/gpu/drm/drm_gem_vram_helper.c
> +++ b/drivers/gpu/drm/drm_gem_vram_helper.c
> @@ -175,51 +175,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
>  	}
>  }
>  
> -/*
> - * Note that on error, drm_gem_vram_init will free the buffer object.
> - */
> -
> -static int drm_gem_vram_init(struct drm_device *dev,
> -			     struct drm_gem_vram_object *gbo,
> -			     size_t size, unsigned long pg_align)
> -{
> -	struct drm_vram_mm *vmm = dev->vram_mm;
> -	struct ttm_bo_device *bdev;
> -	int ret;
> -	size_t acc_size;
> -
> -	if (WARN_ONCE(!vmm, "VRAM MM not initialized")) {
> -		kfree(gbo);
> -		return -EINVAL;
> -	}
> -	bdev = &vmm->bdev;
> -
> -	gbo->bo.base.funcs = &drm_gem_vram_object_funcs;
> -
> -	ret = drm_gem_object_init(dev, &gbo->bo.base, size);
> -	if (ret) {
> -		kfree(gbo);
> -		return ret;
> -	}
> -
> -	acc_size = ttm_bo_dma_acc_size(bdev, size, sizeof(*gbo));
> -
> -	gbo->bo.bdev = bdev;
> -	drm_gem_vram_placement(gbo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM);
> -
> -	ret = ttm_bo_init(bdev, &gbo->bo, size, ttm_bo_type_device,
> -			  &gbo->placement, pg_align, false, acc_size,
> -			  NULL, NULL, ttm_buffer_object_destroy);
> -	if (ret)
> -		/*
> -		 * A failing ttm_bo_init will call ttm_buffer_object_destroy
> -		 * to release gbo->bo.base and kfree gbo.
> -		 */
> -		return ret;
> -
> -	return 0;
> -}
> -
>  /**
>   * drm_gem_vram_create() - Creates a VRAM-backed GEM object
>   * @dev:		the DRM device
> @@ -235,7 +190,13 @@ struct drm_gem_vram_object *drm_gem_vram_create(struct drm_device *dev,
>  						unsigned long pg_align)
>  {
>  	struct drm_gem_vram_object *gbo;
> +	struct drm_vram_mm *vmm = dev->vram_mm;
> +	struct ttm_bo_device *bdev;
>  	int ret;
> +	size_t acc_size;
> +
> +	if (WARN_ONCE(!vmm, "VRAM MM not initialized"))
> +		return ERR_PTR(-EINVAL);
>  
>  	if (dev->driver->gem_create_object) {
>  		struct drm_gem_object *gem =
> @@ -249,8 +210,28 @@ struct drm_gem_vram_object *drm_gem_vram_create(struct drm_device *dev,
>  			return ERR_PTR(-ENOMEM);
>  	}
>  
> -	ret = drm_gem_vram_init(dev, gbo, size, pg_align);
> -	if (ret < 0)
> +	gbo->bo.base.funcs = &drm_gem_vram_object_funcs;
> +
> +	ret = drm_gem_object_init(dev, &gbo->bo.base, size);
> +	if (ret) {
> +		kfree(gbo);
> +		return ERR_PTR(ret);
> +	}
> +
> +	bdev = &vmm->bdev;
> +	acc_size = ttm_bo_dma_acc_size(bdev, size, sizeof(*gbo));
> +
> +	gbo->bo.bdev = bdev;
> +	drm_gem_vram_placement(gbo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM);
> +
> +	/*
> +	 * A failing ttm_bo_init will call ttm_buffer_object_destroy
> +	 * to release gbo->bo.base and kfree gbo.
> +	 */
> +	ret = ttm_bo_init(bdev, &gbo->bo, size, ttm_bo_type_device,
> +			  &gbo->placement, pg_align, false, acc_size,
> +			  NULL, NULL, ttm_buffer_object_destroy);
> +	if (ret)
>  		return ERR_PTR(ret);
>  
>  	return gbo;
> -- 
> 2.27.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-07-16 20:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14  8:32 [PATCH 0/3] drm/vram-helper: Update GEM VRAM object creation Thomas Zimmermann
2020-07-14  8:32 ` [PATCH 1/3] drm: fix double free for gbo in drm_gem_vram_init and drm_gem_vram_create Thomas Zimmermann
2020-07-14  8:32 ` [PATCH 2/3] drm/vram-helper: Integrate drm_gem_vram_init() into drm_gem_vram_create() Thomas Zimmermann
2020-07-16 20:04   ` Sam Ravnborg [this message]
2020-07-14  8:32 ` [PATCH 3/3] drm/vram-helper: Set object function iff they are not provided by driver Thomas Zimmermann
2020-07-16 20:11   ` Sam Ravnborg
2020-07-17  6:26     ` Thomas Zimmermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200716200428.GA2254583@ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=airlied@linux.ie \
    --cc=butterflyhuangxx@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jiayang5@huawei.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).