drm: Checking of the pitch is only valid for linear formats
authorDave Stevenson <dave.stevenson@raspberrypi.com>
Mon, 27 Jan 2020 10:22:44 +0000 (10:22 +0000)
committerDom Cobley <popcornmix@gmail.com>
Mon, 21 Mar 2022 16:04:00 +0000 (16:04 +0000)
framebuffer_check was computing a minimum pitch value and ensuring
that the provided value was greater than this.
That check is only valid if the format is linear.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
drivers/gpu/drm/drm_framebuffer.c

index 07f5abc875e97b96873f246cd3eea293e6978100..8683b59bcbcbaf57b4b2a4a2efa45f025d07123b 100644 (file)
@@ -214,12 +214,16 @@ static int framebuffer_check(struct drm_device *dev,
                if (min_pitch > UINT_MAX)
                        return -ERANGE;
 
-               if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX)
-                       return -ERANGE;
-
-               if (block_size && r->pitches[i] < min_pitch) {
-                       DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i);
-                       return -EINVAL;
+               if (r->modifier[i] == DRM_FORMAT_MOD_LINEAR) {
+                       if ((uint64_t)height * r->pitches[i] + r->offsets[i] >
+                                                               UINT_MAX)
+                               return -ERANGE;
+
+                       if (block_size && r->pitches[i] < min_pitch) {
+                               DRM_DEBUG_KMS("bad pitch %u for plane %d\n",
+                                             r->pitches[i], i);
+                               return -EINVAL;
+                       }
                }
 
                if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) {