[07/11] drivers/media/video/et61x251/et61x251_core.c: improve error handling

Message ID 201004272111.o3RLBPtw019999@imap1.linux-foundation.org (mailing list archive)
State Superseded, archived
Headers

Commit Message

Andrew Morton April 27, 2010, 9:11 p.m. UTC
  From: Dan Carpenter <error27@gmail.com>

The original code doesn't handle the situation where the controller is not
found.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Cc: Luca Risolia <luca.risolia@studio.unibo.it>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/media/video/et61x251/et61x251_core.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Patch

diff -puN drivers/media/video/et61x251/et61x251_core.c~drivers-media-video-et61x251-et61x251_corec-improve-error-handling drivers/media/video/et61x251/et61x251_core.c
--- a/drivers/media/video/et61x251/et61x251_core.c~drivers-media-video-et61x251-et61x251_corec-improve-error-handling
+++ a/drivers/media/video/et61x251/et61x251_core.c
@@ -1713,7 +1713,7 @@  et61x251_vidioc_s_ctrl(struct et61x251_d
 	if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
 		return -EFAULT;
 
-	for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
+	for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) {
 		if (ctrl.id == s->qctrl[i].id) {
 			if (s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)
 				return -EINVAL;
@@ -1723,7 +1723,9 @@  et61x251_vidioc_s_ctrl(struct et61x251_d
 			ctrl.value -= ctrl.value % s->qctrl[i].step;
 			break;
 		}
-
+	}
+	if (i == ARRAY_SIZE(s->qctrl))
+		return -EINVAL;
 	if ((err = s->set_ctrl(cam, &ctrl)))
 		return err;