return 0;
 }
 
+static int fb_plane_width(int width,
+                         const struct drm_format_info *format, int plane)
+{
+       if (plane == 0)
+               return width;
+
+       return width / format->hsub;
+}
+
+static int fb_plane_height(int height,
+                          const struct drm_format_info *format, int plane)
+{
+       if (plane == 0)
+               return height;
+
+       return height / format->vsub;
+}
+
 static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
 {
        const struct drm_format_info *info;
        }
 
        for (i = 0; i < info->num_planes; i++) {
-               unsigned int width = r->width / (i != 0 ? info->hsub : 1);
-               unsigned int height = r->height / (i != 0 ? info->vsub : 1);
+               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];
 
                if (!r->handles[i]) {
        if (plane >= fb->format->num_planes)
                return 0;
 
-       if (plane == 0)
-               return width;
-
-       return width / fb->format->hsub;
+       return fb_plane_width(width, fb->format, plane);
 }
 EXPORT_SYMBOL(drm_framebuffer_plane_width);
 
        if (plane >= fb->format->num_planes)
                return 0;
 
-       if (plane == 0)
-               return height;
-
-       return height / fb->format->vsub;
+       return fb_plane_height(height, fb->format, plane);
 }
 EXPORT_SYMBOL(drm_framebuffer_plane_height);