Skip to content

Commit

Permalink
[media] uvcvideo: Fix control value clamping for unsigned integer con…
Browse files Browse the repository at this point in the history
…trols

V4L2 integer controls are stored in signed 32-bit values. However, UVC
controls can be either signed or unsigned. Take the UVC control
signedness into account when clamping the control value to the min-max
range.

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 Nov 28, 2012
1 parent 8be8ec6 commit 64ae995
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/media/usb/uvc/uvc_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1455,8 +1455,12 @@ int uvc_ctrl_set(struct uvc_video_chain *chain,
if (step == 0)
step = 1;

xctrl->value = min + (xctrl->value - min + step/2) / step * step;
xctrl->value = clamp(xctrl->value, min, max);
xctrl->value = min + ((u32)(xctrl->value - min) + step / 2)
/ step * step;
if (mapping->data_type == UVC_CTRL_DATA_TYPE_SIGNED)
xctrl->value = clamp(xctrl->value, min, max);
else
xctrl->value = clamp_t(u32, xctrl->value, min, max);
value = xctrl->value;
break;

Expand Down

0 comments on commit 64ae995

Please sign in to comment.