Skip to contentSkip to conversation

drm/bridge: anx7625: Fix edid_read break case in sp_tx_edid_read()

PATCH Superseded Hsin-Yi Wang 3 participants 4 messages Nov 12, 2021 – Nov 18, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bridge: anx7625: Fix edid_read break case in sp_tx_edid_read()

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()")
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +1 -1
index 1a871f6b6822ee..392203b576042b 100644
@@ -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;
 
 				memcpy(&pedid_blocks_buf[offset],
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
Reviewed-by on v1 1/1
#1 lore raw

Hey Hsin-Yi,

Thanks for catching this.

checkpatch --strict is throwing an error for this patch. With that, feel free to add my r-b.

Quoted 28 lines · Hsin-Yi Wang

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()")
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +1 -2
index 1a871f6b6822ee..392203b576042b 100644
@@ -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;
 
                                memcpy(&pedid_blocks_buf[offset],
--

2.34.0.rc1.387.gb447b232ab-goog

#2 lore raw
In reply to Hsin-Yi Wang
Quoted 17 lines · Hsin-Yi Wang

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()")
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +0 -0
index 1a871f6b6822ee..392203b576042b 100644

drivers/gpu/drm/bridge/analogix/anx7625.c static int sp_tx_edid_read(struct anx7625_data *ctx, · line 830

Quoted 6 lines
drivers/gpu/drm/bridge/analogix/anx7625.c +1 -1
@@ -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

#3 lore raw
Quoted 32 lines · Guenter Roeck
Quoted 17 lines · Hsin-Yi Wang

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()")
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +0 -0
index 1a871f6b6822ee..392203b576042b 100644

drivers/gpu/drm/bridge/analogix/anx7625.c static int sp_tx_edid_read(struct anx7625_data *ctx, · line 830

Quoted 6 lines
drivers/gpu/drm/bridge/analogix/anx7625.c +1 -1
@@ -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.

Quoted 3 lines

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.

Before 7f16d0f3b8e2("drm/bridge: anx7625: Propagate errors from sp_tx_rst_aux()"), edid_read() only returns 0 (i2c read bytes > 0) or -EIO, so g_edid_break also couldn't be 1. After checking the code more, I guess what it wants to do is:

- For the 1st and 2nd block (case 0 and 1) in sp_tx_edid_read(), copy the buffer on success.
- For other blocks (case 2 and 3), process the buffer when the last g_edid_break updated in previous blocks is not 1. These blocks probably don't need to be updated if previous blocks have failed. The whole edid will be checked if valid.

I will update the patch.

Quoted 1 line

Guenter