drm/amd/display: use a more accurate check in dm_helpers_dp_read_dpcd()
Subsystems (3)
PATCH 1/1 drm/amd/display: use a more accurate check in dm_helpers_dp_read_dpcd()
We should be checking if drm_dp_dpcd_read() returns the size that we are asking it to read instead of just checking if it is greater than zero. Also, we should WARN_ON() here since this condition is only ever met, if there is an issue worth investigating. So, compare the return value of drm_dp_dpcd_read() to size and WARN_ON() if they aren't equal.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +2 -2
@@ -511,8 +511,8 @@ bool dm_helpers_dp_read_dpcd(return false; } -return drm_dp_dpcd_read (&aconnector->dm_dp_aux.aux, address, - data, size) >0 ; +return !WARN_ON (drm_dp_dpcd_read (&aconnector->dm_dp_aux.aux, address, + data, size) != size); } bool dm_helpers_dp_write_dpcd(
Signature · 1 line
2.39.2
Quoted 16 lines · Hamza Mahfooz
We should be checking if
drm_dp_dpcd_read()returns the size that we are asking it to read instead of just checking if it is greater than zero. Also, we shouldWARN_ON()here since this condition is only ever met, if there is an issue worth investigating. So, compare the return value ofdrm_dp_dpcd_read()to size andWARN_ON()if they aren't equal.Signed-off-by Hamza Mahfooz <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +0
-0
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c bool dm_helpers_dp_read_dpcd( · line 518
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +2
-2@@ -511,8 +511,8 @@ bool dm_helpers_dp_read_dpcd(return false; } -return drm_dp_dpcd_read (&aconnector->dm_dp_aux.aux, address, - data, size) >0 ; +return !WARN_ON (drm_dp_dpcd_read (&aconnector->dm_dp_aux.aux, address, + data, size) != size); } bool dm_helpers_dp_write_dpcd(
and pushed to amd-staging-drm-next.
Thanks
Siqueira
Quoted 16 lines · Hamza Mahfooz
We should be checking if
drm_dp_dpcd_read()returns the size that we are asking it to read instead of just checking if it is greater than zero. Also, we shouldWARN_ON()here since this condition is only ever met, if there is an issue worth investigating. So, compare the return value ofdrm_dp_dpcd_read()to size andWARN_ON()if they aren't equal.Signed-off-by Hamza Mahfooz <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +0
-0
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c bool dm_helpers_dp_read_dpcd( · line 515
Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +2
-2@@ -511,8 +511,8 @@ bool dm_helpers_dp_read_dpcd(return false; } -return drm_dp_dpcd_read (&aconnector->dm_dp_aux.aux, address, - data, size) >0 ; +return !WARN_ON (drm_dp_dpcd_read (&aconnector->dm_dp_aux.aux, address, + data, size) != size);
Just FYI there are devices out there that violate the DP spec and reads from specific DPCD registers simply fail instead of returning the expected 0.
Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +0
-0} bool dm_helpers_dp_write_dpcd(Signature · 1 line
2.39.2
Signature · 2 lines
Ville Syrjälä Intel
Quoted 20 lines · Ville Syrjälä
Quoted 19 lines · Hamza Mahfooz
We should be checking if
drm_dp_dpcd_read()returns the size that we are asking it to read instead of just checking if it is greater than zero. Also, we shouldWARN_ON()here since this condition is only ever met, if there is an issue worth investigating. So, compare the return value ofdrm_dp_dpcd_read()to size andWARN_ON()if they aren't equal.Signed-off-by Hamza Mahfooz <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +0
-0@@ -511,8 +511,8 @@ bool dm_helpers_dp_read_dpcd(return false; }
Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c bool dm_helpers_dp_read_dpcd( · line 515
Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +2
-2-return drm_dp_dpcd_read (&aconnector->dm_dp_aux.aux, address, - data, size) >0 ; +return !WARN_ON (drm_dp_dpcd_read (&aconnector->dm_dp_aux.aux, address, + data, size) != size);Just FYI there are devices out there that violate the DP spec and reads from specific DPCD registers simply fail instead of returning the expected 0.
And of course anyone can yank the cable anytime, so in fact pretty much any DPCD read can fail.
Signature · 2 lines
Ville Syrjälä Intel
Harry Wentland
maintainerQuoted 30 lines · Ville Syrjälä
Quoted 20 lines · Ville Syrjälä
Quoted 19 lines · Hamza Mahfooz
We should be checking if
drm_dp_dpcd_read()returns the size that we are asking it to read instead of just checking if it is greater than zero. Also, we shouldWARN_ON()here since this condition is only ever met, if there is an issue worth investigating. So, compare the return value ofdrm_dp_dpcd_read()to size andWARN_ON()if they aren't equal.Signed-off-by Hamza Mahfooz <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +0
-0@@ -511,8 +511,8 @@ bool dm_helpers_dp_read_dpcd(return false; }Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c bool dm_helpers_dp_read_dpcd( · line 515
Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +2
-2-return drm_dp_dpcd_read (&aconnector->dm_dp_aux.aux, address, - data, size) >0 ; +return !WARN_ON (drm_dp_dpcd_read (&aconnector->dm_dp_aux.aux, address, + data, size) != size);Just FYI there are devices out there that violate the DP spec and reads from specific DPCD registers simply fail instead of returning the expected 0.
Quoted 3 lines
And of course anyone can yank the cable anytime, so in fact pretty much any DPCD read can fail.
Thanks for making this very important point. It seems like drm_dp_dpcd_access checks for that, though, and returns -EPROTO if !(ret == size). So I don't expect this patch to change any behavior.
Harry