Skip to contentSkip to conversation

drm/amd/display: use a more accurate check in dm_helpers_dp_read_dpcd()

PATCH Superseded Hamza Mahfooz 4 participants 5 messages Mar 9, 2023 – Mar 20, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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
index 8d598b322e5b..ed2ed7b1d869 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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 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 +0 -0
index 8d598b322e5b..ed2ed7b1d869 100644

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

#2 lore raw
In reply to Hamza Mahfooz
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 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 +0 -0
index 8d598b322e5b..ed2ed7b1d869 100644

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
#3 lore raw
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 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 +0 -0
index 8d598b322e5b..ed2ed7b1d869 100644
@@ -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
maintainer
#4 lore raw
Quoted 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 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 +0 -0
index 8d598b322e5b..ed2ed7b1d869 100644
@@ -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