media: ov7740: several bug fixes and cleanup
cover media: ov7740: several bug fixes and cleanup
This patchset includes three bug fixes and a cleanup for ov7740 driver.
Akinobu Mita (4):
media: ov7740: fix unbalanced pm_runtime_get/put
media: ov7740: avoid invalid framesize setting
media: ov7740: fix vertical flip control
media: ov7740: remove redundant V4L2_CTRL_FLAG_VOLATILE set
drivers/media/i2c/ov7740.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/4 media: ov7740: fix unbalanced pm_runtime_get/put
Avoid returning without decrement the usage count in s_ctrl().
--- drivers/media/i2c/ov7740.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/media/i2c/ov7740.c +6 -6
@@ -561,16 +561,16 @@ static int ov7740_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_AUTOGAIN :if (!ctrl->val) -return ov7740_set_gain (regmap, ov7740->gain->val); - - ret =ov7740_set_autogain (regmap, ctrl->val); + ret =ov7740_set_gain (regmap, ov7740->gain->val); +else + ret =ov7740_set_autogain (regmap, ctrl->val);break ;case V4L2_CID_EXPOSURE_AUTO :if (ctrl->val ==V4L2_EXPOSURE_MANUAL ) -return ov7740_set_exp (regmap, ov7740->exposure->val); - - ret =ov7740_set_autoexp (regmap, ctrl->val); + ret =ov7740_set_exp (regmap, ov7740->exposure->val); +else + ret =ov7740_set_autoexp (regmap, ctrl->val);break ;default : ret = -EINVAL ;
Signature · 1 line
2.7.4
PATCH 2/4 media: ov7740: avoid invalid framesize setting
In reply to Akinobu MitaIf the requested framesize by VIDIOC_SUBDEV_S_FMT is larger than supported framesizes, it causes an out of bounds array access and the resulting framesize is unexpected.
Avoid out of bounds array access and select the default framesize.
--- drivers/media/i2c/ov7740.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/i2c/ov7740.c +5 -1
@@ -785,7 +785,11 @@ static int ov7740_try_fmt_internal(struct v4l2_subdev *sd, fsize++; } - +if (i >=ARRAY_SIZE (ov7740_framesizes)) { + fsize = &ov7740_framesizes[0 ]; + fmt->width = fsize->width; + fmt->height = fsize->height; + }if (ret_frmsize !=NULL ) *ret_frmsize = fsize;
Signature · 1 line
2.7.4
PATCH 3/4 media: ov7740: fix vertical flip control
In reply to Akinobu MitaSetting the value of the V4L2_CID_VFLIP control is currently ignored.
Because V4L2_CID_HFLIP and V4L2_CID_VFLIP are independently controlled in s_ctrl() but these controls belong to the same cluster and the first control is V4L2_CID_HFLIP.
Fix it by not clustering these controls. Also correct erroneous updating register bit for vertical flip.
--- drivers/media/i2c/ov7740.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/ov7740.c +2 -2
@@ -532,7 +532,7 @@ static int ov7740_set_ctrl(struct v4l2_ctrl *ctrl)struct i2c_client *client =v4l2_get_subdevdata (&ov7740->subdev);struct regmap *regmap = ov7740->regmap;int ret; -u8 val =0 ; +u8 val;if (!pm_runtime_get_if_in_use (&client->dev))return 0 ;
@@ -551,6 +551,7 @@ static int ov7740_set_ctrl(struct v4l2_ctrl *ctrl) ret =ov7740_set_contrast (regmap, ctrl->val);break ;case V4L2_CID_VFLIP : + val = ctrl->val ?REG0C_IMG_FLIP :0x00 ; ret =regmap_update_bits (regmap,REG_REG0C ,REG0C_IMG_FLIP , val);break ;
@@ -1030,7 +1031,6 @@ static int ov7740_init_controls(struct ov7740 *ov7740)v4l2_ctrl_auto_cluster (2 , &ov7740->auto_gain,0 , true);v4l2_ctrl_auto_cluster (2 , &ov7740->auto_exposure,V4L2_EXPOSURE_MANUAL , true); -v4l2_ctrl_cluster (2 , &ov7740->hflip);if (ctrl_hdlr->error) { ret = ctrl_hdlr->error;
Signature · 1 line
2.7.4
PATCH 4/4 media: ov7740: remove redundant V4L2_CTRL_FLAG_VOLATILE set
In reply to Akinobu MitaIf the v4l2 controls are set up for autofoo/foo-type handling by calling v4l2_ctrl_auto_cluster() with the last set_volatile argument setting true, each non-auto control doesn't need to be flagged V4L2_CTRL_FLAG_VOLATILE.
--- drivers/media/i2c/ov7740.c | 2 -- 1 file changed, 2 deletions(-)
drivers/media/i2c/ov7740.c +0 -2
@@ -1012,8 +1012,6 @@ static int ov7740_init_controls(struct ov7740 *ov7740) ov7740->gain =v4l2_ctrl_new_std (ctrl_hdlr, &ov7740_ctrl_ops,V4L2_CID_GAIN ,0 ,1023 ,1 ,500 ); -if (ov7740->gain) - ov7740->gain->flags |=V4L2_CTRL_FLAG_VOLATILE ; ov7740->auto_gain =v4l2_ctrl_new_std (ctrl_hdlr, &ov7740_ctrl_ops,V4L2_CID_AUTOGAIN ,0 ,1 ,1 ,1 );
Signature · 1 line
2.7.4