From f0ed2ce840b3a59b587e8aa398538141a86e9588 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 28 Aug 2012 18:38:58 -0300 Subject: [media] uvcvideo: Set error_idx properly for extended controls API failures When one of the requested controls doesn't exist the error_idx field must reflect that situation. For G_EXT_CTRLS and S_EXT_CTRLS, error_idx must be set to the control count. For TRY_EXT_CTRLS, it must be set to the index of the unexisting control. This issue was found by the v4l2-compliance tool. Signed-off-by: Laurent Pinchart Acked-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/uvc/uvc_v4l2.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'drivers/media/usb/uvc/uvc_v4l2.c') diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index f00db3060e0e..e5817b953938 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -591,8 +591,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ret = uvc_ctrl_get(chain, &xctrl); uvc_ctrl_rollback(handle); - if (ret >= 0) - ctrl->value = xctrl.value; + if (ret < 0) + return ret == -ENOENT ? -EINVAL : ret; + + ctrl->value = xctrl.value; break; } @@ -612,7 +614,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ret = uvc_ctrl_set(chain, &xctrl); if (ret < 0) { uvc_ctrl_rollback(handle); - return ret; + return ret == -ENOENT ? -EINVAL : ret; } ret = uvc_ctrl_commit(handle, &xctrl, 1); if (ret == 0) @@ -637,8 +639,9 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ret = uvc_ctrl_get(chain, ctrl); if (ret < 0) { uvc_ctrl_rollback(handle); - ctrls->error_idx = i; - return ret; + ctrls->error_idx = ret == -ENOENT + ? ctrls->count : i; + return ret == -ENOENT ? -EINVAL : ret; } } ctrls->error_idx = 0; @@ -661,8 +664,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ret = uvc_ctrl_set(chain, ctrl); if (ret < 0) { uvc_ctrl_rollback(handle); - ctrls->error_idx = i; - return ret; + ctrls->error_idx = (ret == -ENOENT && + cmd == VIDIOC_S_EXT_CTRLS) + ? ctrls->count : i; + return ret == -ENOENT ? -EINVAL : ret; } } -- cgit v1.2.3 From 815adc465de9c8cd1967d0d9d538ed30925423a0 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 28 Aug 2012 18:38:58 -0300 Subject: [media] uvcvideo: Don't fail when an unsupported format is requested Return the default format in that case. This issue was found by the v4l2-compliance tool. Signed-off-by: Laurent Pinchart Acked-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/uvc/uvc_v4l2.c | 11 ++++++----- drivers/media/usb/uvc/uvc_video.c | 1 + drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'drivers/media/usb/uvc/uvc_v4l2.c') diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index e5817b953938..3bd93736a82a 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -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 diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 57c3076a4625..3394c3432011 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -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; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index af216ec45e39..d83b6baf703a 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -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 -- cgit v1.2.3 From f887e99ae2210e23c9726b6f146938a84f6acc47 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 28 Aug 2012 18:38:58 -0300 Subject: [media] uvcvideo: Set device_caps in VIDIOC_QUERYCAP Set the capabilities field to global capabilities, and the device_caps field to the video node capabilities. This issue was found by the v4l2-compliance tool. Signed-off-by: Laurent Pinchart Acked-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/uvc/uvc_driver.c | 5 +++++ drivers/media/usb/uvc/uvc_v4l2.c | 10 ++++++---- drivers/media/usb/uvc/uvcvideo.h | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'drivers/media/usb/uvc/uvc_v4l2.c') diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 5967081747ce..ae24f7d70b03 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1741,6 +1741,11 @@ static int uvc_register_video(struct uvc_device *dev, return ret; } + if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) + stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE; + else + stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT; + atomic_inc(&dev->nstreams); return 0; } diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 3bd93736a82a..b1aa55fb8984 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -565,12 +565,14 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) usb_make_path(stream->dev->udev, cap->bus_info, sizeof(cap->bus_info)); cap->version = LINUX_VERSION_CODE; + cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING + | chain->caps; if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) - cap->capabilities = V4L2_CAP_VIDEO_CAPTURE - | V4L2_CAP_STREAMING; + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE + | V4L2_CAP_STREAMING; else - cap->capabilities = V4L2_CAP_VIDEO_OUTPUT - | V4L2_CAP_STREAMING; + cap->device_caps = V4L2_CAP_VIDEO_OUTPUT + | V4L2_CAP_STREAMING; break; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index d83b6baf703a..a6c561f631a0 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -371,6 +371,8 @@ struct uvc_video_chain { struct uvc_entity *selector; /* Selector unit */ struct mutex ctrl_mutex; /* Protects ctrl.info */ + + u32 caps; /* V4L2 chain-wide caps */ }; struct uvc_stats_frame { -- cgit v1.2.3 From 69d11262a3ff4c07e071523e6768ec15ccc147c1 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 28 Aug 2012 18:38:58 -0300 Subject: [media] uvcvideo: Return -ENOTTY for unsupported ioctls The proper error code is -ENOTTY instead of -EINVAL. This issue was found by the v4l2-compliance tool. Signed-off-by: Laurent Pinchart Acked-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/uvc/uvc_v4l2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/media/usb/uvc/uvc_v4l2.c') diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index b1aa55fb8984..bf9d07393139 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -932,7 +932,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_G_CROP: case VIDIOC_S_CROP: - return -EINVAL; + return -ENOTTY; /* Buffers & streaming */ case VIDIOC_REQBUFS: @@ -1038,7 +1038,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_ENUMOUTPUT: uvc_trace(UVC_TRACE_IOCTL, "Unsupported ioctl 0x%08x\n", cmd); - return -EINVAL; + return -ENOTTY; case UVCIOC_CTRL_MAP: return uvc_ioctl_ctrl_map(chain, arg); -- cgit v1.2.3 From 0550513c7a559b4933c5e1d47fbd15d15f6078d5 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 28 Aug 2012 20:29:56 -0300 Subject: [media] uvcvideo: Add VIDIOC_[GS]_PRIORITY support Signed-off-by: Laurent Pinchart Acked-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/uvc/uvc_driver.c | 3 +++ drivers/media/usb/uvc/uvc_v4l2.c | 45 ++++++++++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 49 insertions(+) (limited to 'drivers/media/usb/uvc/uvc_v4l2.c') diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index ae24f7d70b03..22f14d286fbb 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1562,6 +1562,7 @@ static int uvc_scan_device(struct uvc_device *dev) INIT_LIST_HEAD(&chain->entities); mutex_init(&chain->ctrl_mutex); chain->dev = dev; + v4l2_prio_init(&chain->prio); if (uvc_scan_chain(chain, term) < 0) { kfree(chain); @@ -1722,6 +1723,8 @@ static int uvc_register_video(struct uvc_device *dev, vdev->v4l2_dev = &dev->vdev; vdev->fops = &uvc_fops; vdev->release = uvc_release; + vdev->prio = &stream->chain->prio; + set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags); if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) vdev->vfl_dir = VFL_DIR_TX; strlcpy(vdev->name, dev->name, sizeof vdev->name); diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index bf9d07393139..8e056046bc20 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -576,6 +576,19 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) break; } + /* Priority */ + case VIDIOC_G_PRIORITY: + *(u32 *)arg = v4l2_prio_max(vdev->prio); + break; + + case VIDIOC_S_PRIORITY: + ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); + if (ret < 0) + return ret; + + return v4l2_prio_change(vdev->prio, &handle->vfh.prio, + *(u32 *)arg); + /* Get, Set & Query control */ case VIDIOC_QUERYCTRL: return uvc_query_v4l2_ctrl(chain, arg); @@ -606,6 +619,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) struct v4l2_control *ctrl = arg; struct v4l2_ext_control xctrl; + ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); + if (ret < 0) + return ret; + memset(&xctrl, 0, sizeof xctrl); xctrl.id = ctrl->id; xctrl.value = ctrl->value; @@ -653,6 +670,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) } case VIDIOC_S_EXT_CTRLS: + ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); + if (ret < 0) + return ret; + /* Fall through */ case VIDIOC_TRY_EXT_CTRLS: { struct v4l2_ext_controls *ctrls = arg; @@ -747,6 +768,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) { u32 input = *(u32 *)arg + 1; + ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); + if (ret < 0) + return ret; + if ((ret = uvc_acquire_privileges(handle)) < 0) return ret; @@ -800,6 +825,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) } case VIDIOC_S_FMT: + ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); + if (ret < 0) + return ret; + if ((ret = uvc_acquire_privileges(handle)) < 0) return ret; @@ -902,6 +931,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) return uvc_v4l2_get_streamparm(stream, arg); case VIDIOC_S_PARM: + ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); + if (ret < 0) + return ret; + if ((ret = uvc_acquire_privileges(handle)) < 0) return ret; @@ -936,6 +969,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) /* Buffers & streaming */ case VIDIOC_REQBUFS: + ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); + if (ret < 0) + return ret; + if ((ret = uvc_acquire_privileges(handle)) < 0) return ret; @@ -981,6 +1018,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) if (*type != stream->type) return -EINVAL; + ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); + if (ret < 0) + return ret; + if (!uvc_has_privileges(handle)) return -EBUSY; @@ -999,6 +1040,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) if (*type != stream->type) return -EINVAL; + ret = v4l2_prio_check(vdev->prio, handle->vfh.prio); + if (ret < 0) + return ret; + if (!uvc_has_privileges(handle)) return -EBUSY; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index a6c561f631a0..006ae274d22e 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -372,6 +372,7 @@ struct uvc_video_chain { struct mutex ctrl_mutex; /* Protects ctrl.info */ + struct v4l2_prio_state prio; /* V4L2 priority state */ u32 caps; /* V4L2 chain-wide caps */ }; -- cgit v1.2.3 From 9c016d61097cc39427a2f5025bdd97ac633d26a6 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sun, 23 Dec 2012 14:39:32 +0100 Subject: Partly revert "[media] uvcvideo: Set error_idx properly for extended controls API failures" Commit f0ed2ce840b3 ("[media] uvcvideo: Set error_idx properly for extended controls API failures") causes user space to behave incorrectly on one of my test machines (there is no sound under KDE 4.9.4 using pulseaudio and there is a knotify4 process occupying one of the CPU cores 100% of the time). Reverting that commit entirely fixes the problem for me. However, commit f0ed2ce840b3 appears to do more than it follows from its changelog, because the changelog only says about the changes related to ctrls->error_idx, while the commit additionally changes error codes returned by various functions in uvc_ctrl.c and uvc_v4l2.c. It turns out that the changes of the returned error codes confuse the user spce, so it is sufficient to revert the part of commit f0ed2ce840b3 not mentioned in its changelog to fix the problem. [ 'ENOENT' is not a valid error return from an ioctl to begin with, and I don't understand how anybody ever even thought it would be. - Linus ] Signed-off-by: Rafael J. Wysocki Cc: Laurent Pinchart Cc: Mauro Carvalho Chehab Cc: Hans Verkuil Signed-off-by: Linus Torvalds --- drivers/media/usb/uvc/uvc_ctrl.c | 19 ++++++++----------- drivers/media/usb/uvc/uvc_v4l2.c | 12 +++++------- 2 files changed, 13 insertions(+), 18 deletions(-) (limited to 'drivers/media/usb/uvc/uvc_v4l2.c') diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 516a5b188ea5..2bb7613ddebb 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1061,7 +1061,7 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping); if (ctrl == NULL) { - ret = -ENOENT; + ret = -EINVAL; goto done; } @@ -1099,13 +1099,12 @@ int uvc_query_v4l2_menu(struct uvc_video_chain *chain, return -ERESTARTSYS; ctrl = uvc_find_control(chain, query_menu->id, &mapping); - if (ctrl == NULL) { - ret = -ENOENT; + if (ctrl == NULL || mapping->v4l2_type != V4L2_CTRL_TYPE_MENU) { + ret = -EINVAL; goto done; } - if (mapping->v4l2_type != V4L2_CTRL_TYPE_MENU || - query_menu->index >= mapping->menu_count) { + if (query_menu->index >= mapping->menu_count) { ret = -EINVAL; goto done; } @@ -1264,7 +1263,7 @@ static int uvc_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems) ctrl = uvc_find_control(handle->chain, sev->id, &mapping); if (ctrl == NULL) { - ret = -ENOENT; + ret = -EINVAL; goto done; } @@ -1415,7 +1414,7 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, ctrl = uvc_find_control(chain, xctrl->id, &mapping); if (ctrl == NULL) - return -ENOENT; + return -EINVAL; return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value); } @@ -1432,10 +1431,8 @@ int uvc_ctrl_set(struct uvc_video_chain *chain, int ret; ctrl = uvc_find_control(chain, xctrl->id, &mapping); - if (ctrl == NULL) - return -ENOENT; - if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) - return -EACCES; + if (ctrl == NULL || (ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) == 0) + return -EINVAL; /* Clamp out of range values. */ switch (mapping->v4l2_type) { diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 8e056046bc20..f2ee8c6b0d8d 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -607,10 +607,8 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ret = uvc_ctrl_get(chain, &xctrl); uvc_ctrl_rollback(handle); - if (ret < 0) - return ret == -ENOENT ? -EINVAL : ret; - - ctrl->value = xctrl.value; + if (ret >= 0) + ctrl->value = xctrl.value; break; } @@ -634,7 +632,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ret = uvc_ctrl_set(chain, &xctrl); if (ret < 0) { uvc_ctrl_rollback(handle); - return ret == -ENOENT ? -EINVAL : ret; + return ret; } ret = uvc_ctrl_commit(handle, &xctrl, 1); if (ret == 0) @@ -661,7 +659,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) uvc_ctrl_rollback(handle); ctrls->error_idx = ret == -ENOENT ? ctrls->count : i; - return ret == -ENOENT ? -EINVAL : ret; + return ret; } } ctrls->error_idx = 0; @@ -691,7 +689,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ctrls->error_idx = (ret == -ENOENT && cmd == VIDIOC_S_EXT_CTRLS) ? ctrls->count : i; - return ret == -ENOENT ? -EINVAL : ret; + return ret; } } -- cgit v1.2.3 From 29005c09f41d459c458eb8761a54703b56afb16a Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 11 Jan 2013 09:32:04 -0300 Subject: [media] uvcvideo: Cleanup leftovers of partial revert Commit ba68c8530a263dc4de440fa10bb20a1c5b9d4ff5 (Partly revert "[media] uvcvideo: Set error_idx properly for extended controls API failures") missed two modifications. Clean them up. Signed-off-by: Laurent Pinchart Acked-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/uvc/uvc_v4l2.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'drivers/media/usb/uvc/uvc_v4l2.c') diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index f2ee8c6b0d8d..5eb89894f90b 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -657,8 +657,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ret = uvc_ctrl_get(chain, ctrl); if (ret < 0) { uvc_ctrl_rollback(handle); - ctrls->error_idx = ret == -ENOENT - ? ctrls->count : i; + ctrls->error_idx = i; return ret; } } @@ -686,9 +685,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ret = uvc_ctrl_set(chain, ctrl); if (ret < 0) { uvc_ctrl_rollback(handle); - ctrls->error_idx = (ret == -ENOENT && - cmd == VIDIOC_S_EXT_CTRLS) - ? ctrls->count : i; + ctrls->error_idx = i; return ret; } } -- cgit v1.2.3 From 68d6f84ba0c47e658beff3a4bf0c43acee4b4690 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 11 Jan 2013 09:42:00 -0300 Subject: [media] uvcvideo: Set error_idx properly for S_EXT_CTRLS failures The uvc_set_ctrl() calls don't write to the hardware. A failure at that point thus leaves the device in a clean state, with no control modified. Set the error_idx field to the count value to reflect that, as per the V4L2 specification. TRY_EXT_CTRLS is unchanged and the error_idx field must always be set to the failed control index in that case. Signed-off-by: Laurent Pinchart Acked-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/uvc/uvc_v4l2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/media/usb/uvc/uvc_v4l2.c') diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 5eb89894f90b..68d59b527492 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -685,7 +685,8 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) ret = uvc_ctrl_set(chain, ctrl); if (ret < 0) { uvc_ctrl_rollback(handle); - ctrls->error_idx = i; + ctrls->error_idx = cmd == VIDIOC_S_EXT_CTRLS + ? ctrls->count : i; return ret; } } -- cgit v1.2.3