Skip to content

Commit f0a1015

Browse files
committed
media: uvcvideo: Refactor iterators
jira VULN-53466 cve-pre CVE-2024-58002 commit-author Ricardo Ribalda <[email protected]> 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]> (cherry picked from commit 64627da) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 43304fe commit f0a1015

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
@@ -1692,16 +1692,18 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
16921692
list_for_each_entry(entity, &chain->entities, chain) {
16931693
ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback,
16941694
&err_ctrl);
1695-
if (ret < 0)
1695+
if (ret < 0) {
1696+
if (ctrls)
1697+
ctrls->error_idx =
1698+
uvc_ctrl_find_ctrl_idx(entity, ctrls,
1699+
err_ctrl);
16961700
goto done;
1701+
}
16971702
}
16981703

16991704
if (!rollback)
17001705
uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count);
17011706
done:
1702-
if (ret < 0 && ctrls)
1703-
ctrls->error_idx = uvc_ctrl_find_ctrl_idx(entity, ctrls,
1704-
err_ctrl);
17051707
mutex_unlock(&chain->ctrl_mutex);
17061708
return ret;
17071709
}
@@ -2005,7 +2007,7 @@ static int uvc_ctrl_init_xu_ctrl(struct uvc_device *dev,
20052007
int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
20062008
struct uvc_xu_control_query *xqry)
20072009
{
2008-
struct uvc_entity *entity;
2010+
struct uvc_entity *entity, *iter;
20092011
struct uvc_control *ctrl;
20102012
unsigned int i;
20112013
bool found;
@@ -2015,16 +2017,16 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
20152017
int ret;
20162018

20172019
/* Find the extension unit. */
2018-
found = false;
2019-
list_for_each_entry(entity, &chain->entities, chain) {
2020-
if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT &&
2021-
entity->id == xqry->unit) {
2022-
found = true;
2020+
entity = NULL;
2021+
list_for_each_entry(iter, &chain->entities, chain) {
2022+
if (UVC_ENTITY_TYPE(iter) == UVC_VC_EXTENSION_UNIT &&
2023+
iter->id == xqry->unit) {
2024+
entity = iter;
20232025
break;
20242026
}
20252027
}
20262028

2027-
if (!found) {
2029+
if (!entity) {
20282030
uvc_dbg(chain->dev, CONTROL, "Extension unit %u not found\n",
20292031
xqry->unit);
20302032
return -ENOENT;

0 commit comments

Comments
 (0)