Skip to content

Commit 96d06ba

Browse files
dwlsalmeidagregkh
authored andcommitted
media: uvcvideo: Fix dereference of out-of-bound list iterator
[ Upstream commit f875bcc ] Fixes the following coccinelle report: drivers/media/usb/uvc/uvc_ctrl.c:1860:5-11: ERROR: invalid reference to the index variable of the iterator on line 1854 by adding a boolean variable to check if the loop has found the Found using - Coccinelle (http://coccinelle.lip6.fr) [Replace cursor variable with bool found] Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 26a1c2d commit 96d06ba

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

drivers/media/usb/uvc/uvc_ctrl.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,30 +1848,35 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
18481848
{
18491849
struct uvc_entity *entity;
18501850
struct uvc_control *ctrl;
1851-
unsigned int i, found = 0;
1851+
unsigned int i;
1852+
bool found;
18521853
u32 reqflags;
18531854
u16 size;
18541855
u8 *data = NULL;
18551856
int ret;
18561857

18571858
/* Find the extension unit. */
1859+
found = false;
18581860
list_for_each_entry(entity, &chain->entities, chain) {
18591861
if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT &&
1860-
entity->id == xqry->unit)
1862+
entity->id == xqry->unit) {
1863+
found = true;
18611864
break;
1865+
}
18621866
}
18631867

1864-
if (entity->id != xqry->unit) {
1868+
if (!found) {
18651869
uvc_trace(UVC_TRACE_CONTROL, "Extension unit %u not found.\n",
18661870
xqry->unit);
18671871
return -ENOENT;
18681872
}
18691873

18701874
/* Find the control and perform delayed initialization if needed. */
1875+
found = false;
18711876
for (i = 0; i < entity->ncontrols; ++i) {
18721877
ctrl = &entity->controls[i];
18731878
if (ctrl->index == xqry->selector - 1) {
1874-
found = 1;
1879+
found = true;
18751880
break;
18761881
}
18771882
}

0 commit comments

Comments
 (0)