aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video
diff options
context:
space:
mode:
authorGuennadi Liakhovetski <g.liakhovetski@gmx.de>2012-05-08 10:46:44 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-05-15 15:14:01 -0400
commit67e86524b907ed2189f4875cdbe7a5249c71ebb2 (patch)
tree024321e97d066467df8b25fe92d59b6f2d244b9e /drivers/media/video
parentfc13baff743cf9fa49035974471c17378bfe6146 (diff)
[media] V4L: mx2-camera: avoid overflowing 32-bits
In mx2_camera_try_fmt(), when applying i.MX25 restrictions to frame sizes, the height is checked to be <= 0xffff. But later an integer multiplication height * 4 * 0x3ffff is performed, which will overflow even for bounded height values. This patch switches to using 64-bit multiplication and division to avoid overflowing. Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video')
-rw-r--r--drivers/media/video/mx2_camera.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
index ecd83faf9038..ded26b7286fa 100644
--- a/drivers/media/video/mx2_camera.c
+++ b/drivers/media/video/mx2_camera.c
@@ -22,6 +22,7 @@
22#include <linux/gcd.h> 22#include <linux/gcd.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/math64.h>
25#include <linux/mm.h> 26#include <linux/mm.h>
26#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
27#include <linux/time.h> 28#include <linux/time.h>
@@ -1400,8 +1401,8 @@ static int mx2_camera_try_fmt(struct soc_camera_device *icd,
1400 /* Check against the CSIRXCNT limit */ 1401 /* Check against the CSIRXCNT limit */
1401 if (pix->sizeimage > 4 * 0x3ffff) { 1402 if (pix->sizeimage > 4 * 0x3ffff) {
1402 /* Adjust geometry, preserve aspect ratio */ 1403 /* Adjust geometry, preserve aspect ratio */
1403 unsigned int new_height = int_sqrt(4 * 0x3ffff * 1404 unsigned int new_height = int_sqrt(div_u64(0x3ffffULL *
1404 pix->height / pix->bytesperline); 1405 4 * pix->height, pix->bytesperline));
1405 pix->width = new_height * pix->width / pix->height; 1406 pix->width = new_height * pix->width / pix->height;
1406 pix->height = new_height; 1407 pix->height = new_height;
1407 pix->bytesperline = soc_mbus_bytes_per_line(pix->width, 1408 pix->bytesperline = soc_mbus_bytes_per_line(pix->width,