Skip to contentSkip to conversation

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

PATCH In review Thomas Zimmermann 2 participants 4 messages Nov 4, 2025 – Nov 12, 2025

Subsystems (4)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

PATCH v2 1/1 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

Fixes b1d0e470f881 ("drm/imx/ipuv3: Compute dumb-buffer sizes with drm_mode_size_dumb()")
Cc Thomas Zimmermann <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Pengutronix Kernel Team <[email protected]>
Cc Fabio Estevam <[email protected]>

---
This patch is based on Dmitry's fix for msm. [1] Please test.

There could later be a helper to contain these aligmentment calculations in a single place.

[1] https://lore.kernel.org/dri-devel/[email protected]/

---
 drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +9 -7
index 465b5a6ad5bb..eddb471119c6 100644
@@ -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 (!info)
-		return -EINVAL;
-	pitch_align = drm_format_info_min_pitch(info, 0, SZ_8);
+	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, 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);
Signature · 1 line
2.51.1
author maintainer
#1 lore raw

Ping! Could this patch please get a timely review from imx maintainers?  Not fixing this bug could break user space.

Am 04.11.25 um 16:38 schrieb Thomas Zimmermann:

Quoted 69 lines

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

Fixes b1d0e470f881 ("drm/imx/ipuv3: Compute dumb-buffer sizes with drm_mode_size_dumb()")
Cc Thomas Zimmermann <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Pengutronix Kernel Team <[email protected]>
Cc Fabio Estevam <[email protected]>

---
This patch is based on Dmitry's fix for msm. [1] Please test.

There could later be a helper to contain these aligmentment calculations in a single place.

[1] https://lore.kernel.org/dri-devel/[email protected]/

---
  drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +9 -7
index 465b5a6ad5bb..eddb471119c6 100644
@@ -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 (!info)
-		return -EINVAL;
-	pitch_align = drm_format_info_min_pitch(info, 0, SZ_8);
+	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, 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);
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
maintainer Tested-by Reviewed-by on v2 1/1
#2 lore raw
In reply to Thomas Zimmermann
Quoted 24 lines · Thomas Zimmermann

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

Fixes b1d0e470f881 ("drm/imx/ipuv3: Compute dumb-buffer sizes with drm_mode_size_dumb()")
Cc Thomas Zimmermann <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Pengutronix Kernel Team <[email protected]>
Cc Fabio Estevam <[email protected]>
Quoted 2 lines

---
This patch is based on Dmitry's fix for msm. [1] Please test.

Thank you,

[IGT] kms_getfb: finished subtest getfb2-accept-nv12, CRASH -> SUCCESS

Quoted 32 lines

There could later be a helper to contain these aligmentment calculations in a single place.

[1] https://lore.kernel.org/dri-devel/[email protected]/

---
 drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +2 -7
index 465b5a6ad5bb..eddb471119c6 100644
@@ -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 (!info)
-		return -EINVAL;
-	pitch_align = drm_format_info_min_pitch(info, 0, SZ_8);
+	if (fourcc != DRM_FORMAT_INVALID) {
+		const struct drm_format_info *info = drm_format_info(fourcc);

drivers/gpu/drm/imx/ipuv3/imx-drm-core.c static int imx_drm_dumb_create(struct drm_file *file_priv, · line 169

Quoted 10 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +7 -0
+
+		if (!info)
+			return -EINVAL;
+		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);

regards
Philipp

author maintainer
#3 lore raw

Hi

Am 12.11.25 um 13:53 schrieb Philipp Zabel:

Quoted 68 lines · Thomas Zimmermann
Quoted 24 lines

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

Fixes b1d0e470f881 ("drm/imx/ipuv3: Compute dumb-buffer sizes with drm_mode_size_dumb()")
Cc Thomas Zimmermann <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Pengutronix Kernel Team <[email protected]>
Cc Fabio Estevam <[email protected]>
Quoted 2 lines

---
This patch is based on Dmitry's fix for msm. [1] Please test.

Thank you,

[IGT] kms_getfb: finished subtest getfb2-accept-nv12, CRASH -> SUCCESS

Quoted 35 lines

There could later be a helper to contain these aligmentment calculations in a single place.

[1] https://lore.kernel.org/dri-devel/[email protected]/

---
  drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +5 -7
index 465b5a6ad5bb..eddb471119c6 100644
@@ -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 (!info)
-		return -EINVAL;
-	pitch_align = drm_format_info_min_pitch(info, 0, SZ_8);
+	if (fourcc != DRM_FORMAT_INVALID) {
+		const struct drm_format_info *info = drm_format_info(fourcc);
+
+		if (!info)
+			return -EINVAL;
Quoted 8 lines

drivers/gpu/drm/imx/ipuv3/imx-drm-core.c static int imx_drm_dumb_create(struct drm_file *file_priv, · line 169

Quoted 7 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +4 -0
+		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);

Thanks a lot. I'll land this fix ASAP.

Best regards
Thomas

Quoted 3 lines

regards
Philipp

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)