Re: [PATCH] drm/bridge: anx7625: Fix edid_read break case in sp_tx_edid_read()

From: Guenter Roeck
Date: Thu Nov 18 2021 - 11:52:08 EST


On Fri, Nov 12, 2021 at 07:24:33PM +0800, Hsin-Yi Wang wrote:
> edid_read() was assumed to return 0 on success. After
> 7f16d0f3b8e2("drm/bridge: anx7625: Propagate errors from sp_tx_rst_aux()"),
> the function can return >= 0 for successful case. Fix the g_edid_break
> condition in sp_tx_edid_read().
>
> Fixes: 7f16d0f3b8e2("drm/bridge: anx7625: Propagate errors from sp_tx_rst_aux()")
> Signed-off-by: Hsin-Yi Wang <hsinyi@xxxxxxxxxxxx>
> Reviewed-by: Robert Foss <robert.foss@xxxxxxxxxx>
> ---
> drivers/gpu/drm/bridge/analogix/anx7625.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index 1a871f6b6822ee..392203b576042b 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -826,7 +826,7 @@ static int sp_tx_edid_read(struct anx7625_data *ctx,
> g_edid_break = edid_read(ctx, offset,
> pblock_buf);
>
> - if (g_edid_break)
> + if (g_edid_break < 0)
> break;

g_edid_break is declared u8 and thus never < 0. The break; statement
doesn't indicate an error but that a break was encountered, and the
value of g_edid_break == 1 is used elsewhere in the function to indicate
that condition. It also doesn't break out of the outer loop, but only
out of the switch statement.

With this patch in place, g_edid_break will have a more or less random
value after an error, and the behavior of this function will be undefined.

Guenter