From: TAKANO Mitsuhiro <[email protected]>

In drm_scdc_read_state(), buf is initialized to state->scdc before state
is checked for NULL. Evaluating state->scdc when state is NULL is
undefined behavior and allows the compiler to assume state is non-NULL.

Assign buf after verifying that state and connector are non-NULL.

Fixes: 6c5121962ec0 ("drm/scdc-helper: Add scdc_status debugfs entry")
Signed-off-by: TAKANO Mitsuhiro <[email protected]>
---
Verification: compile-tested on x86_64 with CONFIG_DRM_DISPLAY_HELPER=m
and CONFIG_DRM_DISPLAY_HDMI_HELPER=y (make W=1
drivers/gpu/drm/display/drm_scdc_helper.o; 0 warnings) and checked with
scripts/checkpatch.pl --strict. Checked against linux-next (next-20261127)
and lore.kernel.org for duplicates. Not runtime-tested on HDMI hardware.

The change and the changelog text were produced with an AI coding
assistant (Gemini) working from the tree; I reviewed the diff and the
reasoning, and I am responsible for the submission.
---
 drivers/gpu/drm/display/drm_scdc_helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/display/drm_scdc_helper.c 
b/drivers/gpu/drm/display/drm_scdc_helper.c
index 74388481f..9a0300092 100644
--- a/drivers/gpu/drm/display/drm_scdc_helper.c
+++ b/drivers/gpu/drm/display/drm_scdc_helper.c
@@ -428,13 +428,14 @@ int drm_scdc_read_state(struct drm_connector *connector, 
struct drm_scdc_state *
 {
        struct i2c_adapter *ddc;
        struct drm_scdc *scdc;
-       u8 *buf = state->scdc;
+       u8 *buf;
        int num_lanes;
        int ret;
 
        if (!state || !connector)
                return -ENODEV;
 
+       buf = state->scdc;
        scdc = &connector->display_info.hdmi.scdc;
        ddc = connector->ddc;
 

---
base-commit: f93eb7cfc4bfa5d46340f360873726e3e77f2365
change-id: 20261128-b4-drm-scdc-null-check-8017240e3b9d

Best regards,
--  
TAKANO Mitsuhiro <[email protected]>


Reply via email to