LinuxTV Patchwork [13/14] media: ov6650: Fix stored frame format not in sync with hardware

mail settings
Submitter Janusz Krzysztofik
Date April 8, 2019, 9:42 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/55551/
State New
Delegated to: Sakari Ailus
Headers show


Janusz Krzysztofik - April 8, 2019, 9:42 p.m.
The driver stores frame format settings supposed to be in line with
hardware state in a device private structure.  Since the driver initial
submission, those settings are updated before they are actually applied
on hardware.  If an error occurs on device update, the stored settings
my not reflect hardware state anymore and consecutive calls to
.get_fmt() may return incorrect information.  That in turn may affect
ability of a host device to use correct DMA transfer settings if such
incorrect informmation on active frame format returned by .get_fmt() is

Assuming a failed device update means its state hasn't changed, update
frame format related settings stored in the device private structure
only after they are successfully applied so the stored values always
reflect hardware state as closely as possible.

Fixes: 2f6e2404799a ("[media] SoC Camera: add driver for OV6650 sensor")
Signed-off-by: Janusz Krzysztofik <>
 drivers/media/i2c/ov6650.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)


diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index 8013afea0c02..001457d39742 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -643,7 +643,6 @@  static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
 		dev_err(&client->dev, "Pixel format not handled: 0x%x\n", code);
 		return -EINVAL;
-	priv->code = code;
 	if (code == MEDIA_BUS_FMT_Y8_1X8 ||
 			code == MEDIA_BUS_FMT_SBGGR8_1X8) {
@@ -664,7 +663,6 @@  static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
 		dev_dbg(&client->dev, "max resolution: CIF\n");
 		coma_mask |= COMA_QCIF;
-	priv->half_scale = half_scale;
 	clkrc = CLKRC_12MHz;
 	mclk = 12000000;
@@ -682,8 +680,13 @@  static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
 		ret = ov6650_reg_rmw(client, REG_COMA, coma_set, coma_mask);
 	if (!ret)
 		ret = ov6650_reg_write(client, REG_CLKRC, clkrc);
-	if (!ret)
+	if (!ret) {
+		priv->half_scale = half_scale;
 		ret = ov6650_reg_rmw(client, REG_COML, coml_set, coml_mask);
+	}
+	if (!ret)
+		priv->code = code;
 	return ret;

Privacy Policy