[PATCH v2 12/25] drm/mediatek: Compute dumb-buffer sizes with drm_mode_size_dumb()
Thomas Zimmermann
tzimmermann at suse.de
Thu Jan 9 14:57:06 UTC 2025
Call drm_mode_size_dumb() to compute dumb-buffer scanline pitch and
buffer size. Align the pitch to a multiple of 8.
Signed-off-by: Thomas Zimmermann <tzimmermann at suse.de>
Cc: Chun-Kuang Hu <chunkuang.hu at kernel.org>
Cc: Philipp Zabel <p.zabel at pengutronix.de>
Cc: Matthias Brugger <matthias.bgg at gmail.com>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>
---
drivers/gpu/drm/mediatek/mtk_gem.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_gem.c b/drivers/gpu/drm/mediatek/mtk_gem.c
index a172456d1d7b..21e08fabfd7f 100644
--- a/drivers/gpu/drm/mediatek/mtk_gem.c
+++ b/drivers/gpu/drm/mediatek/mtk_gem.c
@@ -8,6 +8,7 @@
#include <drm/drm.h>
#include <drm/drm_device.h>
+#include <drm/drm_dumb_buffers.h>
#include <drm/drm_gem.h>
#include <drm/drm_gem_dma_helper.h>
#include <drm/drm_prime.h>
@@ -124,15 +125,9 @@ int mtk_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
struct mtk_gem_obj *mtk_gem;
int ret;
- args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
-
- /*
- * Multiply 2 variables of different types,
- * for example: args->size = args->spacing * args->height;
- * may cause coverity issue with unintentional overflow.
- */
- args->size = args->pitch;
- args->size *= args->height;
+ ret = drm_mode_size_dumb(dev, args, SZ_8, 0);
+ if (ret)
+ return ret;
mtk_gem = mtk_gem_create(dev, args->size, false);
if (IS_ERR(mtk_gem))
--
2.47.1
More information about the Spice-devel
mailing list