Skip to contentSkip to conversation

drm/sun4i: hdmi: Fix sun4i_tmds_determine_rate

PATCH Superseded Jonathan Liu 2 participants 2 messages Dec 21, 2017

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/sun4i: hdmi: Fix sun4i_tmds_determine_rate

There are several issues in sun4i_tmds_determine_rate:
- doesn't check if the best match was already set before comparing it with the enumerated parameters which could result in integer divide by zero
- doesn't consider rate halving when determining closest match if it can't match the requested rate exactly
- sets best_div to i which corresponds to rate halving when it should be set to j which corresponds to the divider

Fix these issues.

Fixes 9c5681011a0c ("drm/sun4i: Add HDMI support")
---
 drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c +6 -3
index dc332ea56f6c..3ecffa52c814 100644
@@ -102,10 +102,13 @@ static int sun4i_tmds_determine_rate(struct clk_hw *hw,
 					goto out;
 				}
 
-				if (abs(rate - rounded / i) <
-				    abs(rate - best_parent / best_div)) {
+				if (!best_parent ||
+				    abs(rate - rounded / i / j) <
+				    abs(rate - best_parent / best_half /
+					best_div)) {
 					best_parent = rounded;
-					best_div = i;
+					best_half = i;
+					best_div = j;
 				}
 			}
 		}
Signature · 1 line
2.15.0
#1 lore raw

Hi,

Quoted 9 lines · Jonathan Liu

There are several issues in sun4i_tmds_determine_rate:
- doesn't check if the best match was already set before comparing it with the enumerated parameters which could result in integer divide by zero
- doesn't consider rate halving when determining closest match if it can't match the requested rate exactly
- sets best_div to i which corresponds to rate halving when it should be set to j which corresponds to the divider

Quoted 4 lines

Fix these issues.

Fixes 9c5681011a0c ("drm/sun4i: Add HDMI support")

Please make separate patches for each of these issues, if possible detailing how do you reproduce them.

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20171221/555a6fd4/attachment.sig>