linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Remove .ioctl from v4l2_file_operations
@ 2015-02-03 12:47 Hans Verkuil
  2015-02-03 12:47 ` [PATCH 1/5] pvrusb2: replace .ioctl by .unlocked_ioctl Hans Verkuil
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Hans Verkuil @ 2015-02-03 12:47 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart, isely, pali.rohar

All V4L2 drivers should use .unlocked_ioctl instead of .ioctl. There are
only three drivers left that do not do that: pvrusb2, radio-bcm2048 and
the uvc gadget driver.

The pvrusb2 driver does its own locking as far as I can tell, so it can
just switch to unlocked_ioctl. Ditto for radio-bcm2048.

The uvc gadget driver uses a lock for the queuing ioctls, but not for
g/s_format, so a new lock was added for that. In addition querycap
didn't set device_caps, so that was added as well (this will cause a
warning otherwise).

The last patch removes the old .ioctl op completely.

Regards,

	Hans


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

* [PATCH 1/5] pvrusb2: replace .ioctl by .unlocked_ioctl.
  2015-02-03 12:47 [PATCH 0/5] Remove .ioctl from v4l2_file_operations Hans Verkuil
@ 2015-02-03 12:47 ` Hans Verkuil
  2015-02-03 12:47 ` [PATCH 2/5] radio-bcm2048: use unlocked_ioctl instead of ioctl Hans Verkuil
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Hans Verkuil @ 2015-02-03 12:47 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart, isely, pali.rohar, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

As far as I can tell pvrusb2 does its own locking, so there is
no need to use .ioctl.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/usb/pvrusb2/pvrusb2-v4l2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
index 35e4ea5..91c1700 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
@@ -1247,7 +1247,7 @@ static const struct v4l2_file_operations vdev_fops = {
 	.open       = pvr2_v4l2_open,
 	.release    = pvr2_v4l2_release,
 	.read       = pvr2_v4l2_read,
-	.ioctl      = pvr2_v4l2_ioctl,
+	.unlocked_ioctl = pvr2_v4l2_ioctl,
 	.poll       = pvr2_v4l2_poll,
 };
 
-- 
2.1.4


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

* [PATCH 2/5] radio-bcm2048: use unlocked_ioctl instead of ioctl
  2015-02-03 12:47 [PATCH 0/5] Remove .ioctl from v4l2_file_operations Hans Verkuil
  2015-02-03 12:47 ` [PATCH 1/5] pvrusb2: replace .ioctl by .unlocked_ioctl Hans Verkuil
@ 2015-02-03 12:47 ` Hans Verkuil
  2015-02-03 13:01   ` Pali Rohár
  2015-02-03 12:47 ` [PATCH 3/5] uvc gadget: switch to unlocked_ioctl Hans Verkuil
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Hans Verkuil @ 2015-02-03 12:47 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart, isely, pali.rohar, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

This driver does its own locking, so there is no need to use
ioctl instead of unlocked_ioctl.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/staging/media/bcm2048/radio-bcm2048.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/bcm2048/radio-bcm2048.c b/drivers/staging/media/bcm2048/radio-bcm2048.c
index 5382506..512fa26 100644
--- a/drivers/staging/media/bcm2048/radio-bcm2048.c
+++ b/drivers/staging/media/bcm2048/radio-bcm2048.c
@@ -2274,7 +2274,7 @@ done:
  */
 static const struct v4l2_file_operations bcm2048_fops = {
 	.owner		= THIS_MODULE,
-	.ioctl		= video_ioctl2,
+	.unlocked_ioctl	= video_ioctl2,
 	/* for RDS read support */
 	.open		= bcm2048_fops_open,
 	.release	= bcm2048_fops_release,
-- 
2.1.4


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

* [PATCH 3/5] uvc gadget: switch to unlocked_ioctl.
  2015-02-03 12:47 [PATCH 0/5] Remove .ioctl from v4l2_file_operations Hans Verkuil
  2015-02-03 12:47 ` [PATCH 1/5] pvrusb2: replace .ioctl by .unlocked_ioctl Hans Verkuil
  2015-02-03 12:47 ` [PATCH 2/5] radio-bcm2048: use unlocked_ioctl instead of ioctl Hans Verkuil
@ 2015-02-03 12:47 ` Hans Verkuil
  2015-02-03 13:55   ` Laurent Pinchart
  2015-02-03 12:47 ` [PATCH 4/5] uvc gadget: set device_caps in querycap Hans Verkuil
  2015-02-03 12:47 ` [PATCH 5/5] v4l2-core: remove the old .ioctl BKL replacement Hans Verkuil
  4 siblings, 1 reply; 11+ messages in thread
From: Hans Verkuil @ 2015-02-03 12:47 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart, isely, pali.rohar, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Instead of .ioctl use unlocked_ioctl. While all the queue ops
already use a lock, there was no lock to protect uvc_video, so
add that one.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/usb/gadget/function/f_uvc.c    | 1 +
 drivers/usb/gadget/function/uvc.h      | 1 +
 drivers/usb/gadget/function/uvc_v4l2.c | 6 +++++-
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
index 945b3bd..748a80c 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -817,6 +817,7 @@ static struct usb_function *uvc_alloc(struct usb_function_instance *fi)
 	if (uvc == NULL)
 		return ERR_PTR(-ENOMEM);
 
+	mutex_init(&uvc->video.mutex);
 	uvc->state = UVC_STATE_DISCONNECTED;
 	opts = to_f_uvc_opts(fi);
 
diff --git a/drivers/usb/gadget/function/uvc.h b/drivers/usb/gadget/function/uvc.h
index f67695c..3390ecd 100644
--- a/drivers/usb/gadget/function/uvc.h
+++ b/drivers/usb/gadget/function/uvc.h
@@ -115,6 +115,7 @@ struct uvc_video
 	unsigned int width;
 	unsigned int height;
 	unsigned int imagesize;
+	struct mutex mutex;	/* protects frame parameters */
 
 	/* Requests */
 	unsigned int req_size;
diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index 5aad7fe..67f084f 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -88,6 +88,7 @@ uvc_v4l2_get_format(struct file *file, void *fh, struct v4l2_format *fmt)
 	struct uvc_device *uvc = video_get_drvdata(vdev);
 	struct uvc_video *video = &uvc->video;
 
+	mutex_lock(&video->mutex);
 	fmt->fmt.pix.pixelformat = video->fcc;
 	fmt->fmt.pix.width = video->width;
 	fmt->fmt.pix.height = video->height;
@@ -96,6 +97,7 @@ uvc_v4l2_get_format(struct file *file, void *fh, struct v4l2_format *fmt)
 	fmt->fmt.pix.sizeimage = video->imagesize;
 	fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
 	fmt->fmt.pix.priv = 0;
+	mutex_unlock(&video->mutex);
 
 	return 0;
 }
@@ -126,11 +128,13 @@ uvc_v4l2_set_format(struct file *file, void *fh, struct v4l2_format *fmt)
 	bpl = format->bpp * fmt->fmt.pix.width / 8;
 	imagesize = bpl ? bpl * fmt->fmt.pix.height : fmt->fmt.pix.sizeimage;
 
+	mutex_lock(&video->mutex);
 	video->fcc = format->fcc;
 	video->bpp = format->bpp;
 	video->width = fmt->fmt.pix.width;
 	video->height = fmt->fmt.pix.height;
 	video->imagesize = imagesize;
+	mutex_unlock(&video->mutex);
 
 	fmt->fmt.pix.field = V4L2_FIELD_NONE;
 	fmt->fmt.pix.bytesperline = bpl;
@@ -356,7 +360,7 @@ struct v4l2_file_operations uvc_v4l2_fops = {
 	.owner		= THIS_MODULE,
 	.open		= uvc_v4l2_open,
 	.release	= uvc_v4l2_release,
-	.ioctl		= video_ioctl2,
+	.unlocked_ioctl	= video_ioctl2,
 	.mmap		= uvc_v4l2_mmap,
 	.poll		= uvc_v4l2_poll,
 #ifndef CONFIG_MMU
-- 
2.1.4


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

* [PATCH 4/5] uvc gadget: set device_caps in querycap.
  2015-02-03 12:47 [PATCH 0/5] Remove .ioctl from v4l2_file_operations Hans Verkuil
                   ` (2 preceding siblings ...)
  2015-02-03 12:47 ` [PATCH 3/5] uvc gadget: switch to unlocked_ioctl Hans Verkuil
@ 2015-02-03 12:47 ` Hans Verkuil
  2015-02-03 13:44   ` Laurent Pinchart
  2015-02-03 12:47 ` [PATCH 5/5] v4l2-core: remove the old .ioctl BKL replacement Hans Verkuil
  4 siblings, 1 reply; 11+ messages in thread
From: Hans Verkuil @ 2015-02-03 12:47 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart, isely, pali.rohar, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

The V4L2 core will warn if this is not done. Unfortunately this driver
wasn't updated.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/usb/gadget/function/uvc_v4l2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index 67f084f..3207b3e 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -76,7 +76,8 @@ uvc_v4l2_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
 	strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev),
 		sizeof(cap->bus_info));
 
-	cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
+	cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
+	cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
 
 	return 0;
 }
-- 
2.1.4


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

* [PATCH 5/5] v4l2-core: remove the old .ioctl BKL replacement
  2015-02-03 12:47 [PATCH 0/5] Remove .ioctl from v4l2_file_operations Hans Verkuil
                   ` (3 preceding siblings ...)
  2015-02-03 12:47 ` [PATCH 4/5] uvc gadget: set device_caps in querycap Hans Verkuil
@ 2015-02-03 12:47 ` Hans Verkuil
  4 siblings, 0 replies; 11+ messages in thread
From: Hans Verkuil @ 2015-02-03 12:47 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart, isely, pali.rohar, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

To keep V4L2 drivers that did not yet convert to unlocked_ioctl happy,
the v4l2 core had a .ioctl file operation that took a V4L2 lock.

The last drivers are now converted to unlocked_ioctl, so all this
old code can now be removed.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/v4l2-core/v4l2-dev.c    | 28 ----------------------------
 drivers/media/v4l2-core/v4l2-device.c |  1 -
 include/media/v4l2-dev.h              |  1 -
 include/media/v4l2-device.h           |  2 --
 4 files changed, 32 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 86bb93f..276a0d8 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -357,34 +357,6 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 			ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
 		if (lock)
 			mutex_unlock(lock);
-	} else if (vdev->fops->ioctl) {
-		/* This code path is a replacement for the BKL. It is a major
-		 * hack but it will have to do for those drivers that are not
-		 * yet converted to use unlocked_ioctl.
-		 *
-		 * All drivers implement struct v4l2_device, so we use the
-		 * lock defined there to serialize the ioctls.
-		 *
-		 * However, if the driver sleeps, then it blocks all ioctls
-		 * since the lock is still held. This is very common for
-		 * VIDIOC_DQBUF since that normally waits for a frame to arrive.
-		 * As a result any other ioctl calls will proceed very, very
-		 * slowly since each call will have to wait for the VIDIOC_QBUF
-		 * to finish. Things that should take 0.01s may now take 10-20
-		 * seconds.
-		 *
-		 * The workaround is to *not* take the lock for VIDIOC_DQBUF.
-		 * This actually works OK for videobuf-based drivers, since
-		 * videobuf will take its own internal lock.
-		 */
-		struct mutex *m = &vdev->v4l2_dev->ioctl_lock;
-
-		if (cmd != VIDIOC_DQBUF && mutex_lock_interruptible(m))
-			return -ERESTARTSYS;
-		if (video_is_registered(vdev))
-			ret = vdev->fops->ioctl(filp, cmd, arg);
-		if (cmd != VIDIOC_DQBUF)
-			mutex_unlock(m);
 	} else
 		ret = -ENOTTY;
 
diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index 015f92a..e4d40cf 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -37,7 +37,6 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
 
 	INIT_LIST_HEAD(&v4l2_dev->subdevs);
 	spin_lock_init(&v4l2_dev->lock);
-	mutex_init(&v4l2_dev->ioctl_lock);
 	v4l2_prio_init(&v4l2_dev->prio);
 	kref_init(&v4l2_dev->ref);
 	get_device(dev);
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 3e4fddf..acbcd2f 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -65,7 +65,6 @@ struct v4l2_file_operations {
 	ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
 	ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
 	unsigned int (*poll) (struct file *, struct poll_table_struct *);
-	long (*ioctl) (struct file *, unsigned int, unsigned long);
 	long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
 #ifdef CONFIG_COMPAT
 	long (*compat_ioctl32) (struct file *, unsigned int, unsigned long);
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
index ffb69da..9c58157 100644
--- a/include/media/v4l2-device.h
+++ b/include/media/v4l2-device.h
@@ -58,8 +58,6 @@ struct v4l2_device {
 	struct v4l2_ctrl_handler *ctrl_handler;
 	/* Device's priority state */
 	struct v4l2_prio_state prio;
-	/* BKL replacement mutex. Temporary solution only. */
-	struct mutex ioctl_lock;
 	/* Keep track of the references to this struct. */
 	struct kref ref;
 	/* Release function that is called when the ref count goes to 0. */
-- 
2.1.4


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

* Re: [PATCH 2/5] radio-bcm2048: use unlocked_ioctl instead of ioctl
  2015-02-03 12:47 ` [PATCH 2/5] radio-bcm2048: use unlocked_ioctl instead of ioctl Hans Verkuil
@ 2015-02-03 13:01   ` Pali Rohár
  0 siblings, 0 replies; 11+ messages in thread
From: Pali Rohár @ 2015-02-03 13:01 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, laurent.pinchart, isely, Hans Verkuil

[-- Attachment #1: Type: Text/Plain, Size: 372 bytes --]

On Tuesday 03 February 2015 13:47:23 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> This driver does its own locking, so there is no need to use
> ioctl instead of unlocked_ioctl.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

Looks good,
Acked-by: Pali Rohár <pali.rohar@gmail.com>

-- 
Pali Rohár
pali.rohar@gmail.com

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: [PATCH 4/5] uvc gadget: set device_caps in querycap.
  2015-02-03 12:47 ` [PATCH 4/5] uvc gadget: set device_caps in querycap Hans Verkuil
@ 2015-02-03 13:44   ` Laurent Pinchart
  0 siblings, 0 replies; 11+ messages in thread
From: Laurent Pinchart @ 2015-02-03 13:44 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, isely, pali.rohar, Hans Verkuil

Hi Hans,

Thank you for the patch.

On Tuesday 03 February 2015 13:47:25 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> The V4L2 core will warn if this is not done. Unfortunately this driver
> wasn't updated.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/usb/gadget/function/uvc_v4l2.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/function/uvc_v4l2.c
> b/drivers/usb/gadget/function/uvc_v4l2.c index 67f084f..3207b3e 100644
> --- a/drivers/usb/gadget/function/uvc_v4l2.c
> +++ b/drivers/usb/gadget/function/uvc_v4l2.c
> @@ -76,7 +76,8 @@ uvc_v4l2_querycap(struct file *file, void *fh, struct
> v4l2_capability *cap) strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev),
>  		sizeof(cap->bus_info));
> 
> -	cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
> +	cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
> +	cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
> 
>  	return 0;
>  }

-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH 3/5] uvc gadget: switch to unlocked_ioctl.
  2015-02-03 12:47 ` [PATCH 3/5] uvc gadget: switch to unlocked_ioctl Hans Verkuil
@ 2015-02-03 13:55   ` Laurent Pinchart
  2015-02-16 15:11     ` Hans Verkuil
  0 siblings, 1 reply; 11+ messages in thread
From: Laurent Pinchart @ 2015-02-03 13:55 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, isely, pali.rohar, Hans Verkuil

Hi Hans,

Thank you for the patch.

On Tuesday 03 February 2015 13:47:24 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Instead of .ioctl use unlocked_ioctl. While all the queue ops
> already use a lock, there was no lock to protect uvc_video, so
> add that one.

There's more. streamon and streamoff need to be protected by a lock for 
instance. Wouldn't it be easier to just set vdev->lock for this driver instead 
of adding manual locking ?

> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
>  drivers/usb/gadget/function/f_uvc.c    | 1 +
>  drivers/usb/gadget/function/uvc.h      | 1 +
>  drivers/usb/gadget/function/uvc_v4l2.c | 6 +++++-
>  3 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/function/f_uvc.c
> b/drivers/usb/gadget/function/f_uvc.c index 945b3bd..748a80c 100644
> --- a/drivers/usb/gadget/function/f_uvc.c
> +++ b/drivers/usb/gadget/function/f_uvc.c
> @@ -817,6 +817,7 @@ static struct usb_function *uvc_alloc(struct
> usb_function_instance *fi) if (uvc == NULL)
>  		return ERR_PTR(-ENOMEM);
> 
> +	mutex_init(&uvc->video.mutex);

We need a corresponding mutex_destroy() somewhere.

>  	uvc->state = UVC_STATE_DISCONNECTED;
>  	opts = to_f_uvc_opts(fi);
> 
> diff --git a/drivers/usb/gadget/function/uvc.h
> b/drivers/usb/gadget/function/uvc.h index f67695c..3390ecd 100644
> --- a/drivers/usb/gadget/function/uvc.h
> +++ b/drivers/usb/gadget/function/uvc.h
> @@ -115,6 +115,7 @@ struct uvc_video
>  	unsigned int width;
>  	unsigned int height;
>  	unsigned int imagesize;
> +	struct mutex mutex;	/* protects frame parameters */
> 
>  	/* Requests */
>  	unsigned int req_size;
> diff --git a/drivers/usb/gadget/function/uvc_v4l2.c
> b/drivers/usb/gadget/function/uvc_v4l2.c index 5aad7fe..67f084f 100644
> --- a/drivers/usb/gadget/function/uvc_v4l2.c
> +++ b/drivers/usb/gadget/function/uvc_v4l2.c
> @@ -88,6 +88,7 @@ uvc_v4l2_get_format(struct file *file, void *fh, struct
> v4l2_format *fmt) struct uvc_device *uvc = video_get_drvdata(vdev);
>  	struct uvc_video *video = &uvc->video;
> 
> +	mutex_lock(&video->mutex);
>  	fmt->fmt.pix.pixelformat = video->fcc;
>  	fmt->fmt.pix.width = video->width;
>  	fmt->fmt.pix.height = video->height;
> @@ -96,6 +97,7 @@ uvc_v4l2_get_format(struct file *file, void *fh, struct
> v4l2_format *fmt) fmt->fmt.pix.sizeimage = video->imagesize;
>  	fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
>  	fmt->fmt.pix.priv = 0;
> +	mutex_unlock(&video->mutex);
> 
>  	return 0;
>  }
> @@ -126,11 +128,13 @@ uvc_v4l2_set_format(struct file *file, void *fh,
> struct v4l2_format *fmt) bpl = format->bpp * fmt->fmt.pix.width / 8;
>  	imagesize = bpl ? bpl * fmt->fmt.pix.height : fmt->fmt.pix.sizeimage;
> 
> +	mutex_lock(&video->mutex);
>  	video->fcc = format->fcc;
>  	video->bpp = format->bpp;
>  	video->width = fmt->fmt.pix.width;
>  	video->height = fmt->fmt.pix.height;
>  	video->imagesize = imagesize;
> +	mutex_unlock(&video->mutex);
> 
>  	fmt->fmt.pix.field = V4L2_FIELD_NONE;
>  	fmt->fmt.pix.bytesperline = bpl;
> @@ -356,7 +360,7 @@ struct v4l2_file_operations uvc_v4l2_fops = {
>  	.owner		= THIS_MODULE,
>  	.open		= uvc_v4l2_open,
>  	.release	= uvc_v4l2_release,
> -	.ioctl		= video_ioctl2,
> +	.unlocked_ioctl	= video_ioctl2,
>  	.mmap		= uvc_v4l2_mmap,
>  	.poll		= uvc_v4l2_poll,
>  #ifndef CONFIG_MMU

-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH 3/5] uvc gadget: switch to unlocked_ioctl.
  2015-02-03 13:55   ` Laurent Pinchart
@ 2015-02-16 15:11     ` Hans Verkuil
  2015-02-16 20:15       ` Laurent Pinchart
  0 siblings, 1 reply; 11+ messages in thread
From: Hans Verkuil @ 2015-02-16 15:11 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: linux-media, isely, pali.rohar, Hans Verkuil

On 02/03/2015 02:55 PM, Laurent Pinchart wrote:
> Hi Hans,
> 
> Thank you for the patch.
> 
> On Tuesday 03 February 2015 13:47:24 Hans Verkuil wrote:
>> From: Hans Verkuil <hans.verkuil@cisco.com>
>>
>> Instead of .ioctl use unlocked_ioctl. While all the queue ops
>> already use a lock, there was no lock to protect uvc_video, so
>> add that one.
> 
> There's more. streamon and streamoff need to be protected by a lock for 
> instance. Wouldn't it be easier to just set vdev->lock for this driver instead 
> of adding manual locking ?

I could set vdev->lock to &video->mutex and remove the queue->mutex
altogether since video->mutex will now be used for all locking. I only
need to take the video->mutex in uvc_v4l2_release() as well.

If you agree with that, then I'll make that change.

> 
>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
>> ---
>>  drivers/usb/gadget/function/f_uvc.c    | 1 +
>>  drivers/usb/gadget/function/uvc.h      | 1 +
>>  drivers/usb/gadget/function/uvc_v4l2.c | 6 +++++-
>>  3 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/gadget/function/f_uvc.c
>> b/drivers/usb/gadget/function/f_uvc.c index 945b3bd..748a80c 100644
>> --- a/drivers/usb/gadget/function/f_uvc.c
>> +++ b/drivers/usb/gadget/function/f_uvc.c
>> @@ -817,6 +817,7 @@ static struct usb_function *uvc_alloc(struct
>> usb_function_instance *fi) if (uvc == NULL)
>>  		return ERR_PTR(-ENOMEM);
>>
>> +	mutex_init(&uvc->video.mutex);
> 
> We need a corresponding mutex_destroy() somewhere.

Why? Few drivers do so. If you want it, then I'll do that, but it's not
required to my knowledge.

Regards,

	Hans

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

* Re: [PATCH 3/5] uvc gadget: switch to unlocked_ioctl.
  2015-02-16 15:11     ` Hans Verkuil
@ 2015-02-16 20:15       ` Laurent Pinchart
  0 siblings, 0 replies; 11+ messages in thread
From: Laurent Pinchart @ 2015-02-16 20:15 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, isely, pali.rohar, Hans Verkuil

Hi Hans,

On Monday 16 February 2015 16:11:55 Hans Verkuil wrote:
> On 02/03/2015 02:55 PM, Laurent Pinchart wrote:
> > On Tuesday 03 February 2015 13:47:24 Hans Verkuil wrote:
> >> From: Hans Verkuil <hans.verkuil@cisco.com>
> >> 
> >> Instead of .ioctl use unlocked_ioctl. While all the queue ops
> >> already use a lock, there was no lock to protect uvc_video, so
> >> add that one.
> > 
> > There's more. streamon and streamoff need to be protected by a lock for
> > instance. Wouldn't it be easier to just set vdev->lock for this driver
> > instead of adding manual locking ?
> 
> I could set vdev->lock to &video->mutex and remove the queue->mutex
> altogether since video->mutex will now be used for all locking. I only
> need to take the video->mutex in uvc_v4l2_release() as well.
> 
> If you agree with that, then I'll make that change.

That sounds good to me. I haven't really tried to optimize locking in the UVC 
gadget driver, so relying on core locking is fine. Could you split that in two 
patches, one that switches to core locking, and another that switches to 
unlocked_ioctl ?

> >> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> >> ---
> >> 
> >>  drivers/usb/gadget/function/f_uvc.c    | 1 +
> >>  drivers/usb/gadget/function/uvc.h      | 1 +
> >>  drivers/usb/gadget/function/uvc_v4l2.c | 6 +++++-
> >>  3 files changed, 7 insertions(+), 1 deletion(-)
> >> 
> >> diff --git a/drivers/usb/gadget/function/f_uvc.c
> >> b/drivers/usb/gadget/function/f_uvc.c index 945b3bd..748a80c 100644
> >> --- a/drivers/usb/gadget/function/f_uvc.c
> >> +++ b/drivers/usb/gadget/function/f_uvc.c
> >> @@ -817,6 +817,7 @@ static struct usb_function *uvc_alloc(struct
> >> usb_function_instance *fi) if (uvc == NULL)
> >> 
> >>  		return ERR_PTR(-ENOMEM);
> >> 
> >> +	mutex_init(&uvc->video.mutex);
> > 
> > We need a corresponding mutex_destroy() somewhere.
> 
> Why? Few drivers do so. If you want it, then I'll do that, but it's not
> required to my knowledge.

I somehow thought mutex_destroy() was required to avoid leakages when mutex 
debugging is enabled, but it turns out I'm wrong. Omitting it thus seems fine.

-- 
Regards,

Laurent Pinchart


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

end of thread, other threads:[~2015-02-16 20:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-03 12:47 [PATCH 0/5] Remove .ioctl from v4l2_file_operations Hans Verkuil
2015-02-03 12:47 ` [PATCH 1/5] pvrusb2: replace .ioctl by .unlocked_ioctl Hans Verkuil
2015-02-03 12:47 ` [PATCH 2/5] radio-bcm2048: use unlocked_ioctl instead of ioctl Hans Verkuil
2015-02-03 13:01   ` Pali Rohár
2015-02-03 12:47 ` [PATCH 3/5] uvc gadget: switch to unlocked_ioctl Hans Verkuil
2015-02-03 13:55   ` Laurent Pinchart
2015-02-16 15:11     ` Hans Verkuil
2015-02-16 20:15       ` Laurent Pinchart
2015-02-03 12:47 ` [PATCH 4/5] uvc gadget: set device_caps in querycap Hans Verkuil
2015-02-03 13:44   ` Laurent Pinchart
2015-02-03 12:47 ` [PATCH 5/5] v4l2-core: remove the old .ioctl BKL replacement Hans Verkuil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).