OSDN Git Service

drm/modes: Switch to 64bit maths to avoid integer overflow
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Thu, 22 Oct 2020 19:42:56 +0000 (22:42 +0300)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Thu, 14 Jan 2021 17:37:53 +0000 (19:37 +0200)
The new >8k CEA modes have dotclocks reaching 5.94 GHz, which
means our clock*1000 will now overflow the 32bit unsigned
integer. Switch to 64bit maths to avoid it.

Cc: stable@vger.kernel.org
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20201022194256.30978-1-ville.syrjala@linux.intel.com
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
drivers/gpu/drm/drm_modes.c

index 33fb2f0..1ac67d4 100644 (file)
@@ -762,7 +762,7 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode)
        if (mode->htotal == 0 || mode->vtotal == 0)
                return 0;
 
-       num = mode->clock * 1000;
+       num = mode->clock;
        den = mode->htotal * mode->vtotal;
 
        if (mode->flags & DRM_MODE_FLAG_INTERLACE)
@@ -772,7 +772,7 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode)
        if (mode->vscan > 1)
                den *= mode->vscan;
 
-       return DIV_ROUND_CLOSEST(num, den);
+       return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
 }
 EXPORT_SYMBOL(drm_mode_vrefresh);