[15/16] media: sun6i-isp: Add support for MC-centric format enumeration
Commit Message
Just make sure the provided mbus code is supported and carry on with the
existing implementation since the pixelformat is independent from the
mbus code.
The params video node only supports a single format and does not care
about the mbus format, but we can still report MC-centric support.
Signed-off-by: Paul Kocialkowski <paulk@sys-base.io>
---
.../staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c | 9 ++++++++-
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c | 3 ++-
2 files changed, 10 insertions(+), 2 deletions(-)
Comments
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing mbus_code validation in sun6i_isp_params_enum_fmt when V4L2_CAP_IO_MC is enabled.
--
commit 1a4894a83da0c694f7055ec896e27ceb3fb1ad43
Author: Paul Kocialkowski <paulk@sys-base.io>
media: sun6i-isp: Add support for MC-centric format enumeration
This commit adds MC-centric format enumeration support to the sun6i-isp
driver by setting the V4L2_CAP_IO_MC capability on the capture and params
video nodes. It also updates the capture format enumeration to validate
the provided mbus code.
> diff --git a/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c b/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c
> index 0cc48e2bc8c61..2622e5a078176 100644
> --- a/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c
> +++ b/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c
> @@ -531,7 +531,8 @@ int sun6i_isp_params_setup(struct sun6i_isp_device *isp_dev)
>
> strscpy(video_dev->name, SUN6I_ISP_PARAMS_NAME,
> sizeof(video_dev->name));
> - video_dev->device_caps = V4L2_CAP_META_OUTPUT | V4L2_CAP_STREAMING;
> + video_dev->device_caps = V4L2_CAP_META_OUTPUT | V4L2_CAP_STREAMING |
> + V4L2_CAP_IO_MC;
The commit message mentions that the params video node does not care about
the mbus format, but with V4L2_CAP_IO_MC enabled here, does this allow
sun6i_isp_params_enum_fmt() to return success for invalid mbus codes?
According to the V4L2 specification for MC-centric devices, if the
mbus_code field in struct v4l2_fmtdesc is non-zero during the
VIDIOC_ENUM_FMT ioctl, the driver must restrict the enumerated formats
to those supported for the given media bus code, and return -EINVAL if
the code is unsupported.
By ignoring the mbus_code in the params node entirely, it appears userspace
could query completely arbitrary values and still receive a 0 (success)
return code. This incorrectly informs userspace that the format is
supported in combination with any given mbus_code.
Should sun6i_isp_params_enum_fmt() be updated to return -EINVAL if a
non-zero mbus_code is provided, similar to the check added in
sun6i_isp_capture_enum_fmt()?
Hi Paul,
On Mon, May 18, 2026 at 2:02 PM Paul Kocialkowski <paulk@sys-base.io> wrote:
>
> Just make sure the provided mbus code is supported and carry on with the
> existing implementation since the pixelformat is independent from the
> mbus code.
>
> The params video node only supports a single format and does not care
> about the mbus format, but we can still report MC-centric support.
>
> Signed-off-by: Paul Kocialkowski <paulk@sys-base.io>
> ---
> .../staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c | 9 ++++++++-
> drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c | 3 ++-
> 2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c b/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c
> index 24e731bcabe9..372b9331bd6d 100644
> --- a/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c
> +++ b/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c
> @@ -436,8 +436,14 @@ static int sun6i_isp_capture_querycap(struct file *file, void *priv,
> static int sun6i_isp_capture_enum_fmt(struct file *file, void *priv,
> struct v4l2_fmtdesc *fmtdesc)
> {
> + u32 mbus_code = fmtdesc->mbus_code;
> u32 index = fmtdesc->index;
>
> + if (mbus_code && !sun6i_isp_proc_format_find(mbus_code))
> + return -EINVAL;
> +
> + /* Capture format is independent from proc format. */
> +
> if (index >= ARRAY_SIZE(sun6i_isp_capture_formats))
> return -EINVAL;
>
> @@ -697,7 +703,8 @@ int sun6i_isp_capture_setup(struct sun6i_isp_device *isp_dev)
>
> strscpy(video_dev->name, SUN6I_ISP_CAPTURE_NAME,
> sizeof(video_dev->name));
> - video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
> + video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
> + V4L2_CAP_IO_MC;
> video_dev->vfl_dir = VFL_DIR_RX;
> video_dev->release = video_device_release_empty;
> video_dev->fops = &sun6i_isp_capture_fops;
> diff --git a/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c b/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c
> index 0cc48e2bc8c6..2622e5a07817 100644
> --- a/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c
> +++ b/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c
> @@ -531,7 +531,8 @@ int sun6i_isp_params_setup(struct sun6i_isp_device *isp_dev)
>
> strscpy(video_dev->name, SUN6I_ISP_PARAMS_NAME,
> sizeof(video_dev->name));
> - video_dev->device_caps = V4L2_CAP_META_OUTPUT | V4L2_CAP_STREAMING;
> + video_dev->device_caps = V4L2_CAP_META_OUTPUT | V4L2_CAP_STREAMING |
> + V4L2_CAP_IO_MC;
> video_dev->vfl_dir = VFL_DIR_TX;
> video_dev->release = video_device_release_empty;
> video_dev->fops = &sun6i_isp_params_fops;
> --
> 2.54.0
>
Tested on a LicheePi Zero Dock (V3s) with the following pipeline:
ov5647 -> sun6i-mipi-csi2 -> sun6i-csi-bridge -> sun6i-isp-proc ->
sun6i-isp-capture
I verified MC-centric format enumeration on the ISP capture node with
multiple mbus codes supported by sun6i-isp-proc.
Tested-by: Arash Golgol <arash.golgol@gmail.com>
@@ -436,8 +436,14 @@ static int sun6i_isp_capture_querycap(struct file *file, void *priv,
static int sun6i_isp_capture_enum_fmt(struct file *file, void *priv,
struct v4l2_fmtdesc *fmtdesc)
{
+ u32 mbus_code = fmtdesc->mbus_code;
u32 index = fmtdesc->index;
+ if (mbus_code && !sun6i_isp_proc_format_find(mbus_code))
+ return -EINVAL;
+
+ /* Capture format is independent from proc format. */
+
if (index >= ARRAY_SIZE(sun6i_isp_capture_formats))
return -EINVAL;
@@ -697,7 +703,8 @@ int sun6i_isp_capture_setup(struct sun6i_isp_device *isp_dev)
strscpy(video_dev->name, SUN6I_ISP_CAPTURE_NAME,
sizeof(video_dev->name));
- video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
+ video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
+ V4L2_CAP_IO_MC;
video_dev->vfl_dir = VFL_DIR_RX;
video_dev->release = video_device_release_empty;
video_dev->fops = &sun6i_isp_capture_fops;
@@ -531,7 +531,8 @@ int sun6i_isp_params_setup(struct sun6i_isp_device *isp_dev)
strscpy(video_dev->name, SUN6I_ISP_PARAMS_NAME,
sizeof(video_dev->name));
- video_dev->device_caps = V4L2_CAP_META_OUTPUT | V4L2_CAP_STREAMING;
+ video_dev->device_caps = V4L2_CAP_META_OUTPUT | V4L2_CAP_STREAMING |
+ V4L2_CAP_IO_MC;
video_dev->vfl_dir = VFL_DIR_TX;
video_dev->release = video_device_release_empty;
video_dev->fops = &sun6i_isp_params_fops;