Call drm_mode_size_dumb() to compute dumb-buffer scanline pitch and buffer size. Align the pitch to a multiple of 4. Signed-off-by: Thomas Zimmermann <tzimmermann@xxxxxxx> Cc: David Airlie <airlied@xxxxxxxxxx> Cc: Gerd Hoffmann <kraxel@xxxxxxxxxx> Cc: Gurchetan Singh <gurchetansingh@xxxxxxxxxxxx> Cc: Chia-I Wu <olvaffe@xxxxxxxxx> --- drivers/gpu/drm/virtio/virtgpu_gem.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_gem.c b/drivers/gpu/drm/virtio/virtgpu_gem.c index 5aab588fc400..22cf1cd2fdfd 100644 --- a/drivers/gpu/drm/virtio/virtgpu_gem.c +++ b/drivers/gpu/drm/virtio/virtgpu_gem.c @@ -23,6 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include <drm/drm_dumb_buffers.h> #include <drm/drm_file.h> #include <drm/drm_fourcc.h> @@ -66,15 +67,14 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv, struct virtio_gpu_object_params params = { 0 }; struct virtio_gpu_device *vgdev = dev->dev_private; int ret; - uint32_t pitch; + + ret = drm_mode_size_dumb(dev, args, SZ_4, 0); + if (ret) + return ret; if (args->bpp != 32) return -EINVAL; - pitch = args->width * 4; - args->size = pitch * args->height; - args->size = ALIGN(args->size, PAGE_SIZE); - params.format = virtio_gpu_translate_format(DRM_FORMAT_HOST_XRGB8888); params.width = args->width; params.height = args->height; @@ -92,7 +92,6 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv, if (ret) goto fail; - args->pitch = pitch; return ret; fail: -- 2.47.1