Skip to content

Commit

Permalink
media: uvcvideo: Use DIV_ROUND_CLOSEST directly to make it readable
Browse files Browse the repository at this point in the history
The kernel.h macro DIV_ROUND_CLOSEST performs the computation (x + d/2)/d
but is perhaps more readable.

Signed-off-by: zhong jiang <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
xiongzhongjiang authored and mchehab committed Nov 27, 2020
1 parent eeb76af commit 7ae5308
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/media/usb/uvc/uvc_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,8 +1608,8 @@ int uvc_ctrl_set(struct uvc_fh *handle,
if (step == 0)
step = 1;

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

0 comments on commit 7ae5308

Please sign in to comment.