Skip to content

Commit

Permalink
[media] uvcvideo: Return -ERANGE when userspace sets an unsupported m…
Browse files Browse the repository at this point in the history
…enu entry

Instead of passing the value down to the device and getting an error
back (or worse, crashing the firmware), return -ERANGE when the
requested menu entry is not supported.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Laurent Pinchart authored and Mauro Carvalho Chehab committed May 20, 2011
1 parent fc2d573 commit f411f10
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions drivers/media/video/uvc/uvc_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,23 @@ int uvc_ctrl_set(struct uvc_video_chain *chain,
if (xctrl->value < 0 || xctrl->value >= mapping->menu_count)
return -ERANGE;
value = mapping->menu_info[xctrl->value].value;

/* Valid menu indices are reported by the GET_RES request for
* UVC controls that support it.
*/
if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) {
if (!ctrl->cached) {
ret = uvc_ctrl_populate_cache(chain, ctrl);
if (ret < 0)
return ret;
}

step = mapping->get(mapping, UVC_GET_RES,
uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
if (!(step & value))
return -ERANGE;
}

break;

default:
Expand Down

0 comments on commit f411f10

Please sign in to comment.