mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH next] drm/amd/display: Fix possible NULL dereference in dc_dmub_srv_cmd_run_list()
@ 2023-04-26 19:24 Harshit Mogalapalli
  2023-04-26 20:59 ` Hamza Mahfooz
  0 siblings, 1 reply; 2+ messages in thread
From: Harshit Mogalapalli @ 2023-04-26 19:24 UTC (permalink / raw)
  Cc: error27, kernel-janitors, Harshit Mogalapalli, Harry Wentland,
	Leo Li, Rodrigo Siqueira, Alex Deucher, Christian König,
	Pan, Xinhui, David Airlie, Daniel Vetter, Alvin Lee, Jun Lei,
	Qingqing Zhuo, Josip Pavic, Max Tseng, Eric Yang,
	Nicholas Kazlauskas, amd-gfx, dri-devel, linux-kernel

We have a NULL check for 'dc_dmub_srv' in dc_dmub_srv_cmd_run_list()
but we are dereferencing it before checking.

Fix this moving the dereference next to NULL check.

This issue is found with Smatch(static analysis tool).

Fixes: e97cc04fe0fb ("drm/amd/display: refactor dmub commands into single function")
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(-)

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 d15ec32243e2..62d3473c32bc 100644
--- a/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c
+++ b/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c
@@ -125,7 +125,7 @@ bool dc_dmub_srv_cmd_run(struct dc_dmub_srv *dc_dmub_srv, union dmub_rb_cmd *cmd
 
 bool dc_dmub_srv_cmd_run_list(struct dc_dmub_srv *dc_dmub_srv, unsigned int count, union dmub_rb_cmd *cmd_list, enum dm_dmub_wait_type wait_type)
 {
-	struct dc_context *dc_ctx = dc_dmub_srv->ctx;
+	struct dc_context *dc_ctx;
 	struct dmub_srv *dmub;
 	enum dmub_status status;
 	int i;
@@ -133,6 +133,7 @@ bool dc_dmub_srv_cmd_run_list(struct dc_dmub_srv *dc_dmub_srv, unsigned int coun
 	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++) {
-- 
2.38.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH next] drm/amd/display: Fix possible NULL dereference in dc_dmub_srv_cmd_run_list()
  2023-04-26 19:24 [PATCH next] drm/amd/display: Fix possible NULL dereference in dc_dmub_srv_cmd_run_list() Harshit Mogalapalli
@ 2023-04-26 20:59 ` Hamza Mahfooz
  0 siblings, 0 replies; 2+ messages in thread
From: Hamza Mahfooz @ 2023-04-26 20:59 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: dri-devel, Josip Pavic, amd-gfx, error27, Leo Li,
	kernel-janitors, Qingqing Zhuo, Pan, Xinhui, Rodrigo Siqueira,
	linux-kernel, Nicholas Kazlauskas, Max Tseng, Alvin Lee,
	Alex Deucher, Daniel Vetter, David Airlie, Jun Lei,
	Harry Wentland, Christian König, Eric Yang

On 4/26/23 15:24, Harshit Mogalapalli wrote:
> We have a NULL check for 'dc_dmub_srv' in dc_dmub_srv_cmd_run_list()
> but we are dereferencing it before checking.
> 
> Fix this moving the dereference next to NULL check.
> 
> This issue is found with Smatch(static analysis tool).
> 
> Fixes: e97cc04fe0fb ("drm/amd/display: refactor dmub commands into single function")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>

Applied, thanks!

> ---
> Only compile tested.
> ---
>   drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> 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 d15ec32243e2..62d3473c32bc 100644
> --- a/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c
> +++ b/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c
> @@ -125,7 +125,7 @@ bool dc_dmub_srv_cmd_run(struct dc_dmub_srv *dc_dmub_srv, union dmub_rb_cmd *cmd
>   
>   bool dc_dmub_srv_cmd_run_list(struct dc_dmub_srv *dc_dmub_srv, unsigned int count, union dmub_rb_cmd *cmd_list, enum dm_dmub_wait_type wait_type)
>   {
> -	struct dc_context *dc_ctx = dc_dmub_srv->ctx;
> +	struct dc_context *dc_ctx;
>   	struct dmub_srv *dmub;
>   	enum dmub_status status;
>   	int i;
> @@ -133,6 +133,7 @@ bool dc_dmub_srv_cmd_run_list(struct dc_dmub_srv *dc_dmub_srv, unsigned int coun
>   	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++) {
-- 
Hamza


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-26 20:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-26 19:24 [PATCH next] drm/amd/display: Fix possible NULL dereference in dc_dmub_srv_cmd_run_list() Harshit Mogalapalli
2023-04-26 20:59 ` Hamza Mahfooz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®