]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/gem-dma: Compute dumb-buffer sizes with drm_mode_size_dumb()
authorThomas Zimmermann <tzimmermann@suse.de>
Thu, 21 Aug 2025 08:17:10 +0000 (10:17 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Mon, 29 Sep 2025 11:57:44 +0000 (13:57 +0200)
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 <tzimmermann@suse.de>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Link: https://lore.kernel.org/r/20250821081918.79786-4-tzimmermann@suse.de
drivers/gpu/drm/drm_gem_dma_helper.c
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c

index a507cf517015520a77d4dd1f4a0518f2851a490e..9c9bfc9e85c62ee936264b54699eacad6cfafbaf 100644 (file)
@@ -20,6 +20,7 @@
 #include <drm/drm.h>
 #include <drm/drm_device.h>
 #include <drm/drm_drv.h>
+#include <drm/drm_dumb_buffers.h>
 #include <drm/drm_gem_dma_helper.h>
 #include <drm/drm_vma_manager.h>
 
@@ -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);
index ec5fd9a01f1e4475f70616c059030d391c865e29..af4a30311e188ec2d9470968c7d1ebf83091aa82 100644 (file)
@@ -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;