Commit cb385548 authored by Ricardo Ribalda's avatar Ricardo Ribalda Committed by Hans Verkuil

media: v4l2-ctrls-core.c: Do not use iterator outside loop

Simplify a bit the code introducing a new variable for iterating through
the control list.

It also makes smatch happy:

drivers/media/v4l2-core/v4l2-ctrls-api.c:1091 v4l2_query_ext_ctrl() warn: iterator used outside loop: 'ref'
Signed-off-by: default avatarRicardo Ribalda <ribalda@chromium.org>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
[hverkuil: fix tiny whitespace issue in 'pos  = ref': use just one space]
parent e932a85d
...@@ -1052,35 +1052,40 @@ int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctr ...@@ -1052,35 +1052,40 @@ int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctr
if (id >= node2id(hdl->ctrl_refs.prev)) { if (id >= node2id(hdl->ctrl_refs.prev)) {
ref = NULL; /* Yes, so there is no next control */ ref = NULL; /* Yes, so there is no next control */
} else if (ref) { } else if (ref) {
struct v4l2_ctrl_ref *pos = ref;
/* /*
* We found a control with the given ID, so just get * We found a control with the given ID, so just get
* the next valid one in the list. * the next valid one in the list.
*/ */
list_for_each_entry_continue(ref, &hdl->ctrl_refs, node) { ref = NULL;
is_compound = ref->ctrl->is_array || list_for_each_entry_continue(pos, &hdl->ctrl_refs, node) {
ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; is_compound = pos->ctrl->is_array ||
if (id < ref->ctrl->id && pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
(is_compound & mask) == match) if (id < pos->ctrl->id &&
(is_compound & mask) == match) {
ref = pos;
break; break;
}
} }
if (&ref->node == &hdl->ctrl_refs)
ref = NULL;
} else { } else {
struct v4l2_ctrl_ref *pos;
/* /*
* No control with the given ID exists, so start * No control with the given ID exists, so start
* searching for the next largest ID. We know there * searching for the next largest ID. We know there
* is one, otherwise the first 'if' above would have * is one, otherwise the first 'if' above would have
* been true. * been true.
*/ */
list_for_each_entry(ref, &hdl->ctrl_refs, node) { list_for_each_entry(pos, &hdl->ctrl_refs, node) {
is_compound = ref->ctrl->is_array || is_compound = pos->ctrl->is_array ||
ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
if (id < ref->ctrl->id && if (id < pos->ctrl->id &&
(is_compound & mask) == match) (is_compound & mask) == match) {
ref = pos;
break; break;
}
} }
if (&ref->node == &hdl->ctrl_refs)
ref = NULL;
} }
} }
mutex_unlock(hdl->lock); mutex_unlock(hdl->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment