Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Fixes: b1d0e470f881 ("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: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Link: https://patch.msgid.link/20251104153832.189666-1-tzimmermann@suse.de

+9 -7
+9 -7
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
··· 144 144 struct drm_mode_create_dumb *args) 145 145 { 146 146 u32 fourcc; 147 - const struct drm_format_info *info; 148 147 u64 pitch_align; 149 148 int ret; 150 149 ··· 155 156 * the allocated buffer. 156 157 */ 157 158 fourcc = drm_driver_color_mode_format(drm, args->bpp); 158 - if (fourcc == DRM_FORMAT_INVALID) 159 - return -EINVAL; 160 - info = drm_format_info(fourcc); 161 - if (!info) 162 - return -EINVAL; 163 - pitch_align = drm_format_info_min_pitch(info, 0, SZ_8); 159 + if (fourcc != DRM_FORMAT_INVALID) { 160 + const struct drm_format_info *info = drm_format_info(fourcc); 161 + 162 + if (!info) 163 + return -EINVAL; 164 + pitch_align = drm_format_info_min_pitch(info, 0, 8); 165 + } else { 166 + pitch_align = DIV_ROUND_UP(args->bpp, SZ_8) * 8; 167 + } 164 168 if (!pitch_align || pitch_align > U32_MAX) 165 169 return -EINVAL; 166 170 ret = drm_mode_size_dumb(drm, args, pitch_align, 0);