]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
media: uvcvideo: Use a count variable for meta_formats instead of 0 terminating
authorHans de Goede <hansg@kernel.org>
Tue, 8 Jul 2025 10:46:22 +0000 (12:46 +0200)
committerHans Verkuil <hverkuil@xs4all.nl>
Fri, 11 Jul 2025 17:27:31 +0000 (19:27 +0200)
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>
drivers/media/usb/uvc/uvc_metadata.c
drivers/media/usb/uvc/uvcvideo.h

index 12972527ab8d5e92c6fb4cbce53fc0dbebbaab62..229e08ff323eed9129d835b24ea2e8085bb713b8 100644 (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;
 }
index b34c1914ff394dc61a3636217c9e256e4ced7274..757254fc4fe930ae61c9d0425f04d4cd074a617e 100644 (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;