Skip to content

Commit bcfa48f

Browse files
julizhanalexdeucher
authored andcommitted
drm/amdgpu: avoid using null object of framebuffer
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. Reported-by: Fusheng Huang <[email protected]> Signed-off-by: Julia Zhang <[email protected]> Reviewed-by: Huang Rui <[email protected]> Signed-off-by: Alex Deucher <[email protected]> Cc: [email protected]
1 parent 2ec6c7f commit bcfa48f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <drm/drm_atomic_helper.h>
44
#include <drm/drm_edid.h>
55
#include <drm/drm_simple_kms_helper.h>
6+
#include <drm/drm_gem_framebuffer_helper.h>
67
#include <drm/drm_vblank.h>
78

89
#include "amdgpu.h"
@@ -314,7 +315,13 @@ static int amdgpu_vkms_prepare_fb(struct drm_plane *plane,
314315
return 0;
315316
}
316317
afb = to_amdgpu_framebuffer(new_state->fb);
317-
obj = new_state->fb->obj[0];
318+
319+
obj = drm_gem_fb_get_obj(new_state->fb, 0);
320+
if (!obj) {
321+
DRM_ERROR("Failed to get obj from framebuffer\n");
322+
return -EINVAL;
323+
}
324+
318325
rbo = gem_to_amdgpu_bo(obj);
319326
adev = amdgpu_ttm_adev(rbo->tbo.bdev);
320327

@@ -368,12 +375,19 @@ static void amdgpu_vkms_cleanup_fb(struct drm_plane *plane,
368375
struct drm_plane_state *old_state)
369376
{
370377
struct amdgpu_bo *rbo;
378+
struct drm_gem_object *obj;
371379
int r;
372380

373381
if (!old_state->fb)
374382
return;
375383

376-
rbo = gem_to_amdgpu_bo(old_state->fb->obj[0]);
384+
obj = drm_gem_fb_get_obj(old_state->fb, 0);
385+
if (!obj) {
386+
DRM_ERROR("Failed to get obj from framebuffer\n");
387+
return;
388+
}
389+
390+
rbo = gem_to_amdgpu_bo(obj);
377391
r = amdgpu_bo_reserve(rbo, false);
378392
if (unlikely(r)) {
379393
DRM_ERROR("failed to reserve rbo before unpin\n");

0 commit comments

Comments
 (0)