Previous fix in #2547 altered id before they were handed off to
callbacks and v4l2 wont strip its own flags from ids resulting in
invalid ids in the ioctl.
Instead add cleanup section and jump all branches there before looping.
(Jim edit: I'm changing this entire function so that it isn't horrible.)
v4l2_ioctl will clear the V4L2_CTRL_FLAG_NEXT_CTRL flag resulting in
infinite loops for any driver that reported readonly, disabled, or
volitile controls.
As currently all 64bit Linux platforms are respecting LP64
data model and most 32bit platforms are respecting ILP32, we
don't have to discuss pointer size case by case. LP64 is effective
enough to tell pointer size.
This fixes build for armhf and powerpc.
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>