All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [media] tvp686x: Don't go past array
@ 2016-04-23  9:23 Mauro Carvalho Chehab
  2016-04-23  9:51 ` Hans Verkuil
  2016-04-25 11:36 ` Hans Verkuil
  0 siblings, 2 replies; 8+ messages in thread
From: Mauro Carvalho Chehab @ 2016-04-23  9:23 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Ezequiel Garcia

Depending on the compiler version, currently it produces the
following warnings:
	tw686x-video.c: In function 'tw686x_video_init':
	tw686x-video.c:65:543: warning: array subscript is above array bounds [-Warray-bounds]

This is actually bogus with the current code, as it currently
hardcodes the framerate to 30 frames/sec, however a potential
use after the array size could happen when the driver adds support
for setting the framerate. So, fix it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/pci/tw686x/tw686x-video.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/tw686x/tw686x-video.c b/drivers/media/pci/tw686x/tw686x-video.c
index 118e9fac9f28..1ff59084ce08 100644
--- a/drivers/media/pci/tw686x/tw686x-video.c
+++ b/drivers/media/pci/tw686x/tw686x-video.c
@@ -61,8 +61,19 @@ static unsigned int tw686x_fields_map(v4l2_std_id std, unsigned int fps)
 		   8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 0, 0
 	};
 
-	unsigned int i =
-		(std & V4L2_STD_625_50) ? std_625_50[fps] : std_525_60[fps];
+	unsigned int i;
+
+	if (std & V4L2_STD_625_50) {
+		if (unlikely(i > ARRAY_SIZE(std_625_50)))
+			i = 14;		/* 25 fps */
+		else
+			i = std_625_50[fps];
+	} else {
+		if (unlikely(i > ARRAY_SIZE(std_525_60)))
+			i = 0;		/* 30 fps */
+		else
+			i = std_525_60[fps];
+	}
 
 	return map[i];
 }
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-04-25 16:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-23  9:23 [PATCH] [media] tvp686x: Don't go past array Mauro Carvalho Chehab
2016-04-23  9:51 ` Hans Verkuil
2016-04-25 11:36 ` Hans Verkuil
2016-04-25 12:40   ` Mauro Carvalho Chehab
2016-04-25 12:42     ` Hans Verkuil
2016-04-25 12:52       ` Mauro Carvalho Chehab
2016-04-25 15:26     ` Ezequiel Garcia
2016-04-25 16:10       ` Mauro Carvalho Chehab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.