Skip to contentSkip to conversation

drm/amd/display: Add null check before access structs

PATCH In review Ma Ke 3 participants 4 messages Jun 26, 2024

Subsystems (3)
lore
Share & tools
lore

Ma Ke

author
#0 lore raw

PATCH 1/1 drm/amd/display: Add null check before access structs

In enable_phantom_plane, we should better check null pointer before accessing various structs.

Fixes 09a4ec5da92c ("drm/amd/display: Refactor dc_state interface")
---
 drivers/gpu/drm/amd/display/dc/dml2/dml2_mall_phantom.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/display/dc/dml2/dml2_mall_phantom.c +2 -0
index 282d70e2b18a..3d29169dd6bb 100644
@@ -750,6 +750,8 @@ static void enable_phantom_plane(struct dml2_context *ctx,
 					ctx->config.svp_pstate.callbacks.dc,
 					state,
 					curr_pipe->plane_state);
+			if (!phantom_plane)
+				return;
 		}
 
 		memcpy(&phantom_plane->address, &curr_pipe->plane_state->address, sizeof(phantom_plane->address));
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines

In enable_phantom_plane, we should better check null pointer before accessing various structs.

1. Can a wording approach (like the following) be a better change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.10-rc5#n45

A null pointer is stored in the local variable “phantom_plane” after a call of the function “create_phantom_plane” (as a data structure menber) failed. This pointer was used in subsequent statements where an undesirable dereference will be performed then.
Thus add a corresponding return value check.

2. How do you think about to use a summary phrase like “Prevent null pointer dereference in enable_phantom_plane()”?

Regards,
Markus

#2 lore raw
In reply to Ma Ke

Thanks for the fix, I'll apply this.

Quoted 22 lines · Ma Ke

In enable_phantom_plane, we should better check null pointer before accessing various structs.

Fixes 09a4ec5da92c ("drm/amd/display: Refactor dc_state interface")
---
  drivers/gpu/drm/amd/display/dc/dml2/dml2_mall_phantom.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/display/dc/dml2/dml2_mall_phantom.c +2 -0
index 282d70e2b18a..3d29169dd6bb 100644
@@ -750,6 +750,8 @@ static void enable_phantom_plane(struct dml2_context *ctx,
  					ctx->config.svp_pstate.callbacks.dc,
  					state,
  					curr_pipe->plane_state);
+			if (!phantom_plane)
+				return;
  		}
 
  		memcpy(&phantom_plane->address, &curr_pipe->plane_state->address, sizeof(phantom_plane->address));
Signature · 4 lines
--

Thanks & Regards,
Aurabindo Pillai