AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Huang Rui <ray.huang@amd.com>
To: "Zhang, Julia" <Julia.Zhang@amd.com>
Cc: "Deucher, Alexander" <Alexander.Deucher@amd.com>,
	"Koenig, Christian" <Christian.Koenig@amd.com>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
	"Chen, Jiqian" <Jiqian.Chen@amd.com>
Subject: Re: [PATCH] drm/amdgpu: avoid using null object of framebuffer
Date: Tue, 18 Jun 2024 10:44:24 +0800	[thread overview]
Message-ID: <ZnD0iC42srxzIV3t@amd.com> (raw)
In-Reply-To: <20240607070455.125522-1-julia.zhang@amd.com>

On Fri, Jun 07, 2024 at 03:04:55PM +0800, Zhang, Julia wrote:
> Instead of using state->fb->obj[0] directly, get object from framebuffer
> by calling drm_gem_fb_get_obj() and return error code when object is
> null to avoid using null object of framebuffer.
> 
> Signed-off-by: Julia Zhang <Julia.Zhang@amd.com>

Reviewed-by: Huang Rui <ray.huang@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> index d60c4a2eeb0c..d50ee0828935 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
> @@ -2,6 +2,7 @@
>  
>  #include <drm/drm_atomic_helper.h>
>  #include <drm/drm_simple_kms_helper.h>
> +#include <drm/drm_gem_framebuffer_helper.h>
>  #include <drm/drm_vblank.h>
>  
>  #include "amdgpu.h"
> @@ -311,7 +312,13 @@ static int amdgpu_vkms_prepare_fb(struct drm_plane *plane,
>  		return 0;
>  	}
>  	afb = to_amdgpu_framebuffer(new_state->fb);
> -	obj = new_state->fb->obj[0];
> +
> +	obj = drm_gem_fb_get_obj(new_state->fb, 0);
> +	if (!obj) {
> +		DRM_ERROR("Failed to get obj from framebuffer\n");
> +		return -EINVAL;
> +	}
> +
>  	rbo = gem_to_amdgpu_bo(obj);
>  	adev = amdgpu_ttm_adev(rbo->tbo.bdev);
>  
> @@ -365,12 +372,18 @@ static void amdgpu_vkms_cleanup_fb(struct drm_plane *plane,
>  				   struct drm_plane_state *old_state)
>  {
>  	struct amdgpu_bo *rbo;
> +	struct drm_gem_object *obj = drm_gem_fb_get_obj(old_state->fb, 0);
>  	int r;
>  
>  	if (!old_state->fb)
>  		return;
>  
> -	rbo = gem_to_amdgpu_bo(old_state->fb->obj[0]);
> +	if (!obj) {
> +		DRM_ERROR("Failed to get obj from framebuffer\n");
> +		return;
> +	}
> +
> +	rbo = gem_to_amdgpu_bo(obj);
>  	r = amdgpu_bo_reserve(rbo, false);
>  	if (unlikely(r)) {
>  		DRM_ERROR("failed to reserve rbo before unpin\n");
> -- 
> 2.34.1
> 

      reply	other threads:[~2024-06-18  2:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-07  7:04 [PATCH] drm/amdgpu: avoid using null object of framebuffer Julia Zhang
2024-06-18  2:44 ` Huang Rui [this message]

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=ZnD0iC42srxzIV3t@amd.com \
    --to=ray.huang@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Jiqian.Chen@amd.com \
    --cc=Julia.Zhang@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    /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