Skip to content

Commit

Permalink
[media] uvcvideo: Don't fail when an unsupported format is requested
Browse files Browse the repository at this point in the history
Return the default format in that case.
This issue was found by the v4l2-compliance tool.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Laurent Pinchart authored and Mauro Carvalho Chehab committed Nov 28, 2012
1 parent 30ecb93 commit 815adc4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions drivers/media/usb/uvc/uvc_v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,18 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream,
fcc[0], fcc[1], fcc[2], fcc[3],
fmt->fmt.pix.width, fmt->fmt.pix.height);

/* Check if the hardware supports the requested format. */
/* Check if the hardware supports the requested format, use the default
* format otherwise.
*/
for (i = 0; i < stream->nformats; ++i) {
format = &stream->format[i];
if (format->fcc == fmt->fmt.pix.pixelformat)
break;
}

if (format == NULL || format->fcc != fmt->fmt.pix.pixelformat) {
uvc_trace(UVC_TRACE_FORMAT, "Unsupported format 0x%08x.\n",
fmt->fmt.pix.pixelformat);
return -EINVAL;
if (i == stream->nformats) {
format = stream->def_format;
fmt->fmt.pix.pixelformat = format->fcc;
}

/* Find the closest image size. The distance between image sizes is
Expand Down
1 change: 1 addition & 0 deletions drivers/media/usb/uvc/uvc_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,7 @@ int uvc_video_init(struct uvc_streaming *stream)
probe->bFormatIndex = format->index;
probe->bFrameIndex = frame->bFrameIndex;

stream->def_format = format;
stream->cur_format = format;
stream->cur_frame = frame;

Expand Down
1 change: 1 addition & 0 deletions drivers/media/usb/uvc/uvcvideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ struct uvc_streaming {
struct uvc_format *format;

struct uvc_streaming_control ctrl;
struct uvc_format *def_format;
struct uvc_format *cur_format;
struct uvc_frame *cur_frame;
/* Protect access to ctrl, cur_format, cur_frame and hardware video
Expand Down

0 comments on commit 815adc4

Please sign in to comment.