* [PATCH v2] drm/amdgpu: avoid using null object of framebuffer @ 2024-06-19 4:29 Julia Zhang 2024-06-19 4:46 ` Huang Rui 0 siblings, 1 reply; 4+ messages in thread From: Julia Zhang @ 2024-06-19 4:29 UTC (permalink / raw) To: Alex Deucher, Christian König, amd-gfx Cc: Chen Jiqian, Huang Rui, Zhu Lingshan, Julia Zhang, Julia Zhang 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. v2: Call drm_gem_fb_get_obj after check old_state->fb for NULL. Signed-off-by: Julia Zhang <Julia.Zhang@amd.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 18 ++++++++++++++++-- 1 file changed, 16 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..212f6522859d 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,19 @@ 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; int r; if (!old_state->fb) return; - rbo = gem_to_amdgpu_bo(old_state->fb->obj[0]); + obj = drm_gem_fb_get_obj(old_state->fb, 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 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/amdgpu: avoid using null object of framebuffer 2024-06-19 4:29 [PATCH v2] drm/amdgpu: avoid using null object of framebuffer Julia Zhang @ 2024-06-19 4:46 ` Huang Rui 2024-06-19 4:53 ` Huang Rui 0 siblings, 1 reply; 4+ messages in thread From: Huang Rui @ 2024-06-19 4:46 UTC (permalink / raw) To: Zhang, Julia Cc: Deucher, Alexander, Koenig, Christian, amd-gfx@lists.freedesktop.org, Chen, Jiqian, Zhu, Lingshan On Wed, Jun 19, 2024 at 12:29:24PM +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. > > v2: Call drm_gem_fb_get_obj after check old_state->fb for NULL. > > Signed-off-by: Julia Zhang <Julia.Zhang@amd.com> > --- Julia, you can add my RB during V1 in the next submission. Reviewed-by: Huang Rui <ray.huang@amd.com> > drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 18 ++++++++++++++++-- > 1 file changed, 16 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..212f6522859d 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,19 @@ 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; > int r; > > if (!old_state->fb) > return; > > - rbo = gem_to_amdgpu_bo(old_state->fb->obj[0]); > + obj = drm_gem_fb_get_obj(old_state->fb, 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 > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/amdgpu: avoid using null object of framebuffer 2024-06-19 4:46 ` Huang Rui @ 2024-06-19 4:53 ` Huang Rui 2024-06-19 5:00 ` Zhang, Julia 0 siblings, 1 reply; 4+ messages in thread From: Huang Rui @ 2024-06-19 4:53 UTC (permalink / raw) To: Zhang, Julia Cc: Deucher, Alexander, Koenig, Christian, amd-gfx@lists.freedesktop.org, Chen, Jiqian, Zhu, Lingshan, Fusheng Huang On Wed, Jun 19, 2024 at 12:46:25PM +0800, Huang Rui wrote: > On Wed, Jun 19, 2024 at 12:29:24PM +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. > > > > v2: Call drm_gem_fb_get_obj after check old_state->fb for NULL. > > > > Signed-off-by: Julia Zhang <Julia.Zhang@amd.com> > > --- > > Julia, you can add my RB during V1 in the next submission. > > Reviewed-by: Huang Rui <ray.huang@amd.com> CC Fusheng who reported the issue. Fusheng, may we have your reported-by? > > > drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 18 ++++++++++++++++-- > > 1 file changed, 16 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..212f6522859d 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,19 @@ 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; > > int r; > > > > if (!old_state->fb) > > return; > > > > - rbo = gem_to_amdgpu_bo(old_state->fb->obj[0]); > > + obj = drm_gem_fb_get_obj(old_state->fb, 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 > > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/amdgpu: avoid using null object of framebuffer 2024-06-19 4:53 ` Huang Rui @ 2024-06-19 5:00 ` Zhang, Julia 0 siblings, 0 replies; 4+ messages in thread From: Zhang, Julia @ 2024-06-19 5:00 UTC (permalink / raw) To: Huang, Ray, Zhang, Julia Cc: Deucher, Alexander, Koenig, Christian, amd-gfx@lists.freedesktop.org, Chen, Jiqian, Zhu, Lingshan, 黄富生 [-- Attachment #1: Type: text/plain, Size: 2661 bytes --] On 2024/6/19 12:53, Huang Rui wrote: On Wed, Jun 19, 2024 at 12:46:25PM +0800, Huang Rui wrote: On Wed, Jun 19, 2024 at 12:29:24PM +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. v2: Call drm_gem_fb_get_obj after check old_state->fb for NULL. Signed-off-by: Julia Zhang <Julia.Zhang@amd.com><mailto:Julia.Zhang@amd.com> --- Julia, you can add my RB during V1 in the next submission. Reviewed-by: Huang Rui <ray.huang@amd.com><mailto:ray.huang@amd.com> CC Fusheng who reported the issue. Fusheng, may we have your reported-by? Hi Fusheng, Can you help to review this patch and may we have you reported-by? Thank you. Julia drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 18 ++++++++++++++++-- 1 file changed, 16 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..212f6522859d 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,19 @@ 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; int r; if (!old_state->fb) return; - rbo = gem_to_amdgpu_bo(old_state->fb->obj[0]); + obj = drm_gem_fb_get_obj(old_state->fb, 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 [-- Attachment #2: Type: text/html, Size: 7615 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-19 5:00 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-06-19 4:29 [PATCH v2] drm/amdgpu: avoid using null object of framebuffer Julia Zhang 2024-06-19 4:46 ` Huang Rui 2024-06-19 4:53 ` Huang Rui 2024-06-19 5:00 ` Zhang, Julia
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.