[2.6.22.2 review 27/84] V4L: Add check for valid control ID to v4l2_ctrl_next

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Greg KH
Date: Tuesday, August 7, 2007 - 1:45 pm

From: Hans Verkuil <hverkuil@xs4all.nl>

If v4l2_ctrl_next is called without the V4L2_CTRL_FLAG_NEXT_CTRL then it
should check whether the passed control ID is valid and return 0 if it
isn't. Otherwise a for-loop over the control IDs will never end.

(cherry picked from commit a46c5fbc6912c4e34cb7ded314249b639dc244a6)

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/media/video/v4l2-common.c |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -939,16 +939,25 @@ int v4l2_ctrl_query_menu(struct v4l2_que
    When no more controls are available 0 is returned. */
 u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
 {
-	u32 ctrl_class;
+	u32 ctrl_class = V4L2_CTRL_ID2CLASS(id);
 	const u32 *pctrl;
 
-	/* if no query is desired, then just return the control ID */
-	if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0)
-		return id;
 	if (ctrl_classes == NULL)
 		return 0;
+
+	/* if no query is desired, then check if the ID is part of ctrl_classes */
+	if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0) {
+		/* find class */
+		while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) != ctrl_class)
+			ctrl_classes++;
+		if (*ctrl_classes == NULL)
+			return 0;
+		pctrl = *ctrl_classes;
+		/* find control ID */
+		while (*pctrl && *pctrl != id) pctrl++;
+		return *pctrl ? id : 0;
+	}
 	id &= V4L2_CTRL_ID_MASK;
-	ctrl_class = V4L2_CTRL_ID2CLASS(id);
 	id++;	/* select next control */
 	/* find first class that matches (or is greater than) the class of
 	   the ID */

-- 
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[2.6.22.2 review 03/84] Fix TC deadlock., Greg KH, (Tue Aug 7, 1:42 pm)
[2.6.22.2 review 04/84] Fix IPCOMP crashes., Greg KH, (Tue Aug 7, 1:42 pm)
[2.6.22.2 review 09/84] Fix rfkill IRQ flags., Greg KH, (Tue Aug 7, 1:43 pm)
[2.6.22.2 review 14/84] Netpoll leak, Greg KH, (Tue Aug 7, 1:44 pm)
[2.6.22.2 review 17/84] Fix sparc32 memset(), Greg KH, (Tue Aug 7, 1:44 pm)
[2.6.22.2 review 19/84] Fix TCP IPV6 MD5 bug., Greg KH, (Tue Aug 7, 1:44 pm)
[2.6.22.2 review 27/84] V4L: Add check for valid control I ..., Greg KH, (Tue Aug 7, 1:45 pm)
[2.6.22.2 review 70/84] dm raid1: fix status, Greg KH, (Tue Aug 7, 1:48 pm)
[2.6.22.2 review 73/84] dm: disable barriers, Greg KH, (Tue Aug 7, 1:49 pm)
Re: [2.6.22.2 review 09/84] Fix rfkill IRQ flags., Jan Engelhardt, (Tue Aug 7, 2:37 pm)
Re: [2.6.22.2 review 09/84] Fix rfkill IRQ flags., Alexey Dobriyan, (Wed Aug 8, 10:24 pm)