Skip to content

Commit 0563d17

Browse files
srishanmalexdeucher
authored andcommitted
drm/amd/display: Fix dereference-before-check for dc_link
The function dereferences amdgpu_dm_connector->dc_link early to initialize verified_link_cap and dc, but later still checks amdgpu_dm_connector->dc_link for NULL in the analog path. This late NULL check is redundant, introduce a local dc_link pointer, use it consistently, and drop the superfluous NULL check while using dc_link->link_id.id instead. The function uses dc_link at the very beginning without checking if it is NULL. But later in the code, it suddenly checks if dc_link is NULL. This check is too late to be useful, because the code has already used dc_link earlier. So this NULL check does nothing. We simplify the code by storing amdgpu_dm_connector->dc_link in a local dc_link variable and using it throughout the function. Since dc_link is already dereferenced early, the later NULL check is unnecessary and is removed. Fixes the below: amdgpu_dm_connector_get_modes(): variable dereferenced before check 'amdgpu_dm_connector->dc_link' drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c 8845 &amdgpu_dm_connector->dc_link->verified_link_cap; 8846 const struct dc *dc = amdgpu_dm_connector->dc_link->dc; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Dereference ... 8856 8857 if (amdgpu_dm_connector->dc_sink && 8858 amdgpu_dm_connector->dc_link && ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Checked too late. Presumably this NULL check could be removed? ... Fixes: d46e422 ("drm/amd/display: Cleanup uses of the analog flag") Reported by: Dan Carpenter <dan.carpenter@linaro.org> Cc: Timur Kristóf <timur.kristof@gmail.com> Cc: Aurabindo Pillai <aurabindo.pillai@amd.com> Cc: Roman Li <roman.li@amd.com> Cc: Harry Wentland <harry.wentland@amd.com> Cc: Tom Chung <chiahsuan.chung@amd.com> Cc: Alex Hung <alex.hung@amd.com> Cc: Ivan Lipski <ivan.lipski@amd.com> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com> Reviewed-by: Timur Kristóf <timur.kristof@gmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent f6eeab3 commit 0563d17

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8854,11 +8854,11 @@ static int amdgpu_dm_connector_get_modes(struct drm_connector *connector)
88548854
{
88558855
struct amdgpu_dm_connector *amdgpu_dm_connector =
88568856
to_amdgpu_dm_connector(connector);
8857+
struct dc_link *dc_link = amdgpu_dm_connector->dc_link;
88578858
struct drm_encoder *encoder;
88588859
const struct drm_edid *drm_edid = amdgpu_dm_connector->drm_edid;
8859-
struct dc_link_settings *verified_link_cap =
8860-
&amdgpu_dm_connector->dc_link->verified_link_cap;
8861-
const struct dc *dc = amdgpu_dm_connector->dc_link->dc;
8860+
struct dc_link_settings *verified_link_cap = &dc_link->verified_link_cap;
8861+
const struct dc *dc = dc_link->dc;
88628862

88638863
encoder = amdgpu_dm_connector_to_encoder(connector);
88648864

@@ -8870,9 +8870,8 @@ static int amdgpu_dm_connector_get_modes(struct drm_connector *connector)
88708870
drm_add_modes_noedid(connector, 1920, 1080);
88718871

88728872
if (amdgpu_dm_connector->dc_sink &&
8873-
amdgpu_dm_connector->dc_link &&
88748873
amdgpu_dm_connector->dc_sink->edid_caps.analog &&
8875-
dc_connector_supports_analog(amdgpu_dm_connector->dc_link->link_id.id)) {
8874+
dc_connector_supports_analog(dc_link->link_id.id)) {
88768875
/* Analog monitor connected by DAC load detection.
88778876
* Add common modes. It will be up to the user to select one that works.
88788877
*/

0 commit comments

Comments
 (0)