Skip to content

Commit e0360e0

Browse files
ribaldagregkh
authored andcommitted
media: uvcvideo: Refactor iterators
[ Upstream commit 64627da ] 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]> Stable-dep-of: d9fecd0 ("media: uvcvideo: Only save async fh if success") Signed-off-by: Sasha Levin <[email protected]>
1 parent 972f412 commit e0360e0

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
@@ -1730,16 +1730,18 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
17301730
list_for_each_entry(entity, &chain->entities, chain) {
17311731
ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback,
17321732
&err_ctrl);
1733-
if (ret < 0)
1733+
if (ret < 0) {
1734+
if (ctrls)
1735+
ctrls->error_idx =
1736+
uvc_ctrl_find_ctrl_idx(entity, ctrls,
1737+
err_ctrl);
17341738
goto done;
1739+
}
17351740
}
17361741

17371742
if (!rollback)
17381743
uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count);
17391744
done:
1740-
if (ret < 0 && ctrls)
1741-
ctrls->error_idx = uvc_ctrl_find_ctrl_idx(entity, ctrls,
1742-
err_ctrl);
17431745
mutex_unlock(&chain->ctrl_mutex);
17441746
return ret;
17451747
}
@@ -2037,7 +2039,7 @@ static int uvc_ctrl_init_xu_ctrl(struct uvc_device *dev,
20372039
int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
20382040
struct uvc_xu_control_query *xqry)
20392041
{
2040-
struct uvc_entity *entity;
2042+
struct uvc_entity *entity, *iter;
20412043
struct uvc_control *ctrl;
20422044
unsigned int i;
20432045
bool found;
@@ -2047,16 +2049,16 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
20472049
int ret;
20482050

20492051
/* Find the extension unit. */
2050-
found = false;
2051-
list_for_each_entry(entity, &chain->entities, chain) {
2052-
if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT &&
2053-
entity->id == xqry->unit) {
2054-
found = true;
2052+
entity = NULL;
2053+
list_for_each_entry(iter, &chain->entities, chain) {
2054+
if (UVC_ENTITY_TYPE(iter) == UVC_VC_EXTENSION_UNIT &&
2055+
iter->id == xqry->unit) {
2056+
entity = iter;
20552057
break;
20562058
}
20572059
}
20582060

2059-
if (!found) {
2061+
if (!entity) {
20602062
uvc_dbg(chain->dev, CONTROL, "Extension unit %u not found\n",
20612063
xqry->unit);
20622064
return -ENOENT;

0 commit comments

Comments
 (0)