All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org
Subject: Re: V4L-DVB drivers and BKL
Date: Thu, 1 Apr 2010 11:23:30 +0200	[thread overview]
Message-ID: <201004011123.31080.laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <201004011001.10500.hverkuil@xs4all.nl>

Hi Hans,

On Thursday 01 April 2010 10:01:10 Hans Verkuil wrote:
> Hi all,
> 
> I just read on LWN that the core kernel guys are putting more effort into
> removing the BKL. We are still using it in our own drivers, mostly V4L.
> 
> I added a BKL column to my driver list:
> 
> http://www.linuxtv.org/wiki/index.php/V4L_framework_progress#Bridge_Drivers
> 
> If you 'own' one of these drivers that still use BKL, then it would be nice
> if you can try and remove the use of the BKL from those drivers.
> 
> The other part that needs to be done is to move from using the .ioctl file
> op to using .unlocked_ioctl. Very few drivers do that, but I suspect
> almost no driver actually needs to use .ioctl.

What about something like this patch as a first step ?

diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 7090699..14e1b1c 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -25,6 +25,7 @@
 #include <linux/init.h>
 #include <linux/kmod.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
@@ -215,28 +216,22 @@ static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
 	return vdev->fops->poll(filp, poll);
 }
 
-static int v4l2_ioctl(struct inode *inode, struct file *filp,
-		unsigned int cmd, unsigned long arg)
-{
-	struct video_device *vdev = video_devdata(filp);
-
-	if (!vdev->fops->ioctl)
-		return -ENOTTY;
-	/* Allow ioctl to continue even if the device was unregistered.
-	   Things like dequeueing buffers might still be useful. */
-	return vdev->fops->ioctl(filp, cmd, arg);
-}
-
 static long v4l2_unlocked_ioctl(struct file *filp,
 		unsigned int cmd, unsigned long arg)
 {
 	struct video_device *vdev = video_devdata(filp);
+	int ret = -ENOTTY;
 
-	if (!vdev->fops->unlocked_ioctl)
-		return -ENOTTY;
 	/* Allow ioctl to continue even if the device was unregistered.
 	   Things like dequeueing buffers might still be useful. */
-	return vdev->fops->unlocked_ioctl(filp, cmd, arg);
+	if (vdev->fops->ioctl) {
+		lock_kernel();
+		ret = vdev->fops->ioctl(filp, cmd, arg);
+		unlock_kernel();
+	} else if (vdev->fops->unlocked_ioctl)
+		ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
+
+	return ret;
 }
 
 #ifdef CONFIG_MMU
@@ -323,22 +318,6 @@ static const struct file_operations v4l2_unlocked_fops = {
 	.llseek = no_llseek,
 };
 
-static const struct file_operations v4l2_fops = {
-	.owner = THIS_MODULE,
-	.read = v4l2_read,
-	.write = v4l2_write,
-	.open = v4l2_open,
-	.get_unmapped_area = v4l2_get_unmapped_area,
-	.mmap = v4l2_mmap,
-	.ioctl = v4l2_ioctl,
-#ifdef CONFIG_COMPAT
-	.compat_ioctl = v4l2_compat_ioctl32,
-#endif
-	.release = v4l2_release,
-	.poll = v4l2_poll,
-	.llseek = no_llseek,
-};
-
 /**
  * get_index - assign stream index number based on parent device
  * @vdev: video_device to assign index number to, vdev->parent should be assigned
@@ -517,10 +496,7 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,
 		ret = -ENOMEM;
 		goto cleanup;
 	}
-	if (vdev->fops->unlocked_ioctl)
-		vdev->cdev->ops = &v4l2_unlocked_fops;
-	else
-		vdev->cdev->ops = &v4l2_fops;
+	vdev->cdev->ops = &v4l2_unlocked_fops;
 	vdev->cdev->owner = vdev->fops->owner;
 	ret = cdev_add(vdev->cdev, MKDEV(VIDEO_MAJOR, vdev->minor), 1);
 	if (ret < 0) {

A second step would be to replace lock_kernel/unlock_kernel with a
V4L-specific lock, and the third step to push the lock into drivers.

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2010-04-01  9:23 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-01  8:01 V4L-DVB drivers and BKL Hans Verkuil
2010-04-01  9:23 ` Laurent Pinchart [this message]
2010-04-01 11:11   ` Hans Verkuil
2010-04-01 12:11     ` Laurent Pinchart
2010-04-01 14:12       ` Mauro Carvalho Chehab
2010-04-01 14:30         ` Laurent Pinchart
2010-04-01 14:44           ` Mauro Carvalho Chehab
2010-04-01 14:42         ` Hans Verkuil
2010-04-01 15:02           ` Mauro Carvalho Chehab
2010-04-01 15:27             ` Hans Verkuil
2010-04-01 16:58             ` Devin Heitmueller
2010-04-01 17:36               ` Mauro Carvalho Chehab
2010-04-01 18:29                 ` Devin Heitmueller
2010-04-01 18:42                   ` Mauro Carvalho Chehab
2010-04-01 18:56                     ` Devin Heitmueller
2010-04-01 21:07                       ` Mauro Carvalho Chehab
2010-04-01 21:40                         ` Devin Heitmueller
2010-04-01 23:10                           ` Mauro Carvalho Chehab
2010-04-01 21:11                       ` Hans Verkuil
2010-04-01 21:06                   ` Hans Verkuil
2010-04-01 21:16                     ` Mauro Carvalho Chehab
2010-04-01 21:29                       ` Devin Heitmueller
2010-04-03  0:23                         ` Andy Walls
2010-04-07 20:07               ` [PATCH] em28xx: fix locks during dvb init sequence - was: " Mauro Carvalho Chehab
2010-04-07 20:15                 ` Devin Heitmueller
2010-04-07 20:23                   ` Mauro Carvalho Chehab
2010-04-01 11:57 ` Stefan Richter
2010-04-01 12:11   ` Hans Verkuil
2010-04-01 12:08 ` Stefan Richter
2010-04-01 12:12   ` Stefan Richter
2010-04-01 14:03 ` Mauro Carvalho Chehab
2010-04-03 14:19   ` Stefan Richter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201004011123.31080.laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.