drm/amd/display: fix a possible NULL dereference bug

Message ID 20240216062825.165627-1-harshit.m.mogalapalli@oracle.com
State New
Headers
Series drm/amd/display: fix a possible NULL dereference bug |

Commit Message

Harshit Mogalapalli Feb. 16, 2024, 6:28 a.m. UTC
  Smatch warns:
	drivers/gpu/drm/amd/amdgpu/../display/dc/dc_dmub_srv.c:136
	dc_dmub_srv_cmd_list_queue_execute() warn: variable dereferenced
	before check 'dc_dmub_srv' (see line 131)

Fix this by moving the dereference "dc_dmub_srv->ctx" after the NULL check.

Fixes: 028bac583449 ("drm/amd/display: decouple dmcub execution to reduce lock granularity")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202311141141.GoLAPxD5-lkp@intel.com/
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
Only compile tested
---
 drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c b/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c
index 0bc32537e2eb..a4bd46ec6da4 100644
--- a/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c
+++ b/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c
@@ -128,7 +128,7 @@  bool dc_dmub_srv_cmd_list_queue_execute(struct dc_dmub_srv *dc_dmub_srv,
 		unsigned int count,
 		union dmub_rb_cmd *cmd_list)
 {
-	struct dc_context *dc_ctx = dc_dmub_srv->ctx;
+	struct dc_context *dc_ctx;
 	struct dmub_srv *dmub;
 	enum dmub_status status;
 	int i;
@@ -136,6 +136,7 @@  bool dc_dmub_srv_cmd_list_queue_execute(struct dc_dmub_srv *dc_dmub_srv,
 	if (!dc_dmub_srv || !dc_dmub_srv->dmub)
 		return false;
 
+	dc_ctx = dc_dmub_srv->ctx;
 	dmub = dc_dmub_srv->dmub;
 
 	for (i = 0 ; i < count; i++) {