Commit 0709abaf authored by Thomas Zimmermann's avatar Thomas Zimmermann
Browse files

drm/imx/ipuv3: Fix dumb-buffer allocation for non-RGB formats



Align pitch to multiples of 8 pixels for bpp values that do not map
to RGB formats. The call to drm_driver_color_mode_format() fails with
DRM_INVALID_FORMAT in these cases. Fall back to manually computing
the pitch alignment from which drm_mode_size_dumb() can compute the
correct pitch.

Fixes userspace that allocates dumb buffers for YUV formats, where
bpp equals 12. A common example is the IGT kms_getfb test.

v2:
- ignore width in calculation

Suggested-by: default avatarDmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Fixes: b1d0e470 ("drm/imx/ipuv3: Compute dumb-buffer sizes with drm_mode_size_dumb()")
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Cc: imx@lists.linux.dev
Cc: linux-arm-kernel@lists.infradead.org
Tested-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Link: https://patch.msgid.link/20251104153832.189666-1-tzimmermann@suse.de
parent de0d6e19
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -144,7 +144,6 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,
			       struct drm_mode_create_dumb *args)
{
	u32 fourcc;
	const struct drm_format_info *info;
	u64 pitch_align;
	int ret;

@@ -156,12 +155,15 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,
	 * the allocated buffer.
	 */
	fourcc = drm_driver_color_mode_format(drm, args->bpp);
	if (fourcc == DRM_FORMAT_INVALID)
		return -EINVAL;
	info = drm_format_info(fourcc);
	if (fourcc != DRM_FORMAT_INVALID) {
		const struct drm_format_info *info = drm_format_info(fourcc);

		if (!info)
			return -EINVAL;
	pitch_align = drm_format_info_min_pitch(info, 0, SZ_8);
		pitch_align = drm_format_info_min_pitch(info, 0, 8);
	} else {
		pitch_align = DIV_ROUND_UP(args->bpp, SZ_8) * 8;
	}
	if (!pitch_align || pitch_align > U32_MAX)
		return -EINVAL;
	ret = drm_mode_size_dumb(drm, args, pitch_align, 0);