Skip to contentSkip to conversation

drm/bridge: analogix-anx78xx: Fix drm_dp_link helper removal

PATCH In review Torsten Duwe 2 participants 2 messages Nov 30, 2019 – Dec 2, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bridge: analogix-anx78xx: Fix drm_dp_link helper removal

drm_dp_link_rate_to_bw_code and ...bw_code_to_link_rate simply divide by and multiply with 27000, respectively. Avoid an overflow in the u8 dpcd[0] and the multiply+divide alltogether.

Fixes ff1e8fb68ea06027 ("analogix-anx78xx: Avoid drm_dp_link helpers")

---
Has anybody actually tested ff1e8fb68ea06027 ? I copied that code in good faith for the anx6345 and changed a few other things simultaneously, and spent some time wondering why the panel stayed dark.

---

drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c +2 -3
index 41867be03751..864423f59d66 100644
@@ -722,10 +722,9 @@ static int anx78xx_dp_link_training(struct anx78xx *anx78xx)
 	if (err)
 		return err;
 
-	dpcd[0] = drm_dp_max_link_rate(anx78xx->dpcd);
-	dpcd[0] = drm_dp_link_rate_to_bw_code(dpcd[0]);
 	err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
-			   SP_DP_MAIN_LINK_BW_SET_REG, dpcd[0]);
+			   SP_DP_MAIN_LINK_BW_SET_REG,
+			   anx78xx->dpcd[DP_MAX_LINK_RATE]);
 	if (err)
 		return err;
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Torsten Duwe

drm_dp_link_rate_to_bw_code and ...bw_code_to_link_rate simply divide by and multiply with 27000, respectively. Avoid an overflow in the u8 dpcd[0] and the multiply+divide alltogether.

This was supposed to be a 1:1 conversion of what the helpers did, but then I tried to be clever and reuse variables rather than add an intermediate one and failed to realize that dpcd[0] was u8 and would therefore overflow with the multiplication.

Personally I think it's slightly nicer to go through the multiply/divide for consistency with how these helpers are used. MAX_LINK_RATE is a bit of an exception in that the field occupies the whole register, but most other registers need to have the fields extracted properly.

In this case it doesn't really matter, so the below is probably good enough.

Good catch!

Quoted 15 lines
Fixes ff1e8fb68ea06027 ("analogix-anx78xx: Avoid drm_dp_link helpers")

---
Has anybody actually tested ff1e8fb68ea06027 ? I copied that code in good faith for the anx6345 and changed a few other things simultaneously, and spent some time wondering why the panel stayed dark.

---

drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c +0 -0
index 41867be03751..864423f59d66 100644
@@ -722,10 +722,9 @@ static int anx78xx_dp_link_training(struct anx78xx *anx78xx)
 	if (err)
 		return err;

drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c static int anx78xx_dp_link_training(struct anx78xx *anx78xx) · line 730

Quoted 10 lines
drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c +2 -3
 
-	dpcd[0] = drm_dp_max_link_rate(anx78xx->dpcd);
-	dpcd[0] = drm_dp_link_rate_to_bw_code(dpcd[0]);
 	err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
-			   SP_DP_MAIN_LINK_BW_SET_REG, dpcd[0]);
+			   SP_DP_MAIN_LINK_BW_SET_REG,
+			   anx78xx->dpcd[DP_MAX_LINK_RATE]);
 	if (err)
 		return err;
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel