Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/rect: Round above 1 << 16 upwards to correct scale calculation functions.

When calculating limits we want to be as pessimistic as possible,
so we have to explicitly say whether we want to round up or down
to accurately calculate whether we are below min_scale or above
max_scale.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
[mlankhorst: Fix wording in documentation. (Ville)]
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180503112217.37292-2-maarten.lankhorst@linux.intel.com

+20 -1
+20 -1
drivers/gpu/drm/drm_rect.c
··· 106 106 if (dst == 0) 107 107 return 0; 108 108 109 - scale = src / dst; 109 + if (src > (dst << 16)) 110 + return DIV_ROUND_UP(src, dst); 111 + else 112 + scale = src / dst; 110 113 111 114 return scale; 112 115 } ··· 123 120 * 124 121 * Calculate the horizontal scaling factor as 125 122 * (@src width) / (@dst width). 123 + * 124 + * If the scale is below 1 << 16, round down. If the scale is above 125 + * 1 << 16, round up. This will calculate the scale with the most 126 + * pessimistic limit calculation. 126 127 * 127 128 * RETURNS: 128 129 * The horizontal scaling factor, or errno of out of limits. ··· 158 151 * 159 152 * Calculate the vertical scaling factor as 160 153 * (@src height) / (@dst height). 154 + * 155 + * If the scale is below 1 << 16, round down. If the scale is above 156 + * 1 << 16, round up. This will calculate the scale with the most 157 + * pessimistic limit calculation. 161 158 * 162 159 * RETURNS: 163 160 * The vertical scaling factor, or errno of out of limits. ··· 199 188 * 200 189 * If the calculated scaling factor is above @max_vscale, 201 190 * decrease the height of rectangle @src to compensate. 191 + * 192 + * If the scale is below 1 << 16, round down. If the scale is above 193 + * 1 << 16, round up. This will calculate the scale with the most 194 + * pessimistic limit calculation. 202 195 * 203 196 * RETURNS: 204 197 * The horizontal scaling factor. ··· 253 238 * 254 239 * If the calculated scaling factor is above @max_vscale, 255 240 * decrease the height of rectangle @src to compensate. 241 + * 242 + * If the scale is below 1 << 16, round down. If the scale is above 243 + * 1 << 16, round up. This will calculate the scale with the most 244 + * pessimistic limit calculation. 256 245 * 257 246 * RETURNS: 258 247 * The vertical scaling factor.