Linux-Media Archive on lore.kernel.org
 help / Atom feed
* [PATCH v2 0/9] media: ov6650: A collection of fixes
@ 2019-05-20 22:49 Janusz Krzysztofik
  2019-05-20 22:49 ` [PATCH v2 1/9] media: ov6650: Fix MODDULE_DESCRIPTION Janusz Krzysztofik
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-20 22:49 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Sakari Ailus, Hans Verkuil, linux-media, linux-kernel,
	Janusz Krzysztofik

Janusz Krzysztofik (9):
  media: ov6650: Fix MODDULE_DESCRIPTION
  media: ov6650: Fix control handler not freed on init error
  media: ov6650: Fix crop rectangle alignment not passed back
  media: ov6650: Fix incorrect use of JPEG colorspace
  media: ov6650: Fix some format attributes not under control
  media: ov6650: Fix .get_fmt() V4L2_SUBDEV_FORMAT_TRY support
  media: ov6650: Fix default format not applied on device probe
  media: ov6650: Fix stored frame format not in sync with hardware
  media: ov6650: Fix stored crop rectangle not in sync with hardware

 drivers/media/i2c/ov6650.c | 137 +++++++++++++++++++++++--------------
 1 file changed, 86 insertions(+), 51 deletions(-)

Changelog
v1->v2:
- dropped patches 3/14 through 7/14 which were adding parameter checks
  now called from v4l2_subdev_call() - inspired by Sakari's requiest, 
  thanks!

-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/9] media: ov6650: Fix MODDULE_DESCRIPTION
  2019-05-20 22:49 [PATCH v2 0/9] media: ov6650: A collection of fixes Janusz Krzysztofik
@ 2019-05-20 22:49 ` Janusz Krzysztofik
  2019-05-21  5:15   ` Greg KH
  2019-05-20 22:50 ` [PATCH v2 2/9] media: ov6650: Fix control handler not freed on init error Janusz Krzysztofik
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-20 22:49 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Sakari Ailus, Hans Verkuil, linux-media, linux-kernel,
	Janusz Krzysztofik, stable

Commit 23a52386fabe ("media: ov6650: convert to standalone v4l2
subdevice") converted the driver from a soc_camera sensor to a
standalone V4L subdevice driver.  Unfortunately, module description was
not updated to reflect the change.  Fix it.

While being at it, update email address of the module author.

Fixes: 23a52386fabe ("media: ov6650: convert to standalone v4l2 subdevice")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
cc: stable@vger.kernel.org
---
 drivers/media/i2c/ov6650.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index 1b972e591b48..a3d00afcb0c8 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -1045,6 +1045,6 @@ static struct i2c_driver ov6650_i2c_driver = {
 
 module_i2c_driver(ov6650_i2c_driver);
 
-MODULE_DESCRIPTION("SoC Camera driver for OmniVision OV6650");
-MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>");
+MODULE_DESCRIPTION("V4L2 subdevice driver for OmniVision OV6650 camera sensor");
+MODULE_AUTHOR("Janusz Krzysztofik <jmkrzyszt@gmail.com");
 MODULE_LICENSE("GPL v2");
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 2/9] media: ov6650: Fix control handler not freed on init error
  2019-05-20 22:49 [PATCH v2 0/9] media: ov6650: A collection of fixes Janusz Krzysztofik
  2019-05-20 22:49 ` [PATCH v2 1/9] media: ov6650: Fix MODDULE_DESCRIPTION Janusz Krzysztofik
@ 2019-05-20 22:50 ` Janusz Krzysztofik
  2019-05-20 22:50 ` [PATCH v2 3/9] media: ov6650: Fix crop rectangle alignment not passed back Janusz Krzysztofik
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-20 22:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Sakari Ailus, Hans Verkuil, linux-media, linux-kernel,
	Janusz Krzysztofik, stable

Since commit afd9690c72c3 ("[media] ov6650: convert to the control
framework"), if an error occurs during initialization of a control
handler, resources possibly allocated to the handler are not freed
before device initialiaton is aborted.  Fix it.

Fixes: afd9690c72c3 ("[media] ov6650: convert to the control framework")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: stable@vger.kernel.org
---
 drivers/media/i2c/ov6650.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index a3d00afcb0c8..007f0ca24913 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -992,8 +992,10 @@ static int ov6650_probe(struct i2c_client *client,
 			V4L2_CID_GAMMA, 0, 0xff, 1, 0x12);
 
 	priv->subdev.ctrl_handler = &priv->hdl;
-	if (priv->hdl.error)
-		return priv->hdl.error;
+	if (priv->hdl.error) {
+		ret = priv->hdl.error;
+		goto ectlhdlfree;
+	}
 
 	v4l2_ctrl_auto_cluster(2, &priv->autogain, 0, true);
 	v4l2_ctrl_auto_cluster(3, &priv->autowb, 0, true);
@@ -1012,8 +1014,10 @@ static int ov6650_probe(struct i2c_client *client,
 	priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
 
 	ret = v4l2_async_register_subdev(&priv->subdev);
-	if (ret)
-		v4l2_ctrl_handler_free(&priv->hdl);
+	if (!ret)
+		return 0;
+ectlhdlfree:
+	v4l2_ctrl_handler_free(&priv->hdl);
 
 	return ret;
 }
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 3/9] media: ov6650: Fix crop rectangle alignment not passed back
  2019-05-20 22:49 [PATCH v2 0/9] media: ov6650: A collection of fixes Janusz Krzysztofik
  2019-05-20 22:49 ` [PATCH v2 1/9] media: ov6650: Fix MODDULE_DESCRIPTION Janusz Krzysztofik
  2019-05-20 22:50 ` [PATCH v2 2/9] media: ov6650: Fix control handler not freed on init error Janusz Krzysztofik
@ 2019-05-20 22:50 ` Janusz Krzysztofik
  2019-05-20 22:50 ` [PATCH v2 4/9] media: ov6650: Fix incorrect use of JPEG colorspace Janusz Krzysztofik
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-20 22:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Sakari Ailus, Hans Verkuil, linux-media, linux-kernel,
	Janusz Krzysztofik, stable

Commit 4f996594ceaf ("[media] v4l2: make vidioc_s_crop const")
introduced a writable copy of constified user requested crop rectangle
in order to be able to perform hardware alignments on it.  Later
on, commit 10d5509c8d50 ("[media] v4l2: remove g/s_crop from video
ops") replaced s_crop() video operaion using that const argument with
set_selection() pad operation which had a corresponding argument not
constified, however the original behavior of the driver was not
restored.  Since that time, any hardware alignment applied on a user
requested crop rectangle is not passed back to the user calling
.set_selection() as it should be.

Fix the issue by dropping the copy and replacing all references to it
with references to the crop rectangle embedded in the user argument.

Fixes: 10d5509c8d50 ("[media] v4l2: remove g/s_crop from video ops")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: stable@vger.kernel.org
---
 drivers/media/i2c/ov6650.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index 007f0ca24913..751b48483f27 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -468,38 +468,37 @@ static int ov6650_set_selection(struct v4l2_subdev *sd,
 {
 	struct i2c_client *client = v4l2_get_subdevdata(sd);
 	struct ov6650 *priv = to_ov6650(client);
-	struct v4l2_rect rect = sel->r;
 	int ret;
 
 	if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE ||
 	    sel->target != V4L2_SEL_TGT_CROP)
 		return -EINVAL;
 
-	v4l_bound_align_image(&rect.width, 2, W_CIF, 1,
-			      &rect.height, 2, H_CIF, 1, 0);
-	v4l_bound_align_image(&rect.left, DEF_HSTRT << 1,
-			      (DEF_HSTRT << 1) + W_CIF - (__s32)rect.width, 1,
-			      &rect.top, DEF_VSTRT << 1,
-			      (DEF_VSTRT << 1) + H_CIF - (__s32)rect.height, 1,
-			      0);
+	v4l_bound_align_image(&sel->r.width, 2, W_CIF, 1,
+			      &sel->r.height, 2, H_CIF, 1, 0);
+	v4l_bound_align_image(&sel->r.left, DEF_HSTRT << 1,
+			      (DEF_HSTRT << 1) + W_CIF - (__s32)sel->r.width, 1,
+			      &sel->r.top, DEF_VSTRT << 1,
+			      (DEF_VSTRT << 1) + H_CIF - (__s32)sel->r.height,
+			      1, 0);
 
-	ret = ov6650_reg_write(client, REG_HSTRT, rect.left >> 1);
+	ret = ov6650_reg_write(client, REG_HSTRT, sel->r.left >> 1);
 	if (!ret) {
-		priv->rect.left = rect.left;
+		priv->rect.left = sel->r.left;
 		ret = ov6650_reg_write(client, REG_HSTOP,
-				(rect.left + rect.width) >> 1);
+				       (sel->r.left + sel->r.width) >> 1);
 	}
 	if (!ret) {
-		priv->rect.width = rect.width;
-		ret = ov6650_reg_write(client, REG_VSTRT, rect.top >> 1);
+		priv->rect.width = sel->r.width;
+		ret = ov6650_reg_write(client, REG_VSTRT, sel->r.top >> 1);
 	}
 	if (!ret) {
-		priv->rect.top = rect.top;
+		priv->rect.top = sel->r.top;
 		ret = ov6650_reg_write(client, REG_VSTOP,
-				(rect.top + rect.height) >> 1);
+				       (sel->r.top + sel->r.height) >> 1);
 	}
 	if (!ret)
-		priv->rect.height = rect.height;
+		priv->rect.height = sel->r.height;
 
 	return ret;
 }
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 4/9] media: ov6650: Fix incorrect use of JPEG colorspace
  2019-05-20 22:49 [PATCH v2 0/9] media: ov6650: A collection of fixes Janusz Krzysztofik
                   ` (2 preceding siblings ...)
  2019-05-20 22:50 ` [PATCH v2 3/9] media: ov6650: Fix crop rectangle alignment not passed back Janusz Krzysztofik
@ 2019-05-20 22:50 ` Janusz Krzysztofik
  2019-05-20 22:50 ` [PATCH v2 5/9] media: ov6650: Fix some format attributes not under control Janusz Krzysztofik
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-20 22:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Sakari Ailus, Hans Verkuil, linux-media, linux-kernel,
	Janusz Krzysztofik, stable

Since its initial submission, the driver selects V4L2_COLORSPACE_JPEG
for supported formats other than V4L2_MBUS_FMT_SBGGR8_1X8.  According
to v4l2-compliance test program, V4L2_COLORSPACE_JPEG applies
exclusively to V4L2_PIX_FMT_JPEG.  Since the sensor does not support
JPEG format, fix it to always select V4L2_COLORSPACE_SRGB.

Fixes: 2f6e2404799a ("[media] SoC Camera: add driver for OV6650 sensor")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: stable@vger.kernel.org
---
 drivers/media/i2c/ov6650.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index 751b48483f27..e7790e9b8887 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -203,7 +203,6 @@ struct ov6650 {
 	unsigned long		pclk_max;	/* from resolution and format */
 	struct v4l2_fract	tpf;		/* as requested with s_frame_interval */
 	u32 code;
-	enum v4l2_colorspace	colorspace;
 };
 
 
@@ -517,7 +516,7 @@ static int ov6650_get_fmt(struct v4l2_subdev *sd,
 	mf->width	= priv->rect.width >> priv->half_scale;
 	mf->height	= priv->rect.height >> priv->half_scale;
 	mf->code	= priv->code;
-	mf->colorspace	= priv->colorspace;
+	mf->colorspace	= V4L2_COLORSPACE_SRGB;
 	mf->field	= V4L2_FIELD_NONE;
 
 	return 0;
@@ -625,11 +624,6 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
 		priv->pclk_max = 8000000;
 	}
 
-	if (code == MEDIA_BUS_FMT_SBGGR8_1X8)
-		priv->colorspace = V4L2_COLORSPACE_SRGB;
-	else if (code != 0)
-		priv->colorspace = V4L2_COLORSPACE_JPEG;
-
 	if (half_scale) {
 		dev_dbg(&client->dev, "max resolution: QCIF\n");
 		coma_set |= COMA_QCIF;
@@ -660,7 +654,6 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
 		ret = ov6650_reg_rmw(client, REG_COML, coml_set, coml_mask);
 
 	if (!ret) {
-		mf->colorspace	= priv->colorspace;
 		mf->width = priv->rect.width >> half_scale;
 		mf->height = priv->rect.height >> half_scale;
 	}
@@ -683,6 +676,7 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd,
 				&mf->height, 2, H_CIF, 1, 0);
 
 	mf->field = V4L2_FIELD_NONE;
+	mf->colorspace = V4L2_COLORSPACE_SRGB;
 
 	switch (mf->code) {
 	case MEDIA_BUS_FMT_Y10_1X10:
@@ -693,13 +687,11 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd,
 	case MEDIA_BUS_FMT_YUYV8_2X8:
 	case MEDIA_BUS_FMT_VYUY8_2X8:
 	case MEDIA_BUS_FMT_UYVY8_2X8:
-		mf->colorspace = V4L2_COLORSPACE_JPEG;
 		break;
 	default:
 		mf->code = MEDIA_BUS_FMT_SBGGR8_1X8;
 		/* fall through */
 	case MEDIA_BUS_FMT_SBGGR8_1X8:
-		mf->colorspace = V4L2_COLORSPACE_SRGB;
 		break;
 	}
 
@@ -1007,7 +999,6 @@ static int ov6650_probe(struct i2c_client *client,
 	priv->rect.height = H_CIF;
 	priv->half_scale  = false;
 	priv->code	  = MEDIA_BUS_FMT_YUYV8_2X8;
-	priv->colorspace  = V4L2_COLORSPACE_JPEG;
 
 	priv->subdev.internal_ops = &ov6650_internal_ops;
 	priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 5/9] media: ov6650: Fix some format attributes not under control
  2019-05-20 22:49 [PATCH v2 0/9] media: ov6650: A collection of fixes Janusz Krzysztofik
                   ` (3 preceding siblings ...)
  2019-05-20 22:50 ` [PATCH v2 4/9] media: ov6650: Fix incorrect use of JPEG colorspace Janusz Krzysztofik
@ 2019-05-20 22:50 ` Janusz Krzysztofik
  2019-05-20 22:50 ` [PATCH v2 6/9] media: ov6650: Fix .get_fmt() V4L2_SUBDEV_FORMAT_TRY support Janusz Krzysztofik
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-20 22:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Sakari Ailus, Hans Verkuil, linux-media, linux-kernel,
	Janusz Krzysztofik, stable

User arguments passed to .get/set_fmt() pad operation callbacks may
contain unsupported values.  The driver takes control over frame size
and pixel code as well as colorspace and field attributes but has never
cared for remainig format attributes, i.e., ycbcr_enc, quantization
and xfer_func, introduced by commit 11ff030c7365 ("[media]
v4l2-mediabus: improve colorspace support").  Fix it.

Set up a static v4l2_mbus_framefmt structure with attributes
initialized to reasonable defaults and use it for updating content of
user provided arguments.  In case of V4L2_SUBDEV_FORMAT_ACTIVE,
postpone frame size update, now performed from inside ov6650_s_fmt()
helper, util the user argument is first updated in ov6650_set_fmt() with
default frame format content.  For V4L2_SUBDEV_FORMAT_TRY, don't copy
all attributes to pad config, only those handled by the driver, then
fill the response with the default frame format updated with updated
pad config format code and frame size.

Fixes: 11ff030c7365 ("[media] v4l2-mediabus: improve colorspace support")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: stable@vger.kernel.org
---
 drivers/media/i2c/ov6650.c | 51 +++++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 12 deletions(-)

diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index e7790e9b8887..731b03bef7a5 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -215,6 +215,17 @@ static u32 ov6650_codes[] = {
 	MEDIA_BUS_FMT_Y8_1X8,
 };
 
+static const struct v4l2_mbus_framefmt ov6650_def_fmt = {
+	.width		= W_CIF,
+	.height		= H_CIF,
+	.code		= MEDIA_BUS_FMT_SBGGR8_1X8,
+	.colorspace	= V4L2_COLORSPACE_SRGB,
+	.field		= V4L2_FIELD_NONE,
+	.ycbcr_enc	= V4L2_YCBCR_ENC_DEFAULT,
+	.quantization	= V4L2_QUANTIZATION_DEFAULT,
+	.xfer_func	= V4L2_XFER_FUNC_DEFAULT,
+};
+
 /* read a register */
 static int ov6650_reg_read(struct i2c_client *client, u8 reg, u8 *val)
 {
@@ -513,11 +524,13 @@ static int ov6650_get_fmt(struct v4l2_subdev *sd,
 	if (format->pad)
 		return -EINVAL;
 
+	/* initialize response with default media bus frame format */
+	*mf = ov6650_def_fmt;
+
+	/* update media bus format code and frame size */
 	mf->width	= priv->rect.width >> priv->half_scale;
 	mf->height	= priv->rect.height >> priv->half_scale;
 	mf->code	= priv->code;
-	mf->colorspace	= V4L2_COLORSPACE_SRGB;
-	mf->field	= V4L2_FIELD_NONE;
 
 	return 0;
 }
@@ -653,10 +666,6 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
 	if (!ret)
 		ret = ov6650_reg_rmw(client, REG_COML, coml_set, coml_mask);
 
-	if (!ret) {
-		mf->width = priv->rect.width >> half_scale;
-		mf->height = priv->rect.height >> half_scale;
-	}
 	return ret;
 }
 
@@ -675,9 +684,6 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd,
 		v4l_bound_align_image(&mf->width, 2, W_CIF, 1,
 				&mf->height, 2, H_CIF, 1, 0);
 
-	mf->field = V4L2_FIELD_NONE;
-	mf->colorspace = V4L2_COLORSPACE_SRGB;
-
 	switch (mf->code) {
 	case MEDIA_BUS_FMT_Y10_1X10:
 		mf->code = MEDIA_BUS_FMT_Y8_1X8;
@@ -695,10 +701,31 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd,
 		break;
 	}
 
-	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
-		return ov6650_s_fmt(sd, mf);
-	cfg->try_fmt = *mf;
+	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
+		/* store media bus format code and frame size in pad config */
+		cfg->try_fmt.width = mf->width;
+		cfg->try_fmt.height = mf->height;
+		cfg->try_fmt.code = mf->code;
 
+		/* return default mbus frame format updated with pad config */
+		*mf = ov6650_def_fmt;
+		mf->width = cfg->try_fmt.width;
+		mf->height = cfg->try_fmt.height;
+		mf->code = cfg->try_fmt.code;
+
+	} else {
+		/* apply new media bus format code and frame size */
+		int ret = ov6650_s_fmt(sd, mf);
+
+		if (ret)
+			return ret;
+
+		/* return default format updated with active size and code */
+		*mf = ov6650_def_fmt;
+		mf->width = priv->rect.width >> priv->half_scale;
+		mf->height = priv->rect.height >> priv->half_scale;
+		mf->code = priv->code;
+	}
 	return 0;
 }
 
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 6/9] media: ov6650: Fix .get_fmt() V4L2_SUBDEV_FORMAT_TRY support
  2019-05-20 22:49 [PATCH v2 0/9] media: ov6650: A collection of fixes Janusz Krzysztofik
                   ` (4 preceding siblings ...)
  2019-05-20 22:50 ` [PATCH v2 5/9] media: ov6650: Fix some format attributes not under control Janusz Krzysztofik
@ 2019-05-20 22:50 ` Janusz Krzysztofik
  2019-05-20 22:50 ` [PATCH v2 7/9] media: ov6650: Fix default format not applied on device probe Janusz Krzysztofik
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-20 22:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Sakari Ailus, Hans Verkuil, linux-media, linux-kernel,
	Janusz Krzysztofik, stable

Commit da298c6d98d5 ("[media] v4l2: replace video op g_mbus_fmt by pad
op get_fmt") converted a former ov6650_g_fmt() video operation callback
to an ov6650_get_fmt() pad operation callback.  However, the converted
function disregards a format->which flag that pad operations should
obey and always returns active frame format settings.

That can be fixed by always responding to V4L2_SUBDEV_FORMAT_TRY with
-EINVAL, or providing the response from a pad config argument, likely
updated by a former user call to V4L2_SUBDEV_FORMAT_TRY .set_fmt().
Since implementation of the latter is trivial, go for it.

Fixes: da298c6d98d5 ("[media] v4l2: replace video op g_mbus_fmt by pad op get_fmt")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: stable@vger.kernel.org
---
 drivers/media/i2c/ov6650.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index 731b03bef7a5..1915a43bff87 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -528,10 +528,16 @@ static int ov6650_get_fmt(struct v4l2_subdev *sd,
 	*mf = ov6650_def_fmt;
 
 	/* update media bus format code and frame size */
-	mf->width	= priv->rect.width >> priv->half_scale;
-	mf->height	= priv->rect.height >> priv->half_scale;
-	mf->code	= priv->code;
+	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
+		mf->width = cfg->try_fmt.width;
+		mf->height = cfg->try_fmt.height;
+		mf->code = cfg->try_fmt.code;
 
+	} else {
+		mf->width = priv->rect.width >> priv->half_scale;
+		mf->height = priv->rect.height >> priv->half_scale;
+		mf->code = priv->code;
+	}
 	return 0;
 }
 
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 7/9] media: ov6650: Fix default format not applied on device probe
  2019-05-20 22:49 [PATCH v2 0/9] media: ov6650: A collection of fixes Janusz Krzysztofik
                   ` (5 preceding siblings ...)
  2019-05-20 22:50 ` [PATCH v2 6/9] media: ov6650: Fix .get_fmt() V4L2_SUBDEV_FORMAT_TRY support Janusz Krzysztofik
@ 2019-05-20 22:50 ` Janusz Krzysztofik
  2019-05-20 22:50 ` [PATCH v2 8/9] media: ov6650: Fix stored frame format not in sync with hardware Janusz Krzysztofik
  2019-05-20 22:50 ` [PATCH v2 9/9] media: ov6650: Fix stored crop rectangle " Janusz Krzysztofik
  8 siblings, 0 replies; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-20 22:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Sakari Ailus, Hans Verkuil, linux-media, linux-kernel,
	Janusz Krzysztofik, stable

It is not clear what pixel format is actually configured in hardware on
reset.  MEDIA_BUS_FMT_YUYV8_2X8, assumed on device probe since the
driver was intiially submitted, is for sure not the one.

Fix it by explicitly applying a known, driver default frame format just
after initial device reset.

Fixes: 2f6e2404799a ("[media] SoC Camera: add driver for OV6650 sensor")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: stable@vger.kernel.org
---
 drivers/media/i2c/ov6650.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index 1915a43bff87..b199332f62d7 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -876,6 +876,11 @@ static int ov6650_video_probe(struct v4l2_subdev *sd)
 	ret = ov6650_reset(client);
 	if (!ret)
 		ret = ov6650_prog_dflt(client);
+	if (!ret) {
+		struct v4l2_mbus_framefmt mf = ov6650_def_fmt;
+
+		ret = ov6650_s_fmt(sd, &mf);
+	}
 	if (!ret)
 		ret = v4l2_ctrl_handler_setup(&priv->hdl);
 
@@ -1030,8 +1035,6 @@ static int ov6650_probe(struct i2c_client *client,
 	priv->rect.top	  = DEF_VSTRT << 1;
 	priv->rect.width  = W_CIF;
 	priv->rect.height = H_CIF;
-	priv->half_scale  = false;
-	priv->code	  = MEDIA_BUS_FMT_YUYV8_2X8;
 
 	priv->subdev.internal_ops = &ov6650_internal_ops;
 	priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 8/9] media: ov6650: Fix stored frame format not in sync with hardware
  2019-05-20 22:49 [PATCH v2 0/9] media: ov6650: A collection of fixes Janusz Krzysztofik
                   ` (6 preceding siblings ...)
  2019-05-20 22:50 ` [PATCH v2 7/9] media: ov6650: Fix default format not applied on device probe Janusz Krzysztofik
@ 2019-05-20 22:50 ` Janusz Krzysztofik
  2019-05-20 22:50 ` [PATCH v2 9/9] media: ov6650: Fix stored crop rectangle " Janusz Krzysztofik
  8 siblings, 0 replies; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-20 22:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Sakari Ailus, Hans Verkuil, linux-media, linux-kernel,
	Janusz Krzysztofik, stable

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 bridge device to use correct DMA transfer settings if such
incorrect informmation on active frame format returned by .get_fmt() is
used.

Assuming a failed device update mean 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 <jmkrzyszt@gmail.com>
Cc: stable@vger.kernel.org
---
 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 b199332f62d7..65d43390dbeb 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -630,7 +630,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) {
@@ -651,7 +650,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;
@@ -669,8 +667,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;
 }
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 9/9] media: ov6650: Fix stored crop rectangle not in sync with hardware
  2019-05-20 22:49 [PATCH v2 0/9] media: ov6650: A collection of fixes Janusz Krzysztofik
                   ` (7 preceding siblings ...)
  2019-05-20 22:50 ` [PATCH v2 8/9] media: ov6650: Fix stored frame format not in sync with hardware Janusz Krzysztofik
@ 2019-05-20 22:50 ` " Janusz Krzysztofik
  8 siblings, 0 replies; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-20 22:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Sakari Ailus, Hans Verkuil, linux-media, linux-kernel,
	Janusz Krzysztofik, stable

The driver stores crop rectangle settings supposed to be in line with
hardware state in a device private structure.  Since the driver initial
submission, crop rectangle width and height settings are not updated
correctly when rectangle offset settings are applied on hardware.  If
an error occurs while the device is updated, the stored settings my no
longer reflect hardware state and consecutive calls to .get_selection()
as well as .get/set_fmt() may return incorrect information.  That in
turn may affect ability of a bridge device to use correct DMA transfer
settings if such incorrect informamtion on active frame format returned
by .get/set_fmt() is used.

Assuming a failed update of the device means its actual settings haven't
changed, update crop rectangle width and height settings stored in the
device private structure correctly while the rectangle offset is
successfully applied on hardware so the stored values always reflect
actual hardware state to the extent possible.

Fixes: 2f6e2404799a ("[media] SoC Camera: add driver for OV6650 sensor")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: stable@vger.kernel.org
---
 drivers/media/i2c/ov6650.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index 65d43390dbeb..c728f718716b 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -494,6 +494,7 @@ static int ov6650_set_selection(struct v4l2_subdev *sd,
 
 	ret = ov6650_reg_write(client, REG_HSTRT, sel->r.left >> 1);
 	if (!ret) {
+		priv->rect.width += priv->rect.left - sel->r.left;
 		priv->rect.left = sel->r.left;
 		ret = ov6650_reg_write(client, REG_HSTOP,
 				       (sel->r.left + sel->r.width) >> 1);
@@ -503,6 +504,7 @@ static int ov6650_set_selection(struct v4l2_subdev *sd,
 		ret = ov6650_reg_write(client, REG_VSTRT, sel->r.top >> 1);
 	}
 	if (!ret) {
+		priv->rect.height += priv->rect.top - sel->r.top;
 		priv->rect.top = sel->r.top;
 		ret = ov6650_reg_write(client, REG_VSTOP,
 				       (sel->r.top + sel->r.height) >> 1);
-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/9] media: ov6650: Fix MODDULE_DESCRIPTION
  2019-05-20 22:49 ` [PATCH v2 1/9] media: ov6650: Fix MODDULE_DESCRIPTION Janusz Krzysztofik
@ 2019-05-21  5:15   ` Greg KH
  2019-05-21 17:55     ` Janusz Krzysztofik
  0 siblings, 1 reply; 12+ messages in thread
From: Greg KH @ 2019-05-21  5:15 UTC (permalink / raw)
  To: Janusz Krzysztofik
  Cc: Mauro Carvalho Chehab, Sakari Ailus, Hans Verkuil, linux-media,
	linux-kernel, stable

On Tue, May 21, 2019 at 12:49:59AM +0200, Janusz Krzysztofik wrote:
> Commit 23a52386fabe ("media: ov6650: convert to standalone v4l2
> subdevice") converted the driver from a soc_camera sensor to a
> standalone V4L subdevice driver.  Unfortunately, module description was
> not updated to reflect the change.  Fix it.
> 
> While being at it, update email address of the module author.
> 
> Fixes: 23a52386fabe ("media: ov6650: convert to standalone v4l2 subdevice")
> Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
> cc: stable@vger.kernel.org
> ---
>  drivers/media/i2c/ov6650.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
> index 1b972e591b48..a3d00afcb0c8 100644
> --- a/drivers/media/i2c/ov6650.c
> +++ b/drivers/media/i2c/ov6650.c
> @@ -1045,6 +1045,6 @@ static struct i2c_driver ov6650_i2c_driver = {
>  
>  module_i2c_driver(ov6650_i2c_driver);
>  
> -MODULE_DESCRIPTION("SoC Camera driver for OmniVision OV6650");
> -MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>");
> +MODULE_DESCRIPTION("V4L2 subdevice driver for OmniVision OV6650 camera sensor");
> +MODULE_AUTHOR("Janusz Krzysztofik <jmkrzyszt@gmail.com");
>  MODULE_LICENSE("GPL v2");
> -- 
> 2.21.0
> 

is this _really_ a patch that meets the stable kernel requirements?
Same for this whole series...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/9] media: ov6650: Fix MODDULE_DESCRIPTION
  2019-05-21  5:15   ` Greg KH
@ 2019-05-21 17:55     ` Janusz Krzysztofik
  0 siblings, 0 replies; 12+ messages in thread
From: Janusz Krzysztofik @ 2019-05-21 17:55 UTC (permalink / raw)
  To: Greg KH
  Cc: Mauro Carvalho Chehab, Sakari Ailus, Hans Verkuil, linux-media,
	linux-kernel, stable

On Tuesday, May 21, 2019 7:15:37 AM CEST Greg KH wrote:
> On Tue, May 21, 2019 at 12:49:59AM +0200, Janusz Krzysztofik wrote:
> > Commit 23a52386fabe ("media: ov6650: convert to standalone v4l2
> > subdevice") converted the driver from a soc_camera sensor to a
> > standalone V4L subdevice driver.  Unfortunately, module description was
> > not updated to reflect the change.  Fix it.
> > 
> > While being at it, update email address of the module author.
> > 
> > Fixes: 23a52386fabe ("media: ov6650: convert to standalone v4l2 subdevice")
> > Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
> > cc: stable@vger.kernel.org
> > ---
> >  drivers/media/i2c/ov6650.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
> > index 1b972e591b48..a3d00afcb0c8 100644
> > --- a/drivers/media/i2c/ov6650.c
> > +++ b/drivers/media/i2c/ov6650.c
> > @@ -1045,6 +1045,6 @@ static struct i2c_driver ov6650_i2c_driver = {
> >  
> >  module_i2c_driver(ov6650_i2c_driver);
> >  
> > -MODULE_DESCRIPTION("SoC Camera driver for OmniVision OV6650");
> > -MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>");
> > +MODULE_DESCRIPTION("V4L2 subdevice driver for OmniVision OV6650 camera sensor");
> > +MODULE_AUTHOR("Janusz Krzysztofik <jmkrzyszt@gmail.com");
> >  MODULE_LICENSE("GPL v2");
> 
> is this _really_ a patch that meets the stable kernel requirements?
> Same for this whole series...

Hi Greg,

My bad, I'm sorry.  Please ignore the whole series, and I'll be more careful
in the future.

Thanks,
Janusz

> 
> thanks,
> 
> greg k-h
> 





^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, back to index

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-20 22:49 [PATCH v2 0/9] media: ov6650: A collection of fixes Janusz Krzysztofik
2019-05-20 22:49 ` [PATCH v2 1/9] media: ov6650: Fix MODDULE_DESCRIPTION Janusz Krzysztofik
2019-05-21  5:15   ` Greg KH
2019-05-21 17:55     ` Janusz Krzysztofik
2019-05-20 22:50 ` [PATCH v2 2/9] media: ov6650: Fix control handler not freed on init error Janusz Krzysztofik
2019-05-20 22:50 ` [PATCH v2 3/9] media: ov6650: Fix crop rectangle alignment not passed back Janusz Krzysztofik
2019-05-20 22:50 ` [PATCH v2 4/9] media: ov6650: Fix incorrect use of JPEG colorspace Janusz Krzysztofik
2019-05-20 22:50 ` [PATCH v2 5/9] media: ov6650: Fix some format attributes not under control Janusz Krzysztofik
2019-05-20 22:50 ` [PATCH v2 6/9] media: ov6650: Fix .get_fmt() V4L2_SUBDEV_FORMAT_TRY support Janusz Krzysztofik
2019-05-20 22:50 ` [PATCH v2 7/9] media: ov6650: Fix default format not applied on device probe Janusz Krzysztofik
2019-05-20 22:50 ` [PATCH v2 8/9] media: ov6650: Fix stored frame format not in sync with hardware Janusz Krzysztofik
2019-05-20 22:50 ` [PATCH v2 9/9] media: ov6650: Fix stored crop rectangle " Janusz Krzysztofik

Linux-Media Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-media/0 linux-media/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-media linux-media/ https://lore.kernel.org/linux-media \
		linux-media@vger.kernel.org linux-media@archiver.kernel.org
	public-inbox-index linux-media


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-media


AGPL code for this site: git clone https://public-inbox.org/ public-inbox