Merge tag 'drm-misc-next-2018-11-28' of git://anongit.freedesktop.org/drm/drm-misc...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / drm_framebuffer.c
index 3bf729d0aae5899e1bca8dbd5783bbc38f899c73..fcaea8f50513d845b8d736d7d3df0092dc33d67b 100644 (file)
@@ -195,20 +195,26 @@ static int framebuffer_check(struct drm_device *dev,
        for (i = 0; i < info->num_planes; i++) {
                unsigned int width = fb_plane_width(r->width, info, i);
                unsigned int height = fb_plane_height(r->height, info, i);
-               unsigned int cpp = info->cpp[i];
+               unsigned int block_size = info->char_per_block[i];
+               u64 min_pitch = drm_format_info_min_pitch(info, i, width);
+
+               if (!block_size && (r->modifier[i] == DRM_FORMAT_MOD_LINEAR)) {
+                       DRM_DEBUG_KMS("Format requires non-linear modifier for plane %d\n", i);
+                       return -EINVAL;
+               }
 
                if (!r->handles[i]) {
                        DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
                        return -EINVAL;
                }
 
-               if ((uint64_t) width * cpp > UINT_MAX)
+               if (min_pitch > UINT_MAX)
                        return -ERANGE;
 
                if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX)
                        return -ERANGE;
 
-               if (r->pitches[i] < width * cpp) {
+               if (block_size && r->pitches[i] < min_pitch) {
                        DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i);
                        return -EINVAL;
                }
@@ -317,6 +323,7 @@ drm_internal_framebuffer_create(struct drm_device *dev,
 
        return fb;
 }
+EXPORT_SYMBOL_FOR_TESTS_ONLY(drm_internal_framebuffer_create);
 
 /**
  * drm_mode_addfb2 - add an FB to the graphics configuration