Skip to contentSkip to conversation

drm/sun4i: hdmi: Fix u64 div on 32bit arch

PATCH Applied Maxime Ripard 2 participants 4 messages Mar 4, 2024 – Mar 14, 2024

Subsystems (4)
lore
Share & tools
lore

Maxime Ripard

author maintainer
#0 lore raw

PATCH 1/1 drm/sun4i: hdmi: Fix u64 div on 32bit arch

Commit 358e76fd613a ("drm/sun4i: hdmi: Consolidate atomic_check and mode_valid") changed the clock rate from an unsigned long to an unsigned long long resulting in a a 64-bit division that might not be supported on all platforms.

The resulted in compilation being broken at least for m68k, xtensa and some arm configurations, at least.

---
 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +1 -1
index b7cf369b1906..987041850df2 100644
@@ -163,11 +163,11 @@ static enum drm_mode_status
 sun4i_hdmi_connector_clock_valid(const struct drm_connector *connector,
 				 const struct drm_display_mode *mode,
 				 unsigned long long clock)
 {
 	const struct sun4i_hdmi *hdmi = drm_connector_to_sun4i_hdmi(connector);
-	unsigned long diff = clock / 200; /* +-0.5% allowed by HDMI spec */
+	unsigned long diff = div_u64(clock, 200); /* +-0.5% allowed by HDMI spec */
 	long rounded_rate;
 
 	if (mode->flags & DRM_MODE_FLAG_DBLCLK)
 		return MODE_BAD;
 
Signature · 1 line
2.43.2
#1 lore raw

Hi Maxime,

Thanks for your patch!

Quoted 4 lines · Maxime Ripard

Commit 358e76fd613a ("drm/sun4i: hdmi: Consolidate atomic_check and mode_valid") changed the clock rate from an unsigned long to an unsigned long long resulting in a a 64-bit division that might not be supported on all platforms.

Why was this changed to unsigned long long?
Can a valid pixel clock really not fit in 32-bit?

Quoted 14 lines

The resulted in compilation being broken at least for m68k, xtensa and some arm configurations, at least.

drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c static enum drm_mode_status · line 168

Quoted 7 lines
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +1 -1
@@ -163,11 +163,11 @@ static enum drm_mode_status
 sun4i_hdmi_connector_clock_valid(const struct drm_connector *connector,
                                 const struct drm_display_mode *mode,
                                 unsigned long long clock)
 {
        const struct sun4i_hdmi *hdmi = drm_connector_to_sun4i_hdmi(connector);
-       unsigned long diff = clock / 200; /* +-0.5% allowed by HDMI spec */
+       unsigned long diff = div_u64(clock, 200); /* +-0.5% allowed by HDMI spec */

I'd rather see clock changed back to unsigned long.

drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c static enum drm_mode_status · line 173

Quoted 5 lines
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +0 -0
        long rounded_rate;
 
        if (mode->flags & DRM_MODE_FLAG_DBLCLK)
                return MODE_BAD;
 

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author maintainer
#2 lore raw
Quoted 4 lines · Geert Uytterhoeven

Hi Maxime,

Thanks for your patch!

Quoted 8 lines
Quoted 4 lines · Maxime Ripard

Commit 358e76fd613a ("drm/sun4i: hdmi: Consolidate atomic_check and mode_valid") changed the clock rate from an unsigned long to an unsigned long long resulting in a a 64-bit division that might not be supported on all platforms.

Why was this changed to unsigned long long?
Can a valid pixel clock really not fit in 32-bit?

Yes, HDMI 2.1 supports pixel rates up until 5.940GHz, so the framework has to use that.

Quoted 11 lines
Quoted 10 lines

The resulted in compilation being broken at least for m68k, xtensa and some arm configurations, at least.

Quoted 12 lines

drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c static enum drm_mode_status · line 168

Quoted 10 lines
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +1 -1
@@ -163,11 +163,11 @@ static enum drm_mode_status
 sun4i_hdmi_connector_clock_valid(const struct drm_connector *connector,
                                 const struct drm_display_mode *mode,
                                 unsigned long long clock)
 {
        const struct sun4i_hdmi *hdmi = drm_connector_to_sun4i_hdmi(connector);
-       unsigned long diff = clock / 200; /* +-0.5% allowed by HDMI spec */
+       unsigned long diff = div_u64(clock, 200); /* +-0.5% allowed by HDMI spec */

I'd rather see clock changed back to unsigned long.

No, the tolerance we allow is an unsigned long. The tolerance is 0.5% of the pixel clock, so even if that controller supported HDMI 2.1 at its full capacity (it doesn't, at all), it would be 29.7 MHz, which fits comfortably in an unsigned long.

Maxime

author maintainer Applied
#3 lore raw
In reply to Maxime Ripard
Quoted 9 lines · Maxime Ripard

Commit 358e76fd613a ("drm/sun4i: hdmi: Consolidate atomic_check and mode_valid") changed the clock rate from an unsigned long to an unsigned long long resulting in a a 64-bit division that might not be supported on all platforms.

The resulted in compilation being broken at least for m68k, xtensa and some arm configurations, at least.

[...]

Applied to misc/kernel.git (drm-misc-next-fixes).

Thanks!
Maxime