Skip to contentSkip to conversation

OV5642: fix VIDIOC_S_GROP ioctl

PATCH In review Anatolij Gustschin 2 participants 6 messages Nov 5, 2012 – Nov 28, 2012 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 OV5642: fix VIDIOC_S_GROP ioctl

VIDIOC_S_GROP ioctl doesn't work, soc-camera driver reports:

soc-camera-pdrv soc-camera-pdrv.0: S_CROP denied: getting current crop failed

The issue is caused by checking for V4L2_BUF_TYPE_VIDEO_CAPTURE type in driver's g_crop callback. This check should be in s_crop instead, g_crop should just set the type field to V4L2_BUF_TYPE_VIDEO_CAPTURE as other drivers do. Move the V4L2_BUF_TYPE_VIDEO_CAPTURE type check to s_crop callback.

Cc Guennadi Liakhovetski <[email protected]>
---
 drivers/media/i2c/soc_camera/ov5642.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/media/i2c/soc_camera/ov5642.c +4 -3
index 8577e0c..19863e5 100644
@@ -872,6 +872,9 @@ static int ov5642_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
 	struct v4l2_rect rect = a->c;
 	int ret;
 
+	if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+
 	v4l_bound_align_image(&rect.width, 48, OV5642_MAX_WIDTH, 1,
 			      &rect.height, 32, OV5642_MAX_HEIGHT, 1, 0);
 
@@ -899,9 +902,7 @@ static int ov5642_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
 	struct ov5642 *priv = to_ov5642(client);
 	struct v4l2_rect *rect = &a->c;
 
-	if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-		return -EINVAL;
-
+	a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	*rect = priv->crop_rect;
 
 	return 0;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 9 lines · Anatolij Gustschin

VIDIOC_S_GROP ioctl doesn't work, soc-camera driver reports:

soc-camera-pdrv soc-camera-pdrv.0: S_CROP denied: getting current crop failed

The issue is caused by checking for V4L2_BUF_TYPE_VIDEO_CAPTURE type in driver's g_crop callback. This check should be in s_crop instead, g_crop should just set the type field to V4L2_BUF_TYPE_VIDEO_CAPTURE as other drivers do. Move the V4L2_BUF_TYPE_VIDEO_CAPTURE type check to s_crop callback.

I'm not sure this is correct:

http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-crop.html

Or is the .g_crop() subdev operation using a different semantics? Where is that documented?

Thanks
Guennadi

Quoted 40 lines
Cc Guennadi Liakhovetski <[email protected]>
---
 drivers/media/i2c/soc_camera/ov5642.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/media/i2c/soc_camera/ov5642.c +4 -3
index 8577e0c..19863e5 100644
@@ -872,6 +872,9 @@ static int ov5642_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
 	struct v4l2_rect rect = a->c;
 	int ret;
 
+	if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+
 	v4l_bound_align_image(&rect.width, 48, OV5642_MAX_WIDTH, 1,
 			      &rect.height, 32, OV5642_MAX_HEIGHT, 1, 0);
 
@@ -899,9 +902,7 @@ static int ov5642_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
 	struct ov5642 *priv = to_ov5642(client);
 	struct v4l2_rect *rect = &a->c;
 
-	if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-		return -EINVAL;
-
+	a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	*rect = priv->crop_rect;
 
 	return 0;
Signature · 6 lines
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#2 lore raw
Quoted 12 lines · On Tue, 6 Nov 2012 12:45:51 +0100 (CET) Guennadi Liakhovetski…
Quoted 9 lines · Anatolij Gustschin

VIDIOC_S_GROP ioctl doesn't work, soc-camera driver reports:

soc-camera-pdrv soc-camera-pdrv.0: S_CROP denied: getting current crop failed

The issue is caused by checking for V4L2_BUF_TYPE_VIDEO_CAPTURE type in driver's g_crop callback. This check should be in s_crop instead, g_crop should just set the type field to V4L2_BUF_TYPE_VIDEO_CAPTURE as other drivers do. Move the V4L2_BUF_TYPE_VIDEO_CAPTURE type check to s_crop callback.

Quoted 6 lines

I'm not sure this is correct:

http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-crop.html

Or is the .g_crop() subdev operation using a different semantics? Where is that documented?

I do not know if it is documented somewhere. But it seems natural to me that a sensor driver sets the type field to V4L2_BUF_TYPE_VIDEO_CAPTURE in its .g_crop(). A sensor is a capture device, not an output or overlay device. And this ioctl is a query operation.

OTOH I'm fine with this type checking in .g_crop() and it can help to discover bugs in user space apps. The VIDIOC_G_CROP documentation states that the type field needs to be set to the respective buffer type when querying, so the check in .g_crop() is perfectly valid. But then I need following patch to fix the observed issue:

drivers/media/platform/soc_camera/soc_camera.c +2 -0
@@ -902,6 +902,8 @@ static int soc_camera_s_crop(struct file *file, void *fh,
        dev_dbg(icd->pdev, "S_CROP(%ux%u@%u:%u)\n",
                rect->width, rect->height, rect->left, rect->top);
 
+       current_crop.type = a->type;
+
        /* If get_crop fails, we'll let host and / or client drivers decide */
        ret = ici->ops->get_crop(icd, &current_crop);
 

What do you think?

And the type field should be checked in .s_crop() anyway, I think.

Thanks,
Anatolij

#3 lore raw

Hi Anatolij

Sorry for a delay

Quoted 44 lines · Anatolij Gustschin
Quoted 12 lines · On Tue, 6 Nov 2012 12:45:51 +0100 (CET) Guennadi Liakhovetski…
Quoted 9 lines · Anatolij Gustschin

VIDIOC_S_GROP ioctl doesn't work, soc-camera driver reports:

soc-camera-pdrv soc-camera-pdrv.0: S_CROP denied: getting current crop failed

The issue is caused by checking for V4L2_BUF_TYPE_VIDEO_CAPTURE type in driver's g_crop callback. This check should be in s_crop instead, g_crop should just set the type field to V4L2_BUF_TYPE_VIDEO_CAPTURE as other drivers do. Move the V4L2_BUF_TYPE_VIDEO_CAPTURE type check to s_crop callback.

Quoted 6 lines

I'm not sure this is correct:

http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-crop.html

Or is the .g_crop() subdev operation using a different semantics? Where is that documented?

I do not know if it is documented somewhere. But it seems natural to me that a sensor driver sets the type field to V4L2_BUF_TYPE_VIDEO_CAPTURE in its .g_crop(). A sensor is a capture device, not an output or overlay device. And this ioctl is a query operation.

OTOH I'm fine with this type checking in .g_crop() and it can help to discover bugs in user space apps. The VIDIOC_G_CROP documentation states that the type field needs to be set to the respective buffer type when querying, so the check in .g_crop() is perfectly valid. But then I need following patch to fix the observed issue:

drivers/media/platform/soc_camera/soc_camera.c +2 -0
@@ -902,6 +902,8 @@ static int soc_camera_s_crop(struct file *file, void *fh,
        dev_dbg(icd->pdev, "S_CROP(%ux%u@%u:%u)\n",
                rect->width, rect->height, rect->left, rect->top);
 
+       current_crop.type = a->type;
+
        /* If get_crop fails, we'll let host and / or client drivers decide */
        ret = ici->ops->get_crop(icd, &current_crop);
 
Quoted 1 line

What do you think?

Yes, this makes sense. Please, submit a patch.

Quoted 1 line

And the type field should be checked in .s_crop() anyway, I think.

It is checked in soc_camera_s_crop() just a couple of lines above the snippet above. Or what do you mean?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#4 lore raw

PATCH 1/1 soc_camera: fix VIDIOC_S_GROP ioctl

Sometimes VIDIOC_S_GROP ioctl doesn't work, soc-camera driver reports:

soc-camera-pdrv soc-camera-pdrv.0: S_CROP denied: getting current crop failed

The VIDIOC_G_CROP documentation states that the type field needs to be set to the respective buffer type when querying, so the check in .g_crop() of the subdevices returns -EINVAL if the type is not set properly. Here the uninitialized local variable 'current_crop' is passed to the .g_crop() and this leads to the observed error. Initialize the type field of the local 'current_crop' before get_crop call.

---
 drivers/media/platform/soc_camera/soc_camera.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/media/platform/soc_camera/soc_camera.c +2 -0
index d3f0b84..7ebc784 100644
@@ -902,6 +902,8 @@ static int soc_camera_s_crop(struct file *file, void *fh,
 	dev_dbg(icd->pdev, "S_CROP(%ux%u@%u:%u)\n",
 		rect->width, rect->height, rect->left, rect->top);
 
+	current_crop.type = a->type;
+
 	/* If get_crop fails, we'll let host and / or client drivers decide */
 	ret = ici->ops->get_crop(icd, &current_crop);
 
Signature · 1 line
1.7.1
#5 lore raw
In reply to Guennadi Liakhovetski

Hi Guennadi,

On Mon, 26 Nov 2012 16:20:14 +0100 (CET) Guennadi Liakhovetski <[email protected]> wrote:
...

Quoted 6 lines
Quoted 6 lines
drivers/media/platform/soc_camera/soc_camera.c +0 -0
@@ -902,6 +902,8 @@ static int soc_camera_s_crop(struct file *file, void *fh,
        dev_dbg(icd->pdev, "S_CROP(%ux%u@%u:%u)\n",
                rect->width, rect->height, rect->left, rect->top);
 
Quoted 8 lines
Quoted 6 lines
drivers/media/platform/soc_camera/soc_camera.c +2 -0
+       current_crop.type = a->type;
+
        /* If get_crop fails, we'll let host and / or client drivers decide */
        ret = ici->ops->get_crop(icd, &current_crop);
 

What do you think?

Yes, this makes sense. Please, submit a patch.

Done.

Quoted 5 lines
Quoted 2 lines

And the type field should be checked in .s_crop() anyway, I think.

It is checked in soc_camera_s_crop() just a couple of lines above the snippet above. Or what do you mean?

Yes, you are right! Okay, then there is no need to check it again in the subdevice driver.

Thanks,

Anatolij