Skip to contentSkip to conversation

drm/amd/display: use proper context for logging

PATCH Superseded Jiri Slaby (SUSE) 3 participants 5 messages Jul 22

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/display: use proper context for logging

The same as the rest of the code, get_ss_info_from_atombios() uses calc_pll_cs->ctx->logger for logging. But calc_pll_cs->ctx is initialized only later in calc_pll_max_vco_construct(). Therefore, any output using DC_LOG_SYNC() leads to a NULL pointer deference in get_ss_info_from_atombios().

To avoid accessing the NULL context, use clk_src->base.ctx->logger in get_ss_info_from_atombios(). That context is initialized earlier in dce110_clk_src_construct() -- before get_ss_info_from_atombios() is actually called. This is done by temporarily redefining DC_LOGGER to CTX->logger.

Before:
dce110_clk_src_construct() did:
-> sets clk_src->base.ctx = ctx;
-> ss_info_from_atombios_create()
-> get_ss_info_from_atombios() <- uses calc_pll_cs->ctx # BOOM
-> calc_pll_max_vco_construct() <- sets calc_pll_cs->ctx

After:
dce110_clk_src_construct() does:
-> sets clk_src->base.ctx = ctx;
-> ss_info_from_atombios_create()
-> get_ss_info_from_atombios() <- uses clk_src->base.ctx

Fixes 1296423bf23c ("drm/amd/display: define DC_LOGGER for logger")
Cc Lakha, Bhawanpreet <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Leo Li <[email protected]>
Cc Rodrigo Siqueira <[email protected]>
Cc Alex Deucher <[email protected]>
Cc "Christian König" <[email protected]>
Cc David Airlie <[email protected]>
Cc Simona Vetter <[email protected]>

---
Cc: [email protected]

---
 drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c +7 -1
index ecb8493ec523..d3f7aa853e3a 100644
@@ -1513,6 +1513,10 @@ static const struct clock_source_funcs dce110_clk_src_funcs = {
 	.get_dp_dto_frequency_100hz = get_dp_dto_frequency_100hz
 };
 
+/* calc_pll_cs->ctx is set only after get_ss_info_from_atombios(), unlike clk_src->base */
+#pragma push_macro("DC_LOGGER")
+#undef DC_LOGGER
+#define DC_LOGGER CTX->logger
 
 static void get_ss_info_from_atombios(
 		struct dce110_clk_src *clk_src,
@@ -1526,7 +1530,7 @@ static void get_ss_info_from_atombios(
 	struct spread_spectrum_info *ss_info_cur;
 	struct spread_spectrum_data *ss_data_cur;
 	uint32_t i;
-	DC_LOGGER_INIT();
+
 	if (ss_entries_num == NULL) {
 		DC_LOG_SYNC(
 			"Invalid entry !!!\n");
@@ -1631,6 +1635,8 @@ static void get_ss_info_from_atombios(
 	kfree(ss_info);
 }
 
+#pragma pop_macro("DC_LOGGER")
+
 static void ss_info_from_atombios_create(
 	struct dce110_clk_src *clk_src)
 {
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] NULL pointer dereference when logging errors in dce112_get_pix_clk_dividers and dcn3_get_pix_clk_dividers. --

--- Patch [1]: [PATCH] drm/amd/display: use proper context for logging --- commit 67013b697b017867bb1c1e61f13b863b96364c5e
Author: Jiri Slaby (SUSE) <[email protected]>

drm/amd/display: use proper context for logging

This commit fixes a NULL pointer dereference in get_ss_info_from_atombios() by temporarily redefining DC_LOGGER to use clk_src->base.ctx->logger. The calc_pll_cs->ctx context is uninitialized at that time since it is only set later by calc_pll_max_vco_construct().

Fixes 1296423bf23c ("drm/amd/display: define DC_LOGGER for logger")

drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c static const struct clock_source_funcs dce110_clk_src_funcs = { · line 1519

Quoted 12 lines
drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c +4 -0
index ecb8493ec5233..d3f7aa853e3a6 100644
@@ -1513,6 +1513,10 @@ static const struct clock_source_funcs dce110_clk_src_funcs = {
 	.get_dp_dto_frequency_100hz = get_dp_dto_frequency_100hz
 };
 
+/* calc_pll_cs->ctx is set only after get_ss_info_from_atombios(), unlike clk_src->base */
+#pragma push_macro("DC_LOGGER")
+#undef DC_LOGGER
+#define DC_LOGGER CTX->logger

[Severity: High]
This is a pre-existing issue, but does a similar NULL pointer dereference exist in dce112_get_pix_clk_dividers() and dcn3_get_pix_clk_dividers() during their error paths?

It appears dce112_clk_src_construct() does not call calc_pll_max_vco_construct(), leaving calc_pll_cs->ctx as NULL. If invalid parameters are passed (like requested_pix_clk_100hz == 0), the error path invokes DC_LOG_ERROR() which dereferences calc_pll_cs->ctx->logger:

drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c:dce112_get_pix_clk_dividers() {
        DC_LOGGER_INIT();

        if (pix_clk_params == NULL || pll_settings == NULL
                        || pix_clk_params->requested_pix_clk_100hz == 0) {
                DC_LOG_ERROR(
                        "%s: Invalid parameters!!\n", __func__);
                return (uint32_t)-1;
        }
        ...
}

A similar error path exists in dcn3_get_pix_clk_dividers().

Since DC_LOG_ERROR() relies on the same uninitialized context pointer, could this trigger a crash similar to the one being fixed here if these functions encounter invalid parameters?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author
#2 lore raw
Quoted 56 lines · On 22. 07. 26, 8:51, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] NULL pointer dereference when logging errors in dce112_get_pix_clk_dividers and dcn3_get_pix_clk_dividers. --

--- Patch [1]: [PATCH] drm/amd/display: use proper context for logging --- commit 67013b697b017867bb1c1e61f13b863b96364c5e
Author: Jiri Slaby (SUSE) <[email protected]>

drm/amd/display: use proper context for logging

This commit fixes a NULL pointer dereference in get_ss_info_from_atombios() by temporarily redefining DC_LOGGER to use clk_src->base.ctx->logger. The calc_pll_cs->ctx context is uninitialized at that time since it is only set later by calc_pll_max_vco_construct().

Fixes 1296423bf23c ("drm/amd/display: define DC_LOGGER for logger")

drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c static const struct clock_source_funcs dce110_clk_src_funcs = { · line 1519

Quoted 12 lines
drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c +4 -0
index ecb8493ec5233..d3f7aa853e3a6 100644
@@ -1513,6 +1513,10 @@ static const struct clock_source_funcs dce110_clk_src_funcs = {
  	.get_dp_dto_frequency_100hz = get_dp_dto_frequency_100hz
  };
 
+/* calc_pll_cs->ctx is set only after get_ss_info_from_atombios(), unlike clk_src->base */
+#pragma push_macro("DC_LOGGER")
+#undef DC_LOGGER
+#define DC_LOGGER CTX->logger

[Severity: High]
This is a pre-existing issue, but does a similar NULL pointer dereference exist in dce112_get_pix_clk_dividers() and dcn3_get_pix_clk_dividers() during their error paths?

It appears dce112_clk_src_construct() does not call calc_pll_max_vco_construct(), leaving calc_pll_cs->ctx as NULL. If invalid parameters are passed (like requested_pix_clk_100hz == 0), the error path invokes DC_LOG_ERROR() which dereferences calc_pll_cs->ctx->logger:

drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c:dce112_get_pix_clk_dividers() {
         DC_LOGGER_INIT();

         if (pix_clk_params == NULL || pll_settings == NULL
                         || pix_clk_params->requested_pix_clk_100hz == 0) {
                 DC_LOG_ERROR(
                         "%s: Invalid parameters!!\n", __func__);
                 return (uint32_t)-1;
         }
         ...
}
Quoted 5 lines

A similar error path exists in dcn3_get_pix_clk_dividers().

Since DC_LOG_ERROR() relies on the same uninitialized context pointer, could this trigger a crash similar to the one being fixed here if these functions encounter invalid parameters?

Occurs likely to me. Someone involved in the driver has to look as the logic is really intertwined.

thanks,

Signature · 2 lines
js
suse labs
#3 lore raw
In reply to Jiri Slaby (SUSE)

AMD General

Why not just do

drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c +1 -1
@@ -45,7 +45,7 @@
        clk_src->base.ctx
 
 #define DC_LOGGER \
-       calc_pll_cs->ctx->logger
+       clk_src->base.ctx->logger or CTX->logger
 
 

clk_src is available everywhere right after dce110_clk_src_construct()

Bhawan

________________________________
From: Jiri Slaby (SUSE) <[email protected]>
Sent: July 22, 2026 2:32 AM
To: Deucher, Alexander <[email protected]>
Cc: [email protected] <[email protected]>; Jiri Slaby (SUSE) <[email protected]>; Lakha, Bhawanpreet <[email protected]>; Wentland, Harry <[email protected]>; Li, Sun peng (Leo) <[email protected]>; Rodrigo Siqueira <[email protected]>; Koenig, Christian <[email protected]>; David Airlie <[email protected]>; Simona Vetter <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH] drm/amd/display: use proper context for logging

The same as the rest of the code, get_ss_info_from_atombios() uses calc_pll_cs->ctx->logger for logging. But calc_pll_cs->ctx is initialized only later in calc_pll_max_vco_construct(). Therefore, any output using DC_LOG_SYNC() leads to a NULL pointer deference in get_ss_info_from_atombios().

To avoid accessing the NULL context, use clk_src->base.ctx->logger in get_ss_info_from_atombios(). That context is initialized earlier in dce110_clk_src_construct() -- before get_ss_info_from_atombios() is actually called. This is done by temporarily redefining DC_LOGGER to CTX->logger.

Before:
dce110_clk_src_construct() did:
-> sets clk_src->base.ctx = ctx;
-> ss_info_from_atombios_create()
-> get_ss_info_from_atombios() <- uses calc_pll_cs->ctx # BOOM
-> calc_pll_max_vco_construct() <- sets calc_pll_cs->ctx

After:
dce110_clk_src_construct() does:
-> sets clk_src->base.ctx = ctx;
-> ss_info_from_atombios_create()
-> get_ss_info_from_atombios() <- uses clk_src->base.ctx

Fixes 1296423bf23c ("drm/amd/display: define DC_LOGGER for logger")
Cc Lakha, Bhawanpreet <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Leo Li <[email protected]>
Cc Rodrigo Siqueira <[email protected]>
Cc Alex Deucher <[email protected]>
Cc "Christian König" <[email protected]>
Cc David Airlie <[email protected]>
Cc Simona Vetter <[email protected]>

---
Cc: [email protected]

---
 drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c +7 -1
index ecb8493ec523..d3f7aa853e3a 100644
@@ -1513,6 +1513,10 @@ static const struct clock_source_funcs dce110_clk_src_funcs = {
         .get_dp_dto_frequency_100hz = get_dp_dto_frequency_100hz
 };
 
+/* calc_pll_cs->ctx is set only after get_ss_info_from_atombios(), unlike clk_src->base */
+#pragma push_macro("DC_LOGGER")
+#undef DC_LOGGER
+#define DC_LOGGER CTX->logger
 
 static void get_ss_info_from_atombios(
                 struct dce110_clk_src *clk_src,
@@ -1526,7 +1530,7 @@ static void get_ss_info_from_atombios(
         struct spread_spectrum_info *ss_info_cur;
         struct spread_spectrum_data *ss_data_cur;
         uint32_t i;
-       DC_LOGGER_INIT();
+
         if (ss_entries_num == NULL) {
                 DC_LOG_SYNC(
                         "Invalid entry !!!\n");
@@ -1631,6 +1635,8 @@ static void get_ss_info_from_atombios(
         kfree(ss_info);
 }
 
+#pragma pop_macro("DC_LOGGER")
+
 static void ss_info_from_atombios_create(
         struct dce110_clk_src *clk_src)
 {

--
2.55.0

#4 lore raw

Hey, why not just do

drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c +0 -0
@@ -45,7 +45,7 @@

        clk_src->base.ctx

 #define DC_LOGGER \
-       calc_pll_cs->ctx->logger
+       clk_src->base.ctx->logger or CTX->logger

clk_src is available everywhere right after dce110_clk_src_construct()

Bhawan

________________________________________
From: Lakha, Bhawanpreet <[email protected]>
Sent: July 22, 2026 1:51 PM
To: Jiri Slaby (SUSE) <[email protected]>; Deucher, Alexander <[email protected]>
Cc: [email protected] <[email protected]>; Wentland, Harry <[email protected]>; Li, Sun peng (Leo) <[email protected]>; Rodrigo Siqueira <[email protected]>; Koenig, Christian <[email protected]>; David Airlie <[email protected]>; Simona Vetter <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] drm/amd/display: use proper context for logging

AMD General

Why not just do

drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c +0 -0
@@ -45,7 +45,7 @@

        clk_src->base.ctx

 #define DC_LOGGER \
-       calc_pll_cs->ctx->logger
+       clk_src->base.ctx->logger or CTX->logger

clk_src is available everywhere right after dce110_clk_src_construct()

Bhawan

________________________________________
From: Jiri Slaby (SUSE) <[email protected]>
Sent: July 22, 2026 2:32 AM
To: Deucher, Alexander <[email protected]>
Cc: [email protected] <[email protected]>; Jiri Slaby (SUSE) <[email protected]>; Lakha, Bhawanpreet <[email protected]>; Wentland, Harry <[email protected]>; Li, Sun peng (Leo) <[email protected]>; Rodrigo Siqueira <[email protected]>; Koenig, Christian <[email protected]>; David Airlie <[email protected]>; Simona Vetter <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH] drm/amd/display: use proper context for logging

The same as the rest of the code, get_ss_info_from_atombios() uses
calc_pll_cs->ctx->logger for logging. But calc_pll_cs->ctx is
initialized only later in calc_pll_max_vco_construct(). Therefore, any
output using DC_LOG_SYNC() leads to a NULL pointer deference in
get_ss_info_from_atombios().

To avoid accessing the NULL context, use clk_src->base.ctx->logger in get_ss_info_from_atombios(). That context is initialized earlier in dce110_clk_src_construct() -- before get_ss_info_from_atombios() is actually called. This is done by temporarily redefining DC_LOGGER to CTX->logger.

Before:
dce110_clk_src_construct() did:
 -> sets clk_src->base.ctx = ctx;
 -> ss_info_from_atombios_create()
   -> get_ss_info_from_atombios()   <- uses calc_pll_cs->ctx  # BOOM -> calc_pll_max_vco_construct()    <- sets calc_pll_cs->ctx

After:
dce110_clk_src_construct() does:
 -> sets clk_src->base.ctx = ctx;
 -> ss_info_from_atombios_create()
   -> get_ss_info_from_atombios()   <- uses clk_src->base.ctx

Fixes 1296423bf23c ("drm/amd/display: define DC_LOGGER for logger")
Cc Lakha, Bhawanpreet <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Leo Li <[email protected]>
Cc Rodrigo Siqueira <[email protected]>
Cc Alex Deucher <[email protected]>
Cc "Christian König" <[email protected]>
Cc David Airlie <[email protected]>
Cc Simona Vetter <[email protected]>

---
Cc: [email protected]
---
 drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c | 8 +++++++-

 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c +0 -0
index ecb8493ec523..d3f7aa853e3a 100644
@@ -1513,6 +1513,10 @@ static const struct clock_source_funcs dce110_clk_src_funcs = {

         .get_dp_dto_frequency_100hz = get_dp_dto_frequency_100hz
 };

+/* calc_pll_cs->ctx is set only after get_ss_info_from_atombios(), unlike clk_src->base */ +#pragma push_macro("DC_LOGGER")
+#undef DC_LOGGER
+#define DC_LOGGER CTX->logger

 static void get_ss_info_from_atombios(
                 struct dce110_clk_src *clk_src,
@@ -1526,7 +1530,7 @@ static void get_ss_info_from_atombios(
         struct spread_spectrum_info *ss_info_cur;
         struct spread_spectrum_data *ss_data_cur;
         uint32_t i;
-       DC_LOGGER_INIT();
+
         if (ss_entries_num == NULL) {
                 DC_LOG_SYNC(
                         "Invalid entry !!!\n");
@@ -1631,6 +1635,8 @@ static void get_ss_info_from_atombios(
         kfree(ss_info);
 }

+#pragma pop_macro("DC_LOGGER")
+
 static void ss_info_from_atombios_create(
         struct dce110_clk_src *clk_src)
 {
--
2.55.0