[media] v4l2-ctrls: fix rounding calculation
authorHans Verkuil <hverkuil@xs4all.nl>
Sat, 26 Jul 2014 16:02:59 +0000 (13:02 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Sun, 27 Jul 2014 20:51:37 +0000 (17:51 -0300)
commit9c9cb1fad865b3d9e9c4d7bbfbd20ca04cdc79b3
treea5c73516fb21deb7d7fc60dd7d841d2900d106bc
parent5b8c8d41919ac4985dfacd31a860e4f00f52d3a6
[media] v4l2-ctrls: fix rounding calculation

Commit 958c7c7e65 ("[media] v4l2-ctrls: fix corner case in round-to-range code") broke
controls that use a negative range.

The cause was a s32/u32 mixup: ctrl->step is unsigned while all others are signed. So
the result type of the expression '(ctrl)->maximum - ((ctrl)->step / 2)' became unsigned,
making 'val >= (ctrl)->maximum - ((ctrl)->step / 2)' true, since '((u32)-128) > 128'
(if val = -128, maximum = 128 and step = 1).

So carefully cast (step / 2) to s32.

There was one cast of step to s32 where it should have been u32 because both offset and
step are unsigned, so casting to signed makes no sense there. You do need a cast to u32
there, because otherwise architectures that have no 64-bit division start complaining
(step is a u64).

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reported-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/v4l2-core/v4l2-ctrls.c
This page took 0.025519 seconds and 5 git commands to generate.