Skip to contentSkip to conversation

drm/vmwgfx: Fix order of operation

PATCH New Sinclair Yeh 1 participant 1 message Apr 27, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 drm/vmwgfx: Fix order of operation

mode->hdisplay * (var->bits_per_pixel + 7) gets evaluated before the division, potentially making the pitch larger than it should be.

Since the original intention is to do a div-round-up, just use the macro instead.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_fb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c +3 -3
index 3b1faf7..679a4cb 100644
@@ -573,9 +573,9 @@ static int vmw_fb_set_par(struct fb_info *info)
 		mode = old_mode;
 		old_mode = NULL;
 	} else if (!vmw_kms_validate_mode_vram(vmw_priv,
-					       mode->hdisplay *
-					       (var->bits_per_pixel + 7) / 8,
-					       mode->vdisplay)) {
+					mode->hdisplay *
+					DIV_ROUND_UP(var->bits_per_pixel, 8),
+					mode->vdisplay)) {
 		drm_mode_destroy(vmw_priv->dev, mode);
 		return -EINVAL;
 	}
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel