2020-01-09 09:04:50

by Tobias Schramm

[permalink] [raw]
Subject: [PATCH 0/1] Regression in analogix_anx78xx

commit ff1e8fb68ea0 ("drm/bridge: analogix-anx78xx: Avoid drm_dp_link helpers")
stores the max link rate in a u8, overflowing it.
This will probably prevent the link training from working properly.

I've not tested this patch beyond a simple compile test since I do not own
any devices containing an anx78xx. So please test!

Tobias

Tobias Schramm (1):
drm/bridge: anx78xx: fix integer type used for storing dp link rate

drivers/gpu/drm/bridge/analogix-anx78xx.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

--
2.24.1


2020-01-09 10:11:30

by Tobias Schramm

[permalink] [raw]
Subject: [PATCH 1/1] drm/bridge: anx78xx: fix integer type used for storing dp link rate

commit ff1e8fb68ea0 ("drm/bridge: analogix-anx78xx: Avoid drm_dp_link helpers")
changed the link training logic to remove use of drm_dp_link helpers. However
the new logic stores the maximum link rate in a u8, overflowing it.
This commit changes the logic to store the max link rate in a unsigned int
instead.

Signed-off-by: Tobias Schramm <[email protected]>
---
drivers/gpu/drm/bridge/analogix-anx78xx.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix-anx78xx.c b/drivers/gpu/drm/bridge/analogix-anx78xx.c
index 274989f96a91..0f38b8c40dff 100644
--- a/drivers/gpu/drm/bridge/analogix-anx78xx.c
+++ b/drivers/gpu/drm/bridge/analogix-anx78xx.c
@@ -748,6 +748,7 @@ static int anx78xx_init_pdata(struct anx78xx *anx78xx)
static int anx78xx_dp_link_training(struct anx78xx *anx78xx)
{
u8 dp_bw, dpcd[2];
+ unsigned int max_link_rate;
int err;

err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_HDMI_MUTE_CTRL_REG,
@@ -866,8 +867,8 @@ 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]);
+ max_link_rate = drm_dp_max_link_rate(anx78xx->dpcd);
+ dpcd[0] = drm_dp_link_rate_to_bw_code(max_link_rate);
err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
SP_DP_MAIN_LINK_BW_SET_REG, dpcd[0]);
if (err)
--
2.24.1

2020-01-17 10:04:16

by Andrzej Hajda

[permalink] [raw]
Subject: Re: [PATCH 1/1] drm/bridge: anx78xx: fix integer type used for storing dp link rate

On 09.01.2020 09:48, Tobias Schramm wrote:
> commit ff1e8fb68ea0 ("drm/bridge: analogix-anx78xx: Avoid drm_dp_link helpers")
> changed the link training logic to remove use of drm_dp_link helpers. However
> the new logic stores the maximum link rate in a u8, overflowing it.
> This commit changes the logic to store the max link rate in a unsigned int
> instead.
>
> Signed-off-by: Tobias Schramm <[email protected]>
> ---
> drivers/gpu/drm/bridge/analogix-anx78xx.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/analogix-anx78xx.c b/drivers/gpu/drm/bridge/analogix-anx78xx.c
> index 274989f96a91..0f38b8c40dff 100644
> --- a/drivers/gpu/drm/bridge/analogix-anx78xx.c
> +++ b/drivers/gpu/drm/bridge/analogix-anx78xx.c
> @@ -748,6 +748,7 @@ static int anx78xx_init_pdata(struct anx78xx *anx78xx)
> static int anx78xx_dp_link_training(struct anx78xx *anx78xx)
> {
> u8 dp_bw, dpcd[2];
> + unsigned int max_link_rate;
> int err;
>
> err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_HDMI_MUTE_CTRL_REG,
> @@ -866,8 +867,8 @@ 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]);
> + max_link_rate = drm_dp_max_link_rate(anx78xx->dpcd);
> + dpcd[0] = drm_dp_link_rate_to_bw_code(max_link_rate);


The code converts bw_code to rate, then reverse, maybe it should be
simplified:

dpcd[0] = anx78xx->dpcd[DP_MAX_LINK_RATE];


Regards

Andrzej


> err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
> SP_DP_MAIN_LINK_BW_SET_REG, dpcd[0]);
> if (err)