aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Gross <andy.gross@ti.com>2012-04-30 12:23:15 -0500
committerZiyann <jaraidaniel@gmail.com>2014-10-01 12:58:34 +0200
commit9b2d0601435c14add3ee1be73a7d9e3451cee583 (patch)
tree48850794471e3d1bb7a6227687b67e8567949b22
parentddc6bd7c2d35549b3646550766a7180924e83a75 (diff)
downloadkernel_samsung_tuna-9b2d0601435c14add3ee1be73a7d9e3451cee583.zip
kernel_samsung_tuna-9b2d0601435c14add3ee1be73a7d9e3451cee583.tar.gz
kernel_samsung_tuna-9b2d0601435c14add3ee1be73a7d9e3451cee583.tar.bz2
OMAP: TILER: validate input width and height
Add validation of input width and height to ensure that it does not exceed maximum pixel width and height for the specific format. Validate maximum length for 1D allocations. Change-Id: I64b00f93a312ae715a040da28a0b0fe663afa9d8 Signed-off-by: Andy Gross <andy.gross@ti.com>
-rw-r--r--drivers/media/video/tiler/tiler-main.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/drivers/media/video/tiler/tiler-main.c b/drivers/media/video/tiler/tiler-main.c
index 7fc601e..85b657b 100644
--- a/drivers/media/video/tiler/tiler-main.c
+++ b/drivers/media/video/tiler/tiler-main.c
@@ -465,17 +465,24 @@ static s32 __analize_area(enum tiler_fmt fmt, u32 width, u32 height,
/* slot width, height, and row size */
u32 slot_row, min_align;
- const struct tiler_geom *g;
+ const struct tiler_geom *g = tiler.geom(fmt);
- /* width and height must be positive */
- if (!width || !height)
+ /* width and height must be non-zero, fmt must be valid */
+ if (!width || !height || !g)
return -EINVAL;
- /* validate tiler format */
- if ((fmt < TILFMT_8BIT) || (fmt > TILFMT_PAGE))
- return -EINVAL;
+ /* Note: Some values have been validated prior to calling this function
+ alignment is always <= PAGE_SIZE
+ offs is always < PAGE_SIZE
+ This is a requirement due to some u32->u16 conversions and avoids
+ having to worry about overflow while doing calculations
+ */
if (fmt == TILFMT_PAGE) {
+ /* check for invalid allocation size, width > container size */
+ if (width > (PAGE_SIZE * tiler.width * tiler.height))
+ return -ENOMEM;
+
/* adjust size to accomodate offset, only do page alignment */
*align = PAGE_SIZE;
*remainder = *offs & ~PAGE_MASK; /* calculate remainder */
@@ -484,17 +491,15 @@ static s32 __analize_area(enum tiler_fmt fmt, u32 width, u32 height,
/* for 1D area keep the height (1), width is in tiler slots */
*x_area = DIV_ROUND_UP(width , tiler.page);
*y_area = *band = 1;
-
- if (*x_area * *y_area > tiler.width * tiler.height)
- return -ENOMEM;
return 0;
}
*remainder = 0;
- /* format must be valid */
- g = tiler.geom(fmt);
- if (!g)
+ /* validate against max width and height values to
+ guard against overflow */
+ if (width > (g->slot_w * tiler.width) ||
+ height > (g->slot_h * tiler.height))
return -EINVAL;
/* get the # of bytes per row in 1 slot */