media: uvcvideo: Use a count variable for meta_formats instead of 0 terminating

The code dealing with the 0 terminated meta_formats array is a bit klunky
especially for the uvc_meta_v4l2_enum_formats() case.

Instead of 0 terminating add an unsigned int nmeta_formats member to struct
uvc_device and use that. This leads to slightly cleaner code.

Signed-off-by: Hans de Goede <hansg@kernel.org>
Reviewed-by: Ricardo Ribalda <ribalda@chrium.org>
Tested-by: Ricardo Ribalda <ribalda@chromium.org> # Camera with MSXU_CONTROL_METADATA
Link: https://lore.kernel.org/r/20250708104622.73237-2-hansg@kernel.org
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
This commit is contained in:
Hans de Goede 2025-07-08 12:46:22 +02:00 committed by Hans Verkuil
parent 6cb786f040
commit c56c437b14
2 changed files with 11 additions and 14 deletions

View File

@ -64,17 +64,16 @@ static int uvc_meta_v4l2_try_format(struct file *file, void *fh,
struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
struct uvc_device *dev = stream->dev;
struct v4l2_meta_format *fmt = &format->fmt.meta;
u32 fmeta = fmt->dataformat;
u32 i;
u32 fmeta = V4L2_META_FMT_UVC;
if (format->type != vfh->vdev->queue->type)
return -EINVAL;
for (i = 0; (fmeta != dev->meta_formats[i]) && dev->meta_formats[i];
i++)
;
if (!dev->meta_formats[i])
fmeta = V4L2_META_FMT_UVC;
for (unsigned int i = 0; i < dev->nmeta_formats; i++)
if (dev->meta_formats[i] == fmt->dataformat) {
fmeta = fmt->dataformat;
break;
}
memset(fmt, 0, sizeof(*fmt));
@ -119,14 +118,12 @@ static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh,
struct v4l2_fh *vfh = file->private_data;
struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
struct uvc_device *dev = stream->dev;
u32 i;
u32 i = fdesc->index;
if (fdesc->type != vfh->vdev->queue->type)
return -EINVAL;
for (i = 0; (i < fdesc->index) && dev->meta_formats[i]; i++)
;
if (!dev->meta_formats[i])
if (i >= dev->nmeta_formats)
return -EINVAL;
memset(fdesc, 0, sizeof(*fdesc));
@ -265,7 +262,7 @@ int uvc_meta_init(struct uvc_device *dev)
dev->meta_formats[i++] = V4L2_META_FMT_UVC_MSXU_1_5;
/* IMPORTANT: for new meta-formats update UVC_MAX_META_DATA_FORMATS. */
dev->meta_formats[i++] = 0;
dev->nmeta_formats = i;
return 0;
}

View File

@ -588,8 +588,8 @@ struct uvc_device {
const struct uvc_device_info *info;
/* Zero-ended list of meta formats */
u32 meta_formats[UVC_MAX_META_DATA_FORMATS + 1];
u32 meta_formats[UVC_MAX_META_DATA_FORMATS];
unsigned int nmeta_formats;
atomic_t nmappings;