From dcacfcd35cef2edb2854e2a04f204e309a8a2605 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 21 Aug 2025 10:17:10 +0200 Subject: [PATCH] drm/gem-dma: Compute dumb-buffer sizes with drm_mode_size_dumb() Call drm_mode_size_dumb() to compute dumb-buffer scanline pitch and buffer size. Align the pitch to a multiple of 8. Push the current calculation into the only direct caller imx. Imx's hardware requires the framebuffer width to be aligned to 8. The driver's current approach is actually incorrect, as it only guarantees this implicitly and requires bpp to be a multiple of 8 already. A later commit will fix this problem by aligning the scanline pitch such that an aligned width still fits into each scanline's memory. A number of other drivers are build on top of gem-dma helpers and implement their own dumb-buffer allocation. These drivers invoke drm_gem_dma_dumb_create_internal(), which is not affected by this commit. v5: - avoid reset of arguments (Tomi) Signed-off-by: Thomas Zimmermann Reviewed-by: Tomi Valkeinen Link: https://lore.kernel.org/r/20250821081918.79786-4-tzimmermann@suse.de --- drivers/gpu/drm/drm_gem_dma_helper.c | 7 +++++-- drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_dma_helper.c b/drivers/gpu/drm/drm_gem_dma_helper.c index a507cf5170155..9c9bfc9e85c62 100644 --- a/drivers/gpu/drm/drm_gem_dma_helper.c +++ b/drivers/gpu/drm/drm_gem_dma_helper.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -304,9 +305,11 @@ int drm_gem_dma_dumb_create(struct drm_file *file_priv, struct drm_mode_create_dumb *args) { struct drm_gem_dma_object *dma_obj; + int ret; - args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8); - args->size = args->pitch * args->height; + ret = drm_mode_size_dumb(drm, args, SZ_8, 0); + if (ret) + return ret; dma_obj = drm_gem_dma_create_with_handle(file_priv, drm, args->size, &args->handle); diff --git a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c index ec5fd9a01f1e4..af4a30311e188 100644 --- a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +++ b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c @@ -145,8 +145,10 @@ static int imx_drm_dumb_create(struct drm_file *file_priv, int ret; args->width = ALIGN(width, 8); + args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8); + args->size = args->pitch * args->height; - ret = drm_gem_dma_dumb_create(file_priv, drm, args); + ret = drm_gem_dma_dumb_create_internal(file_priv, drm, args); if (ret) return ret; -- 2.47.3