aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2022-05-13 15:14:13 +0100
committerMauro Carvalho Chehab <mchehab@kernel.org>2022-07-08 15:39:07 +0100
commit7dcb3a2f1f1871cc6e18e744d125baaedada3944 (patch)
treece6037cc285c8c5b691901645c1f8a0fc6d9e801
parent6ac98b41b4fb44656ef0ccccee4fda73751eb7bf (diff)
downloadlinux-7dcb3a2f1f1871cc6e18e744d125baaedada3944.tar.gz
media: ov5640: Restrict sizes to mbus code
The ov5640 driver supports different sizes for different mbus_codes. In particular: - 8bpp modes: high resolution sizes (>= 1280x720) - 16bpp modes: all sizes - 24bpp modes: low resolutions sizes (< 1280x720) Restrict the frame sizes enumerations to the above constraints. While at it, make sure the fse->mbus_code parameter is valid, and return -EINVAL if it's not. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
-rw-r--r--drivers/media/i2c/ov5640.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index a1c00e7781d5..125ada9ae5fc 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -3474,14 +3474,28 @@ static int ov5640_enum_frame_size(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_frame_size_enum *fse)
{
+ u32 bpp = ov5640_code_to_bpp(fse->code);
+ unsigned int index = fse->index;
+
if (fse->pad != 0)
return -EINVAL;
- if (fse->index >= OV5640_NUM_MODES)
+ if (!bpp)
+ return -EINVAL;
+
+ /* Only low-resolution modes are supported for 24bpp formats. */
+ if (bpp == 24 && index >= OV5640_MODE_720P_1280_720)
+ return -EINVAL;
+
+ /* FIXME: Low resolution modes don't work in 8bpp formats. */
+ if (bpp == 8)
+ index += OV5640_MODE_720P_1280_720;
+
+ if (index >= OV5640_NUM_MODES)
return -EINVAL;
- fse->min_width = ov5640_mode_data[fse->index].width;
+ fse->min_width = ov5640_mode_data[index].width;
fse->max_width = fse->min_width;
- fse->min_height = ov5640_mode_data[fse->index].height;
+ fse->min_height = ov5640_mode_data[index].height;
fse->max_height = fse->min_height;
return 0;