* [PATCH] media: uvc: Fix list_for_each() checking
@ 2020-06-22 14:10 Dan Carpenter
0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2020-06-22 14:10 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, kernel-janitors
If the UVC_QUIRK_IGNORE_SELECTOR_UNIT flag is set, then there is a
problem that the code uses "iterm" after the end of the
list_for_each_entry() loop. It should only be used when the
UVC_ENTITY_IS_ITERM() condition is true and we break from the loop.
Fixes: d5e90b7a6cd1 ("[media] uvcvideo: Move to video_ioctl2")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Please review this one extra carefully because it's from static analysis
and I'm not 100% sure it's correct.
drivers/media/usb/uvc/uvc_v4l2.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 0335e69b70ab..945862afa829 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -827,28 +827,32 @@ static int uvc_ioctl_enum_input(struct file *file, void *fh,
const struct uvc_entity *selector = chain->selector;
struct uvc_entity *iterm = NULL;
u32 index = input->index;
- int pin = 0;
+ bool found = false;
+ int pin;
if (selector == NULL ||
(chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
if (index != 0)
return -EINVAL;
list_for_each_entry(iterm, &chain->entities, chain) {
- if (UVC_ENTITY_IS_ITERM(iterm))
+ if (UVC_ENTITY_IS_ITERM(iterm)) {
+ found = true;
break;
+ }
}
- pin = iterm->id;
} else if (index < selector->bNrInPins) {
pin = selector->baSourceID[index];
list_for_each_entry(iterm, &chain->entities, chain) {
if (!UVC_ENTITY_IS_ITERM(iterm))
continue;
- if (iterm->id == pin)
+ if (iterm->id == pin) {
+ found = true;
break;
+ }
}
}
- if (iterm == NULL || iterm->id != pin)
+ if (!found)
return -EINVAL;
memset(input, 0, sizeof(*input));
--
2.27.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-06-22 14:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22 14:10 [PATCH] media: uvc: Fix list_for_each() checking Dan Carpenter
Unnamed repository; edit this file 'description' to name the repository.
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://archive.lwn.net:8080/linux-media/0 linux-media/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 linux-media linux-media/ http://archive.lwn.net:8080/linux-media \
linux-media@vger.kernel.org lwn-linux-media@archive.lwn.net
public-inbox-index linux-media
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://archive.lwn.net/lwn.kernel.linux-media
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git