Skip to content

Commit 64627da

Browse files
ribaldaHans Verkuil
authored andcommitted
media: uvcvideo: Refactor iterators
Avoid using the iterators after the list_for_each() constructs. This patch should be a NOP, but makes cocci, happier: drivers/media/usb/uvc/uvc_ctrl.c:1861:44-50: ERROR: invalid reference to the index variable of the iterator on line 1850 drivers/media/usb/uvc/uvc_ctrl.c:2195:17-23: ERROR: invalid reference to the index variable of the iterator on line 2179 Reviewed-by: Sergey Senozhatsky <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Signed-off-by: Ricardo Ribalda <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 2c7f7a3 commit 64627da

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

drivers/media/usb/uvc/uvc_ctrl.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,16 +1850,18 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
18501850
list_for_each_entry(entity, &chain->entities, chain) {
18511851
ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback,
18521852
&err_ctrl);
1853-
if (ret < 0)
1853+
if (ret < 0) {
1854+
if (ctrls)
1855+
ctrls->error_idx =
1856+
uvc_ctrl_find_ctrl_idx(entity, ctrls,
1857+
err_ctrl);
18541858
goto done;
1859+
}
18551860
}
18561861

18571862
if (!rollback)
18581863
uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count);
18591864
done:
1860-
if (ret < 0 && ctrls)
1861-
ctrls->error_idx = uvc_ctrl_find_ctrl_idx(entity, ctrls,
1862-
err_ctrl);
18631865
mutex_unlock(&chain->ctrl_mutex);
18641866
return ret;
18651867
}
@@ -2165,7 +2167,7 @@ static int uvc_ctrl_init_xu_ctrl(struct uvc_device *dev,
21652167
int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
21662168
struct uvc_xu_control_query *xqry)
21672169
{
2168-
struct uvc_entity *entity;
2170+
struct uvc_entity *entity, *iter;
21692171
struct uvc_control *ctrl;
21702172
unsigned int i;
21712173
bool found;
@@ -2175,16 +2177,16 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
21752177
int ret;
21762178

21772179
/* Find the extension unit. */
2178-
found = false;
2179-
list_for_each_entry(entity, &chain->entities, chain) {
2180-
if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT &&
2181-
entity->id == xqry->unit) {
2182-
found = true;
2180+
entity = NULL;
2181+
list_for_each_entry(iter, &chain->entities, chain) {
2182+
if (UVC_ENTITY_TYPE(iter) == UVC_VC_EXTENSION_UNIT &&
2183+
iter->id == xqry->unit) {
2184+
entity = iter;
21832185
break;
21842186
}
21852187
}
21862188

2187-
if (!found) {
2189+
if (!entity) {
21882190
uvc_dbg(chain->dev, CONTROL, "Extension unit %u not found\n",
21892191
xqry->unit);
21902192
return -ENOENT;

0 commit comments

Comments
 (0)