This commit adds a null check for the 'afb' variable in the
amdgpu_dm_update_cursor function. Previously, 'afb' was assumed to be
null at line 8388, but was used later in the code without a null check.
This could potentially lead to a null pointer dereference.

Changes since v1:
- Moved the null check for 'afb' to the line where 'afb' is used. (Alex)

Fixes the below:
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:8433 
amdgpu_dm_update_cursor()
        error: we previously assumed 'afb' could be null (see line 8388)

Cc: Tom Chung <chiahsuan.ch...@amd.com>
Cc: Rodrigo Siqueira <rodrigo.sique...@amd.com>
Cc: Roman Li <roman...@amd.com>
Cc: Alex Hung <alex.h...@amd.com>
Cc: Aurabindo Pillai <aurabindo.pil...@amd.com>
Cc: Harry Wentland <harry.wentl...@amd.com>
Co-developed-by: Alex Hung <alex.h...@amd.com>
Signed-off-by: Alex Hung <alex.h...@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmu...@amd.com>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 293f93d1976c..0fe043df643d 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -8697,7 +8697,8 @@ static void amdgpu_dm_update_cursor(struct drm_plane 
*plane,
            adev->dm.dc->caps.color.dpp.gamma_corr)
                attributes.attribute_flags.bits.ENABLE_CURSOR_DEGAMMA = 1;
 
-       attributes.pitch = afb->base.pitches[0] / afb->base.format->cpp[0];
+       if (afb)
+               attributes.pitch = afb->base.pitches[0] / 
afb->base.format->cpp[0];
 
        if (crtc_state->stream) {
                if (!dc_stream_set_cursor_attributes(crtc_state->stream,
-- 
2.34.1

Reply via email to