diff mbox series

[11/14] media: ov6650: Fix .get_fmt() V4L2_SUBDEV_FORMAT_TRY support

Message ID 20190408214242.9603-12-jmkrzyszt@gmail.com (mailing list archive)
State New, archived
Headers show
Series media: ov6650: A collection of fixes | expand

Commit Message

Janusz Krzysztofik April 8, 2019, 9:42 p.m. UTC
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 | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index f6b0b77c5abf..e72210653f55 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -530,25 +530,27 @@  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 */
 	switch (format->which) {
 	case V4L2_SUBDEV_FORMAT_ACTIVE:
+		mf->width = priv->rect.width >> priv->half_scale;
+		mf->height = priv->rect.height >> priv->half_scale;
+		mf->code = priv->code;
 		break;
 	case V4L2_SUBDEV_FORMAT_TRY:
-		if (cfg)
+		if (cfg) {
+			mf->width = cfg->try_fmt.width;
+			mf->height = cfg->try_fmt.height;
+			mf->code = cfg->try_fmt.code;
 			break;
+		}
 		/* fall through */
 	default:
 		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;
-
 	return 0;
 }