Re: [PATCH v2 1/4] media: rcar-isp: ispcore: Honour requested bytesperline on RAW input

From: Jacopo Mondi

Date: Mon Nov 16 2026 - 06:38:36 EST


Hi Niklas,

On Sat, Nov 14, 2026 at 08:55:16PM +0100, Niklas Söderlund wrote:
> From: Yuya Hamamachi <yuya.hamamachi.sx@xxxxxxxxxxx>
>
> The RAW input video device always overwrote the bytesperline requested
> by userspace with width * bpp. The input buffers are however shared with
> the VIN, which may use a larger line stride (for example 3296 instead of
> 3280 bytes for a 1640 pixel wide 10 bit image). The dmabuf exported by
> the ISP was then smaller than the VIN buffer size, and queueing it to
> the VIN failed with -EINVAL:
>
> __prepare_dmabuf: invalid dmabuf length 4042752 for plane 0,
> minimum length 4060672
>
> Use the requested bytesperline if it is larger than the minimum.
>

This is worth a fixes imo

> Signed-off-by: Yuya Hamamachi <yuya.hamamachi.sx@xxxxxxxxxxx>
> [Niklas: Use clamp(..) instead of if statements]
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@xxxxxxxxxxxx>
> ---
> * Changes since v1
> - Use clamp() instead of max(min()).
> - Upper limit at SZ_64K - 1, not SZ_64K.
> ---
> drivers/media/platform/renesas/rcar-isp/core-io.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/renesas/rcar-isp/core-io.c b/drivers/media/platform/renesas/rcar-isp/core-io.c
> index b60b91f43d42..cc538e984aa1 100644
> --- a/drivers/media/platform/renesas/rcar-isp/core-io.c
> +++ b/drivers/media/platform/renesas/rcar-isp/core-io.c
> @@ -5,6 +5,8 @@
> * Copyright (C) 2026 Ragnatech AB
> */
>
> +#include <linux/sizes.h>
> +
> #include <media/v4l2-ctrls.h>
> #include <media/v4l2-event.h>
> #include <media/v4l2-ioctl.h>
> @@ -335,6 +337,7 @@ static void risp_io_input_try_format(struct rcar_isp_core_io *io,
> struct v4l2_pix_format_mplane *pix)
> {
> unsigned int bpp = 0;
> + unsigned int bpl;
>
> v4l_bound_align_image(&pix->width, RISP_MIN_WIDTH, RISP_MAX_WIDTH, RISP_SIZE_ALIGNMENT,
> &pix->height, RISP_MIN_HEIGHT, RISP_MAX_HEIGHT, RISP_SIZE_ALIGNMENT,
> @@ -352,11 +355,17 @@ static void risp_io_input_try_format(struct rcar_isp_core_io *io,
> bpp = risp_io_input_formats[0].bpp;
> }
>
> + /*
> + * Honour the line stride requested by userspace, the buffers are
> + * shared with the VIN which may use a larger stride than the minimum.
> + */
> + bpl = clamp(pix->plane_fmt[0].bytesperline, pix->width * bpp, SZ_64K - 1);
> +

There is a (quite long) anlysis of this bug in our forge:
https://git.ideasonboard.com/renesas-v4h-isp/libcamera/issues/14

and while the commit message of this patch correctly identify the issue
it doesn't take into account any requirement (stride alignment and max
stride length) of the VSP-X unit which actually does the transfer on
behalf of the ISP.

We didn't get to the bottom of VSP-X stride alignment constraints, but
the RPF unit documentation specifies a max size for the source picture
stride (which is the SZ_64K - 1 value that is used by this patch).
https://git.ideasonboard.com/renesas-v4h-isp/libcamera/issues/14#issuecomment-40317

Laurent suggested to get the VSP-X stride alignment and max size by
adding a function (possibily a try format) in the ISP/VSP-X interface.

I'm more of the opinion that as the ISP-core, VSP-X and VIN are part
of the same SoC it is not too crazy to use (SZ_64K - 1) here directly
(maybe adding a comment on where the limits comes from).

What do you think ?


> pix->field = V4L2_FIELD_NONE;
> pix->colorspace = V4L2_COLORSPACE_RAW;
>
> pix->num_planes = 1;
> - pix->plane_fmt[0].bytesperline = pix->width * bpp;
> + pix->plane_fmt[0].bytesperline = bpl;
> pix->plane_fmt[0].sizeimage = pix->plane_fmt[0].bytesperline * pix->height;
> }
>
>
> --
> 2.55.0
>
>