Re: [PATCH 1/2] media: v4l2-common: add v4l2_fill_pixfmt_aligned() helper

From: Laurent Pinchart

Date: Thu Jun 25 2026 - 04:52:55 EST


On Thu, Jun 25, 2026 at 10:12:49AM +0200, Tommaso Merciai wrote:
> Hi Laurent,
> Thanks for your review.
>
> On Wed, Jun 24, 2026 at 10:28:55PM +0300, Laurent Pinchart wrote:
> > Hi Tommaso,
> >
> > Thank you for the patch.
> >
> > On Wed, Jun 24, 2026 at 12:41:30PM +0200, Tommaso Merciai wrote:
> > > Add v4l2_fill_pixfmt_aligned(), a variant of v4l2_fill_pixfmt()
> > > that accepts a stride_alignment parameter, mirroring the existing
> > > v4l2_fill_pixfmt_mp() / v4l2_fill_pixfmt_mp_aligned() pair.
> > >
> > > v4l2_fill_pixfmt() is refactored to call v4l2_fill_pixfmt_aligned()
> > > with stride_alignment=1, preserving its existing behaviour.
> > >
> > > The new helper is needed by drivers whose DMA engine requires the
> > > line stride to be a multiple of a specific value, such as the
> > > Renesas RZ/G3E CRU which requires 128-byte alignment.
> > >
> > > Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@xxxxxxxxxxxxxx>
> > > ---
> > > drivers/media/v4l2-core/v4l2-common.c | 17 +++++++++++++----
> > > include/media/v4l2-common.h | 3 +++
> > > 2 files changed, 16 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
> > > index 65db7340ad38..1de246acc7ab 100644
> > > --- a/drivers/media/v4l2-core/v4l2-common.c
> > > +++ b/drivers/media/v4l2-core/v4l2-common.c
> > > @@ -545,8 +545,8 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt,
> > > }
> > > EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt_mp);
> > >
> > > -int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
> > > - u32 width, u32 height)
> > > +int v4l2_fill_pixfmt_aligned(struct v4l2_pix_format *pixfmt, u32 pixelformat,
> > > + u32 width, u32 height, u8 stride_alignment)
> > > {
> > > const struct v4l2_format_info *info;
> > > int i;
> > > @@ -562,14 +562,23 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
> > > pixfmt->width = width;
> > > pixfmt->height = height;
> > > pixfmt->pixelformat = pixelformat;
> > > - pixfmt->bytesperline = v4l2_format_plane_stride(info, 0, width, 1);
> > > + pixfmt->bytesperline = v4l2_format_plane_stride(info, 0, width,
> > > + stride_alignment);
> > > pixfmt->sizeimage = 0;
> > >
> > > for (i = 0; i < info->comp_planes; i++)
> > > pixfmt->sizeimage +=
> > > - v4l2_format_plane_size(info, i, width, height, 1);
> > > + v4l2_format_plane_size(info, i, width, height,
> > > + stride_alignment);
> > > return 0;
> > > }
> > > +EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt_aligned);
> > > +
> > > +int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
> > > + u32 width, u32 height)
> > > +{
> > > + return v4l2_fill_pixfmt_aligned(pixfmt, pixelformat, width, height, 1);
> > > +}
> >
> > This could be an inline wrapper in include/media/v4l2-common.h, it would
> > be more efficient.
>
> Ok, thanks.
> I guess we want the same for v4l2_fill_pixfmt_mp() ?

That would be nice, as a separate patch, if you have time.

> > > EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt);
> > >
> > > #ifdef CONFIG_MEDIA_CONTROLLER
> > > diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
> > > index edd416178c33..718a0f47f36b 100644
> > > --- a/include/media/v4l2-common.h
> > > +++ b/include/media/v4l2-common.h
> > > @@ -556,6 +556,9 @@ void v4l2_apply_frmsize_constraints(u32 *width, u32 *height,
> > > const struct v4l2_frmsize_stepwise *frmsize);
> > > int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
> > > u32 width, u32 height);
> > > +/* @stride_alignment is a power of 2 value in bytes */
> > > +int v4l2_fill_pixfmt_aligned(struct v4l2_pix_format *pixfmt, u32 pixelformat,
> > > + u32 width, u32 height, u8 stride_alignment);
> >
> > I know the existing functions lack documentation, but it's not a reason
> > to continue with that bad habit :-)
>
> Ouch :)
>
> > One point that needs to be clearly documented is how the stride
> > alignment is handled for different planes.
>
> Thanks, I will add documentation in v2.
>
> > > int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat,
> > > u32 width, u32 height);
> > > /* @stride_alignment is a power of 2 value in bytes */

--
Regards,

Laurent Pinchart