Skip to content

Commit c56c437

Browse files
Hans de Goedehverkuil
authored andcommitted
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 <[email protected]> Reviewed-by: Ricardo Ribalda <[email protected]> Tested-by: Ricardo Ribalda <[email protected]> # Camera with MSXU_CONTROL_METADATA Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans Verkuil <[email protected]>
1 parent 6cb786f commit c56c437

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

drivers/media/usb/uvc/uvc_metadata.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,16 @@ static int uvc_meta_v4l2_try_format(struct file *file, void *fh,
6464
struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
6565
struct uvc_device *dev = stream->dev;
6666
struct v4l2_meta_format *fmt = &format->fmt.meta;
67-
u32 fmeta = fmt->dataformat;
68-
u32 i;
67+
u32 fmeta = V4L2_META_FMT_UVC;
6968

7069
if (format->type != vfh->vdev->queue->type)
7170
return -EINVAL;
7271

73-
for (i = 0; (fmeta != dev->meta_formats[i]) && dev->meta_formats[i];
74-
i++)
75-
;
76-
if (!dev->meta_formats[i])
77-
fmeta = V4L2_META_FMT_UVC;
72+
for (unsigned int i = 0; i < dev->nmeta_formats; i++)
73+
if (dev->meta_formats[i] == fmt->dataformat) {
74+
fmeta = fmt->dataformat;
75+
break;
76+
}
7877

7978
memset(fmt, 0, sizeof(*fmt));
8079

@@ -119,14 +118,12 @@ static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh,
119118
struct v4l2_fh *vfh = file->private_data;
120119
struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
121120
struct uvc_device *dev = stream->dev;
122-
u32 i;
121+
u32 i = fdesc->index;
123122

124123
if (fdesc->type != vfh->vdev->queue->type)
125124
return -EINVAL;
126125

127-
for (i = 0; (i < fdesc->index) && dev->meta_formats[i]; i++)
128-
;
129-
if (!dev->meta_formats[i])
126+
if (i >= dev->nmeta_formats)
130127
return -EINVAL;
131128

132129
memset(fdesc, 0, sizeof(*fdesc));
@@ -265,7 +262,7 @@ int uvc_meta_init(struct uvc_device *dev)
265262
dev->meta_formats[i++] = V4L2_META_FMT_UVC_MSXU_1_5;
266263

267264
/* IMPORTANT: for new meta-formats update UVC_MAX_META_DATA_FORMATS. */
268-
dev->meta_formats[i++] = 0;
265+
dev->nmeta_formats = i;
269266

270267
return 0;
271268
}

drivers/media/usb/uvc/uvcvideo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ struct uvc_device {
588588

589589
const struct uvc_device_info *info;
590590

591-
/* Zero-ended list of meta formats */
592-
u32 meta_formats[UVC_MAX_META_DATA_FORMATS + 1];
591+
u32 meta_formats[UVC_MAX_META_DATA_FORMATS];
592+
unsigned int nmeta_formats;
593593

594594
atomic_t nmappings;
595595

0 commit comments

Comments
 (0)