BKL removal
Subsystems (8)
v2 cover BKL removal
This is my second patch series for the BKL removal project.
While this series is against the v2.6.38 staging tree I think it would be good to target 2.6.37 instead. A lot of files are changed, but the changes are all trivial. And this will hopefully take care of most of the BKL removal problems, except for uvc.
This patch also contains the improved core locking patch which doesn't lock the VIDIOC_DQBUF ioctl.
Regards,
Hans
Hans Verkuil (15):
v4l2-dev: use mutex_lock_interruptible instead of plain mutex_lock
BKL: trivial BKL removal from V4L2 radio drivers
cadet: use unlocked_ioctl
tea5764: convert to unlocked_ioctl
si4713: convert to unlocked_ioctl
typhoon: convert to unlocked_ioctl.
dsbr100: convert to unlocked_ioctl.
BKL: trivial ioctl -> unlocked_ioctl video driver conversions
sn9c102: convert to unlocked_ioctl.
et61x251_core: trivial conversion to unlocked_ioctl.
cafe_ccic: replace ioctl by unlocked_ioctl.
sh_vou: convert to unlocked_ioctl.
radio-timb: convert to unlocked_ioctl.
V4L: improve the BKL replacement heuristic
cx18: convert to unlocked_ioctl.
drivers/media/radio/dsbr100.c | 2 +- drivers/media/radio/radio-aimslab.c | 16 +++--- drivers/media/radio/radio-aztech.c | 6 +- drivers/media/radio/radio-cadet.c | 12 +++- drivers/media/radio/radio-gemtek-pci.c | 6 +- drivers/media/radio/radio-gemtek.c | 14 ++-- drivers/media/radio/radio-maestro.c | 14 ++--- drivers/media/radio/radio-maxiradio.c | 2 +- drivers/media/radio/radio-miropcm20.c | 6 +- drivers/media/radio/radio-rtrack2.c | 10 ++-- drivers/media/radio/radio-sf16fmi.c | 7 +- drivers/media/radio/radio-sf16fmr2.c | 11 ++-- drivers/media/radio/radio-si4713.c | 3 +- drivers/media/radio/radio-tea5764.c | 49 +++------------- drivers/media/radio/radio-terratec.c | 8 +- drivers/media/radio/radio-timb.c | 5 +- drivers/media/radio/radio-trust.c | 18 +++--- drivers/media/radio/radio-typhoon.c | 16 +++--- drivers/media/radio/radio-zoltrix.c | 30 +++++----- drivers/media/video/arv.c | 2 +- drivers/media/video/bw-qcam.c | 2 +- drivers/media/video/c-qcam.c | 2 +- drivers/media/video/cafe_ccic.c | 2 +- drivers/media/video/cx18/cx18-streams.c | 2 +- drivers/media/video/et61x251/et61x251_core.c | 2 +- drivers/media/video/meye.c | 14 ++-- drivers/media/video/pms.c | 2 +- drivers/media/video/sh_vou.c | 13 +++-- drivers/media/video/sn9c102/sn9c102_core.c | 2 +- drivers/media/video/v4l2-dev.c | 81 +++++++++++++++++++++----- drivers/media/video/v4l2-device.c | 1 + drivers/media/video/w9966.c | 2 +- include/media/v4l2-dev.h | 2 +- include/media/v4l2-device.h | 2 + 34 files changed, 201 insertions(+), 165 deletions(-)
RFC PATCH v2 1/15 v4l2-dev: use mutex_lock_interruptible instead of plain mutex_lock
Where reasonable use mutex_lock_interruptible instead of mutex_lock.
--- drivers/media/video/v4l2-dev.c | 44 +++++++++++++++++++++++++++++---------- 1 files changed, 32 insertions(+), 12 deletions(-)
drivers/media/video/v4l2-dev.c +32 -12
@@ -191,8 +191,12 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf,if (!vdev->fops->read)return -EINVAL ; -if (vdev->lock) -mutex_lock (vdev->lock); +if (vdev->lock) { +int res =mutex_lock_interruptible (vdev->lock); + +if (res) +return res; + }if (video_is_registered (vdev)) ret = vdev->fops->read (filp, buf, sz, off);if (vdev->lock)
@@ -208,8 +212,12 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf,if (!vdev->fops->write)return -EINVAL ; -if (vdev->lock) -mutex_lock (vdev->lock); +if (vdev->lock) { +int res =mutex_lock_interruptible (vdev->lock); + +if (res) +return res; + }if (video_is_registered (vdev)) ret = vdev->fops->write (filp, buf, sz, off);if (vdev->lock)
@@ -224,8 +232,8 @@ static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)if (!vdev->fops->poll)return ret; -if (vdev->lock) -mutex_lock (vdev->lock); +if (vdev->lock &&mutex_lock_interruptible (vdev->lock)) +return ret;if (video_is_registered (vdev)) ret = vdev->fops->poll (filp, poll);if (vdev->lock)
@@ -239,8 +247,12 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)int ret = -ENODEV ;if (vdev->fops->unlocked_ioctl) { -if (vdev->lock) -mutex_lock (vdev->lock); +if (vdev->lock) { +int res =mutex_lock_interruptible (vdev->lock); + +if (res) +return res; + }if (video_is_registered (vdev)) ret = vdev->fops->unlocked_ioctl (filp, cmd, arg);if (vdev->lock)
@@ -264,8 +276,12 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)if (!vdev->fops->mmap)return ret; -if (vdev->lock) -mutex_lock (vdev->lock); +if (vdev->lock) { +int res =mutex_lock_interruptible (vdev->lock); + +if (res) +return res; + }if (video_is_registered (vdev)) ret = vdev->fops->mmap (filp, vm);if (vdev->lock)
@@ -291,8 +307,11 @@ static int v4l2_open(struct inode *inode, struct file *filp)video_get (vdev);mutex_unlock (&videodev_lock);if (vdev->fops->open) { -if (vdev->lock) -mutex_lock (vdev->lock); +if (vdev->lock) { + ret =mutex_lock_interruptible (vdev->lock); +if (ret) + goto err; + }if (video_is_registered (vdev)) ret = vdev->fops->open (filp);else
@@ -301,6 +320,7 @@ static int v4l2_open(struct inode *inode, struct file *filp)mutex_unlock (vdev->lock); } +err:/* decrease the refcount in case of an error */ if (ret)video_put (vdev);
Signature · 1 line
1.7.0.4
Re: [RFCv2 PATCH 01/15] v4l2-dev: use mutex_lock_interruptible instead of plain mutex_lock
Quoted 3 lines · On Tuesday 16 November 2010 22:55:32 Hans Verkuil wrote:
Where reasonable use
mutex_lock_interruptibleinstead ofmutex_lock.Signed-off-by Hans Verkuil <[email protected]>
RFC PATCH v2 2/15 BKL: trivial BKL removal from V4L2 radio drivers
In reply to Hans VerkuilThe patch converts a bunch of V4L2 radio drivers to unlocked_ioctl.
These are all simple conversions: most already had a lock and so the ioctl fop could simply be replaced by unlocked_ioctl.
radio-miropcm20.c was converted to use the new V4L2 core lock.
While doing this work I noticed that many of these drivers initialized some more fields or muted audio or something like that *after* creating the device node. This should be done before the device node is created to prevent problems. Especially hal tends to grab a device node as soon as it is created.
In one or two cases the mutex_init was even done after the device creation!
--- drivers/media/radio/radio-aimslab.c | 16 ++++++++-------- drivers/media/radio/radio-aztech.c | 6 +++--- drivers/media/radio/radio-gemtek-pci.c | 6 +++--- drivers/media/radio/radio-gemtek.c | 14 +++++++------- drivers/media/radio/radio-maestro.c | 14 ++++++-------- drivers/media/radio/radio-maxiradio.c | 2 +- drivers/media/radio/radio-miropcm20.c | 6 ++++-- drivers/media/radio/radio-rtrack2.c | 10 +++++----- drivers/media/radio/radio-sf16fmi.c | 7 ++++--- drivers/media/radio/radio-sf16fmr2.c | 11 +++++------ drivers/media/radio/radio-terratec.c | 8 ++++---- drivers/media/radio/radio-trust.c | 18 +++++++++--------- drivers/media/radio/radio-zoltrix.c | 30 +++++++++++++++--------------- 13 files changed, 74 insertions(+), 74 deletions(-)
drivers/media/radio/radio-aimslab.c +8 -8
@@ -361,7 +361,7 @@ static int vidioc_s_audio(struct file *file, void *priv,static const struct v4l2_file_operations rtrack_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops rtrack_ioctl_ops = {
@@ -412,13 +412,6 @@ static int __init rtrack_init(void) rt->vdev.release = video_device_release_empty;video_set_drvdata (&rt->vdev, rt); -if (video_register_device (&rt->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) { -v4l2_device_unregister (&rt->v4l2_dev); -release_region (rt->io,2 ); -return -EINVAL ; - } -v4l2_info (v4l2_dev,"AIMSlab RadioTrack/RadioReveal card driver.\n" ); -/* Set up the I/O locking */ mutex_init (&rt->lock);
@@ -430,6 +423,13 @@ static int __init rtrack_init(void)sleep_delay (2000000 );/* make sure it's totally down */ outb (0xc0 , rt->io);/* steady volume, mute card */ +if (video_register_device (&rt->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) { +v4l2_device_unregister (&rt->v4l2_dev); +release_region (rt->io,2 ); +return -EINVAL ; + } +v4l2_info (v4l2_dev,"AIMSlab RadioTrack/RadioReveal card driver.\n" ); +return 0 ; }
drivers/media/radio/radio-aztech.c +3 -3
@@ -324,7 +324,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,static const struct v4l2_file_operations aztech_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops aztech_ioctl_ops = {
@@ -375,6 +375,8 @@ static int __init aztech_init(void) az->vdev.ioctl_ops = &aztech_ioctl_ops; az->vdev.release = video_device_release_empty;video_set_drvdata (&az->vdev, az); +/* mute card - prevents noisy bootups */ +outb (0 , az->io);if (video_register_device (&az->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) {v4l2_device_unregister (v4l2_dev);
@@ -383,8 +385,6 @@ static int __init aztech_init(void) }v4l2_info (v4l2_dev,"Aztech radio card driver v1.00/19990224 [email protected]\n" ); -/* mute card - prevents noisy bootups */ -outb (0 , az->io);return 0 ; }
drivers/media/radio/radio-gemtek-pci.c +3 -3
@@ -361,7 +361,7 @@ MODULE_DEVICE_TABLE(pci, gemtek_pci_id);static const struct v4l2_file_operations gemtek_pci_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = {
@@ -422,11 +422,11 @@ static int __devinit gemtek_pci_probe(struct pci_dev *pdev, const struct pci_dev card->vdev.release = video_device_release_empty;video_set_drvdata (&card->vdev, card); +gemtek_pci_mute (card); +if (video_register_device (&card->vdev,VFL_TYPE_RADIO , nr_radio) <0 ) goto err_video; -gemtek_pci_mute (card); -v4l2_info (v4l2_dev,"Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n" , pdev->revision, card->iobase, card->iobase + card->length -1 );
drivers/media/radio/radio-gemtek.c +7 -7
@@ -378,7 +378,7 @@ static int gemtek_probe(struct gemtek *gt)static const struct v4l2_file_operations gemtek_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, }; static int vidioc_querycap(struct file *file, void *priv,
@@ -577,12 +577,6 @@ static int __init gemtek_init(void) gt->vdev.release = video_device_release_empty;video_set_drvdata (>->vdev, gt); -if (video_register_device (>->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) { -v4l2_device_unregister (v4l2_dev); -release_region (gt->io,1 ); -return -EBUSY ; - } -/* Set defaults */ gt->lastfreq =GEMTEK_LOWFREQ ; gt->bu2614data =0 ;
@@ -590,6 +584,12 @@ static int __init gemtek_init(void)if (initmute)gemtek_mute (gt); +if (video_register_device (>->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) { +v4l2_device_unregister (v4l2_dev); +release_region (gt->io,1 ); +return -EBUSY ; + } +return 0 ; }
drivers/media/radio/radio-maestro.c +6 -8
@@ -299,7 +299,7 @@ static int vidioc_s_audio(struct file *file, void *priv,static const struct v4l2_file_operations maestro_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops maestro_ioctl_ops = {
@@ -383,22 +383,20 @@ static int __devinit maestro_probe(struct pci_dev *pdev, dev->vdev.release = video_device_release_empty;video_set_drvdata (&dev->vdev, dev); +if (!radio_power_on (dev)) { + retval = -EIO ; + goto errfr1; + } + retval =video_register_device (&dev->vdev,VFL_TYPE_RADIO , radio_nr);if (retval) {v4l2_err (v4l2_dev,"can't register video device!\n" ); goto errfr1; } -if (!radio_power_on (dev)) { - retval = -EIO ; - goto errunr; - } -v4l2_info (v4l2_dev,"version " DRIVER_VERSION "\n" );return 0 ; -errunr: -video_unregister_device (&dev->vdev); errfr1:v4l2_device_unregister (v4l2_dev); errfr:
drivers/media/radio/radio-maxiradio.c +1 -1
@@ -346,7 +346,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,static const struct v4l2_file_operations maxiradio_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = {
drivers/media/radio/radio-miropcm20.c +4 -2
@@ -33,6 +33,7 @@ struct pcm20 {unsigned long freq;int muted;struct snd_miro_aci *aci; +struct mutex lock; };static struct pcm20 pcm20_card = {
@@ -72,7 +73,7 @@ static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq)static const struct v4l2_file_operations pcm20_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, }; static int vidioc_querycap(struct file *file, void *priv,
@@ -229,7 +230,7 @@ static int __init pcm20_init(void)return -ENODEV ; }strlcpy (v4l2_dev->name,"miropcm20" ,sizeof (v4l2_dev->name)); - +mutex_init (&dev->lock); res =v4l2_device_register (NULL , v4l2_dev);if (res <0 ) {
@@ -242,6 +243,7 @@ static int __init pcm20_init(void) dev->vdev.fops = &pcm20_fops; dev->vdev.ioctl_ops = &pcm20_ioctl_ops; dev->vdev.release = video_device_release_empty; + dev->vdev.lock = &dev->lock;video_set_drvdata (&dev->vdev, dev);if (video_register_device (&dev->vdev,VFL_TYPE_RADIO , radio_nr) <0 )
drivers/media/radio/radio-rtrack2.c +5 -5
@@ -266,7 +266,7 @@ static int vidioc_s_audio(struct file *file, void *priv,static const struct v4l2_file_operations rtrack2_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops rtrack2_ioctl_ops = {
@@ -315,6 +315,10 @@ static int __init rtrack2_init(void) dev->vdev.release = video_device_release_empty;video_set_drvdata (&dev->vdev, dev); +/* mute card - prevents noisy bootups */ +outb (1 , dev->io); + dev->muted =1 ; +mutex_init (&dev->lock);if (video_register_device (&dev->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) {v4l2_device_unregister (v4l2_dev);
@@ -324,10 +328,6 @@ static int __init rtrack2_init(void)v4l2_info (v4l2_dev,"AIMSlab Radiotrack II card driver.\n" ); -/* mute card - prevents noisy bootups */ -outb (1 , dev->io); - dev->muted =1 ; -return 0 ; }
drivers/media/radio/radio-sf16fmi.c +4 -3
@@ -260,7 +260,7 @@ static int vidioc_s_audio(struct file *file, void *priv,static const struct v4l2_file_operations fmi_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops fmi_ioctl_ops = {
@@ -382,6 +382,9 @@ static int __init fmi_init(void)mutex_init (&fmi->lock); +/* mute card - prevents noisy bootups */ +fmi_mute (fmi); +if (video_register_device (&fmi->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) {v4l2_device_unregister (v4l2_dev);release_region (fmi->io,2 );
@@ -391,8 +394,6 @@ static int __init fmi_init(void) }v4l2_info (v4l2_dev,"card driver at 0x%x\n" , fmi->io); -/* mute card - prevents noisy bootups */ -fmi_mute (fmi);return 0 ; }
drivers/media/radio/radio-sf16fmr2.c +5 -6
@@ -376,7 +376,7 @@ static int vidioc_s_audio(struct file *file, void *priv,static const struct v4l2_file_operations fmr2_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops fmr2_ioctl_ops = {
@@ -424,6 +424,10 @@ static int __init fmr2_init(void) fmr2->vdev.release = video_device_release_empty;video_set_drvdata (&fmr2->vdev, fmr2); +/* mute card - prevents noisy bootups */ +fmr2_mute (fmr2->io); +fmr2_product_info (fmr2); +if (video_register_device (&fmr2->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) {v4l2_device_unregister (v4l2_dev);release_region (fmr2->io,2 );
@@ -431,11 +435,6 @@ static int __init fmr2_init(void) }v4l2_info (v4l2_dev,"SF16FMR2 radio card driver at 0x%x.\n" , fmr2->io); -/* mute card - prevents noisy bootups */ -mutex_lock (&fmr2->lock); -fmr2_mute (fmr2->io); -fmr2_product_info (fmr2); -mutex_unlock (&fmr2->lock);debug_print ((KERN_DEBUG "card_type %d\n" , fmr2->card_type));return 0 ; }
drivers/media/radio/radio-terratec.c +4 -4
@@ -338,7 +338,7 @@ static int vidioc_s_audio(struct file *file, void *priv,static const struct v4l2_file_operations terratec_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops terratec_ioctl_ops = {
@@ -389,6 +389,9 @@ static int __init terratec_init(void)mutex_init (&tt->lock); +/* mute card - prevents noisy bootups */ +tt_write_vol (tt,0 ); +if (video_register_device (&tt->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) {v4l2_device_unregister (&tt->v4l2_dev);release_region (tt->io,2 );
@@ -396,9 +399,6 @@ static int __init terratec_init(void) }v4l2_info (v4l2_dev,"TERRATEC ActivRadio Standalone card driver.\n" ); - -/* mute card - prevents noisy bootups */ -tt_write_vol (tt,0 );return 0 ; }
drivers/media/radio/radio-trust.c +9 -9
@@ -344,7 +344,7 @@ static int vidioc_s_audio(struct file *file, void *priv,static const struct v4l2_file_operations trust_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops trust_ioctl_ops = {
@@ -396,14 +396,6 @@ static int __init trust_init(void) tr->vdev.release = video_device_release_empty;video_set_drvdata (&tr->vdev, tr); -if (video_register_device (&tr->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) { -v4l2_device_unregister (v4l2_dev); -release_region (tr->io,2 ); -return -EINVAL ; - } - -v4l2_info (v4l2_dev,"Trust FM Radio card driver v1.0.\n" ); -write_i2c (tr,2 ,TDA7318_ADDR ,0x80 );/* speaker att. LF = 0 dB */ write_i2c (tr,2 ,TDA7318_ADDR ,0xa0 );/* speaker att. RF = 0 dB */ write_i2c (tr,2 ,TDA7318_ADDR ,0xc0 );/* speaker att. LR = 0 dB */
@@ -418,6 +410,14 @@ static int __init trust_init(void)/* mute card - prevents noisy bootups */ tr_setmute (tr,1 ); +if (video_register_device (&tr->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) { +v4l2_device_unregister (v4l2_dev); +release_region (tr->io,2 ); +return -EINVAL ; + } + +v4l2_info (v4l2_dev,"Trust FM Radio card driver v1.0.\n" ); +return 0 ; }
drivers/media/radio/radio-zoltrix.c +15 -15
@@ -377,7 +377,7 @@ static int vidioc_s_audio(struct file *file, void *priv,static const struct v4l2_file_operations zoltrix_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops zoltrix_ioctl_ops = {
@@ -424,20 +424,6 @@ static int __init zoltrix_init(void)return res; } -strlcpy (zol->vdev.name, v4l2_dev->name,sizeof (zol->vdev.name)); - zol->vdev.v4l2_dev = v4l2_dev; - zol->vdev.fops = &zoltrix_fops; - zol->vdev.ioctl_ops = &zoltrix_ioctl_ops; - zol->vdev.release = video_device_release_empty; -video_set_drvdata (&zol->vdev, zol); - -if (video_register_device (&zol->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) { -v4l2_device_unregister (v4l2_dev); -release_region (zol->io,2 ); -return -EINVAL ; - } -v4l2_info (v4l2_dev,"Zoltrix Radio Plus card driver.\n" ); -mutex_init (&zol->lock);/* mute card - prevents noisy bootups */
@@ -452,6 +438,20 @@ static int __init zoltrix_init(void) zol->curvol =0 ; zol->stereo =1 ; +strlcpy (zol->vdev.name, v4l2_dev->name,sizeof (zol->vdev.name)); + zol->vdev.v4l2_dev = v4l2_dev; + zol->vdev.fops = &zoltrix_fops; + zol->vdev.ioctl_ops = &zoltrix_ioctl_ops; + zol->vdev.release = video_device_release_empty; +video_set_drvdata (&zol->vdev, zol); + +if (video_register_device (&zol->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) { +v4l2_device_unregister (v4l2_dev); +release_region (zol->io,2 ); +return -EINVAL ; + } +v4l2_info (v4l2_dev,"Zoltrix Radio Plus card driver.\n" ); +return 0 ; }
Signature · 1 line
1.7.0.4
RFC PATCH v2 3/15 cadet: use unlocked_ioctl
In reply to Hans VerkuilConverted from ioctl to unlocked_ioctl.
This driver already used an internal lock, but it was missing in cadet_open and cadet_release and it was not used correctly in cadet_read.
--- drivers/media/radio/radio-cadet.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
drivers/media/radio/radio-cadet.c +9 -3
@@ -328,11 +328,10 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lounsigned char readbuf[RDS_BUFFER ];int i =0 ; +mutex_lock (&dev->lock);if (dev->rdsstat ==0 ) { -mutex_lock (&dev->lock); dev->rdsstat =1 ;outb (0x80 , dev->io);/* Select RDS fifo */ -mutex_unlock (&dev->lock);init_timer (&dev->readtimer); dev->readtimer.function = cadet_handler; dev->readtimer.data = (unsigned long )dev;
@@ -340,12 +339,15 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, loadd_timer (&dev->readtimer); }if (dev->rdsin == dev->rdsout) { +mutex_unlock (&dev->lock);if (file->f_flags &O_NONBLOCK )return -EWOULDBLOCK ;interruptible_sleep_on (&dev->read_queue); +mutex_lock (&dev->lock); }while (i < count && dev->rdsin != dev->rdsout) readbuf[i++] = dev->rdsbuf[dev->rdsout++]; +mutex_unlock (&dev->lock);if (copy_to_user (data, readbuf, i))return -EFAULT ;
@@ -525,9 +527,11 @@ static int cadet_open(struct file *file) {struct cadet *dev =video_drvdata (file); +mutex_lock (&dev->lock); dev->users++;if (1 == dev->users)init_waitqueue_head (&dev->read_queue); +mutex_unlock (&dev->lock);return 0 ; }
@@ -535,11 +539,13 @@ static int cadet_release(struct file *file) {struct cadet *dev =video_drvdata (file); +mutex_lock (&dev->lock); dev->users--;if (0 == dev->users) {del_timer_sync (&dev->readtimer); dev->rdsstat =0 ; } +mutex_unlock (&dev->lock);return 0 ; }
@@ -559,7 +565,7 @@ static const struct v4l2_file_operations cadet_fops = { .open = cadet_open, .release = cadet_release, .read = cadet_read, - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, .poll = cadet_poll, };
Signature · 1 line
1.7.0.4
RFC PATCH v2 4/15 tea5764: convert to unlocked_ioctl
In reply to Hans VerkuilConvert from ioctl to unlocked_ioctl using the v4l2 core lock.
Also removed the 'exclusive access' limitation. There was no need for it and it violates the v4l2 spec as well.
--- drivers/media/radio/radio-tea5764.c | 49 ++++++---------------------------- 1 files changed, 9 insertions(+), 40 deletions(-)
drivers/media/radio/radio-tea5764.c +9 -40
@@ -142,7 +142,6 @@ struct tea5764_device {struct video_device *videodev;struct tea5764_regs regs;struct mutex mutex; -int users; };/* I2C code related */
@@ -458,41 +457,10 @@ static int vidioc_s_audio(struct file *file, void *priv,return 0 ; } -static int tea5764_open (struct file *file) -{ -/* Currently we support only one device */ -struct tea5764_device *radio =video_drvdata (file); - -mutex_lock (&radio->mutex); -/* Only exclusive access */ -if (radio->users) { -mutex_unlock (&radio->mutex); -return -EBUSY ; - } - radio->users++; -mutex_unlock (&radio->mutex); - file->private_data = radio; -return 0 ; -} - -static int tea5764_close (struct file *file) -{ -struct tea5764_device *radio =video_drvdata (file); - -if (!radio) -return -ENODEV ; -mutex_lock (&radio->mutex); - radio->users--; -mutex_unlock (&radio->mutex); -return 0 ; -} -/* File system interface */ static const struct v4l2_file_operations tea5764_fops = { .owner =THIS_MODULE , - .open = tea5764_open, - .release = tea5764_close, - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops tea5764_ioctl_ops = {
@@ -527,7 +495,7 @@ static int __devinit tea5764_i2c_probe(struct i2c_client *client,int ret;PDEBUG ("probe" ); - radio =kmalloc (sizeof (struct tea5764_device ),GFP_KERNEL ); + radio =kzalloc (sizeof (struct tea5764_device ),GFP_KERNEL );if (!radio)return -ENOMEM ;
@@ -555,12 +523,7 @@ static int __devinit tea5764_i2c_probe(struct i2c_client *client,i2c_set_clientdata (client, radio);video_set_drvdata (radio->videodev, radio); - - ret =video_register_device (radio->videodev,VFL_TYPE_RADIO , radio_nr); -if (ret <0 ) { -PWARN ("Could not register video device!" ); - goto errrel; - } + radio->videodev->lock = &radio->mutex;/* initialize and power off the chip */ tea5764_i2c_read (radio);
@@ -568,6 +531,12 @@ static int __devinit tea5764_i2c_probe(struct i2c_client *client,tea5764_mute (radio,1 );tea5764_power_down (radio); + ret =video_register_device (radio->videodev,VFL_TYPE_RADIO , radio_nr); +if (ret <0 ) { +PWARN ("Could not register video device!" ); + goto errrel; + } +PINFO ("registered." );return 0 ; errrel:
Signature · 1 line
1.7.0.4
RFC PATCH v2 5/15 si4713: convert to unlocked_ioctl
In reply to Hans VerkuilConvert ioctl to unlocked_ioctl. Note that for this driver the locking is done inside the sub-device.
--- drivers/media/radio/radio-si4713.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/media/radio/radio-si4713.c +2 -1
@@ -53,7 +53,8 @@ struct radio_si4713_device {/* radio_si4713_fops - file operations interface */ static const struct v4l2_file_operations radio_si4713_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, +/* Note: locking is done at the subdev level in the i2c driver. */ + .unlocked_ioctl = video_ioctl2, };/* Video4Linux Interface */
Signature · 1 line
1.7.0.4
RFC PATCH v2 6/15 typhoon: convert to unlocked_ioctl.
In reply to Hans VerkuilConvert the typhoon driver from ioctl to unlocked_ioctl.
When doing this I noticed a bug where curfreq was not initialized correctly to mutefreq (it wasn't multiplied by 16).
The initialization is now also done before the device node is created.
--- drivers/media/radio/radio-typhoon.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
drivers/media/radio/radio-typhoon.c +8 -8
@@ -317,7 +317,7 @@ static int vidioc_log_status(struct file *file, void *priv)static const struct v4l2_file_operations typhoon_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops typhoon_ioctl_ops = {
@@ -344,18 +344,18 @@ static int __init typhoon_init(void)strlcpy (v4l2_dev->name,"typhoon" ,sizeof (v4l2_dev->name)); dev->io = io; - dev->curfreq = dev->mutefreq = mutefreq;if (dev->io ==-1 ) {v4l2_err (v4l2_dev,"You must set an I/O address with io=0x316 or io=0x336\n" );return -EINVAL ; } -if (dev->mutefreq <87000 || dev->mutefreq >108500 ) { +if (mutefreq <87000 || mutefreq >108500 ) {v4l2_err (v4l2_dev,"You must set a frequency (in kHz) used when muting the card,\n" );v4l2_err (v4l2_dev,"e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108500)\n" );return -EINVAL ; } + dev->curfreq = dev->mutefreq = mutefreq <<4 ;mutex_init (&dev->lock);if (!request_region (dev->io,8 ,"typhoon" )) {
@@ -378,17 +378,17 @@ static int __init typhoon_init(void) dev->vdev.ioctl_ops = &typhoon_ioctl_ops; dev->vdev.release = video_device_release_empty;video_set_drvdata (&dev->vdev, dev); + +/* mute card - prevents noisy bootups */ +typhoon_mute (dev); +if (video_register_device (&dev->vdev,VFL_TYPE_RADIO , radio_nr) <0 ) {v4l2_device_unregister (&dev->v4l2_dev);release_region (dev->io,8 );return -EINVAL ; }v4l2_info (v4l2_dev,"port 0x%x.\n" , dev->io); -v4l2_info (v4l2_dev,"mute frequency is %lu kHz.\n" , dev->mutefreq); - dev->mutefreq <<=4 ; - -/* mute card - prevents noisy bootups */ -typhoon_mute (dev); +v4l2_info (v4l2_dev,"mute frequency is %lu kHz.\n" , mutefreq);return 0 ; }
Signature · 1 line
1.7.0.4
RFC PATCH v2 7/15 dsbr100: convert to unlocked_ioctl.
In reply to Hans VerkuilTrivial conversion to unlocked_ioctl.
--- drivers/media/radio/dsbr100.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/media/radio/dsbr100.c +1 -1
@@ -605,7 +605,7 @@ static void usb_dsbr100_video_device_release(struct video_device *videodev)/* File system interface */ static const struct v4l2_file_operations usb_dsbr100_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = {
Signature · 1 line
1.7.0.4
Re: [RFCv2 PATCH 07/15] dsbr100: convert to unlocked_ioctl.
This driver has quite a few locking issues that would only be made worse by your patch. A much better patch for this can be found here:
Regards,
David Ellingsworth
Re: [RFCv2 PATCH 07/15] dsbr100: convert to unlocked_ioctl.
Quoted 5 lines
This driver has quite a few locking issues that would only be made worse by your patch. A much better patch for this can be found here:
Much too big for 2.6.37. I'll just drop this patch from my patch series. Instead it will rely on the new lock in v4l2_device (BKL replacement) that serializes all ioctls. For 2.6.38 we can convert it to core assisted locking which is much easier.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by Cisco
Re: [RFCv2 PATCH 07/15] dsbr100: convert to unlocked_ioctl.
Quoted 11 lines · Hans Verkuil
Quoted 5 lines
This driver has quite a few locking issues that would only be made worse by your patch. A much better patch for this can be found here:
Much too big for 2.6.37. I'll just drop this patch from my patch series. Instead it will rely on the new lock in
v4l2_device(BKL replacement) that serializes all ioctls. For 2.6.38 we can convert it to core assisted locking which is much easier.
I don't see how this patch is really any bigger than some of the others in your series. Sure there are a lot of deletions, but the number of additions is quite small. There are much worse ways all the locking issues in this driver could have been corrected. This patch manages to do just that while reducing the overall size of the driver at the same time.
Regards,
David Ellingsworth
Re: [RFCv2 PATCH 07/15] dsbr100: convert to unlocked_ioctl.
Quoted 15 lines · Hans Verkuil
Quoted 4 lines
Quoted 4 lines
This driver has quite a few locking issues that would only be made worse by your patch. A much better patch for this can be found here:
Quoted 8 lines
Quoted 1 line
Much too big for 2.6.37. I'll just drop this patch from my patch series. Instead it will rely on the new lock in
v4l2_device(BKL replacement) that
serializes all ioctls. For 2.6.38 we can convert it to core assisted locking which is much easier.
Quoted 6 lines
I don't see how this patch is really any bigger than some of the others in your series. Sure there are a lot of deletions, but the number of additions is quite small. There are much worse ways all the locking issues in this driver could have been corrected. This patch manages to do just that while reducing the overall size of the driver at the same time.
Basically there are two reasons why I'm not including this in my patch
series: 1) you disagreed with my patch and 2) I disagree with your patch.
In this case the patch for 2.6.37 should either be small and trivial, or we should postpone it to 2.6.38 and use proper core-assisted locking (which makes the most sense for this driver in my opinion). And I really dislike those BUG_ONs you've added, to be honest. Sorry about that...
Anyway, feel free to post your own patch for this driver. I've no problems with that at all. It is clear that this driver takes more time to get a proper patch for that makes everyone happy, and I really need to make the git pull request for 2.6.37 tomorrow as we don't want to do this too late in the 2.6.37 cycle.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by Cisco
Re: [RFCv2 PATCH 07/15] dsbr100: convert to unlocked_ioctl.
Quoted 22 lines · Hans Verkuil
Quoted 15 lines · Hans Verkuil
Quoted 4 lines
Quoted 4 lines
This driver has quite a few locking issues that would only be made worse by your patch. A much better patch for this can be found here:
Quoted 8 lines
Quoted 1 line
Much too big for 2.6.37. I'll just drop this patch from my patch series. Instead it will rely on the new lock in
v4l2_device(BKL replacement) that
serializes all ioctls. For 2.6.38 we can convert it to core assisted locking which is much easier.Quoted 6 lines
I don't see how this patch is really any bigger than some of the others in your series. Sure there are a lot of deletions, but the number of additions is quite small. There are much worse ways all the locking issues in this driver could have been corrected. This patch manages to do just that while reducing the overall size of the driver at the same time.
Quoted 7 lines
Basically there are two reasons why I'm not including this in my patch
series: 1) you disagreed with my patch and 2) I disagree with your patch.In this case the patch for 2.6.37 should either be small and trivial, or we should postpone it to 2.6.38 and use proper core-assisted locking (which makes the most sense for this driver in my opinion). And I really dislike those
BUG_ONsyou've added, to be honest. Sorry about that...
The reality is that the BUG_ONs should never be hit. I added those because I don't have the hardware needed to test my changes. So if I missed something, the issue would be very apparent to whoever was doing the testing. If someone would actually test this series, the BUG_ONs could be removed. Maybe a WARN_ON would have been better, but to me accessing the device struct without holding the lock is a bug. The only valid case where it would be okay to do that would be from within the probe function before the device is registered.
Quoted 7 lines
Anyway, feel free to post your own patch for this driver. I've no problems with that at all. It is clear that this driver takes more time to get a proper patch for that makes everyone happy, and I really need to make the git pull request for 2.6.37 tomorrow as we don't want to do this too late in the 2.6.37 cycle.
I understand, but if you or anyone else had actually bothered to review this patch when it was submitted back in May then it might have made its way into the kernel by now. At the time the patch was written, core assisted locking wasn't even implemented. Granted the ioctl added to correct the locking might cause a cache miss, but this is acceptable for such a simple driver. This is a good first step towards core assisted locking.
Regards,
David Ellingsworth
RFC PATCH v2 8/15 BKL: trivial ioctl -> unlocked_ioctl video driver conversions
In reply to Hans VerkuilThese drivers could be trivially converted to unlocked_ioctl since they already did locking.
--- drivers/media/video/arv.c | 2 +- drivers/media/video/bw-qcam.c | 2 +- drivers/media/video/c-qcam.c | 2 +- drivers/media/video/meye.c | 14 +++++++------- drivers/media/video/pms.c | 2 +- drivers/media/video/w9966.c | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-)
drivers/media/video/arv.c +1 -1
@@ -712,7 +712,7 @@ static int ar_initialize(struct ar *ar)static const struct v4l2_file_operations ar_fops = { .owner =THIS_MODULE , .read = ar_read, - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops ar_ioctl_ops = {
drivers/media/video/bw-qcam.c +1 -1
@@ -860,7 +860,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,static const struct v4l2_file_operations qcam_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, .read = qcam_read, };
drivers/media/video/c-qcam.c +1 -1
@@ -718,7 +718,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,static const struct v4l2_file_operations qcam_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, .read = qcam_read, };
drivers/media/video/meye.c +7 -7
@@ -1659,7 +1659,7 @@ static const struct v4l2_file_operations meye_fops = { .open = meye_open, .release = meye_release, .mmap = meye_mmap, - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, .poll = meye_poll, };
@@ -1831,12 +1831,6 @@ static int __devinit meye_probe(struct pci_dev *pcidev,msleep (1 );mchip_set (MCHIP_MM_INTA ,MCHIP_MM_INTA_HIC_1_MASK ); -if (video_register_device (meye.vdev,VFL_TYPE_GRABBER , - video_nr) <0 ) { -v4l2_err (v4l2_dev,"video_register_device failed\n" ); - goto outvideoreg; - } -mutex_init (&meye.lock);init_waitqueue_head (&meye.proc_list); meye.brightness =32 <<10 ;
@@ -1858,6 +1852,12 @@ static int __devinit meye_probe(struct pci_dev *pcidev,sony_pic_camera_command (SONY_PIC_COMMAND_SETCAMERAPICTURE ,0 );sony_pic_camera_command (SONY_PIC_COMMAND_SETCAMERAAGC ,48 ); +if (video_register_device (meye.vdev,VFL_TYPE_GRABBER , + video_nr) <0 ) { +v4l2_err (v4l2_dev,"video_register_device failed\n" ); + goto outvideoreg; + } +v4l2_info (v4l2_dev,"Motion Eye Camera Driver v%s.\n" ,MEYE_DRIVER_VERSION ); v4l2_info(v4l2_dev, "mchip KL5A72002 rev. %d, base %lx, irq %d\n",
drivers/media/video/pms.c +1 -1
@@ -932,7 +932,7 @@ static ssize_t pms_read(struct file *file, char __user *buf,static const struct v4l2_file_operations pms_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, .read = pms_read, };
drivers/media/video/w9966.c +1 -1
@@ -815,7 +815,7 @@ out:static const struct v4l2_file_operations w9966_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, .read = w9966_v4l_read, };
Signature · 1 line
1.7.0.4
RFC PATCH v2 9/15 sn9c102: convert to unlocked_ioctl.
In reply to Hans VerkuilTrivial conversion, this driver used a mutex already.
--- drivers/media/video/sn9c102/sn9c102_core.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/media/video/sn9c102/sn9c102_core.c +1 -1
@@ -3238,7 +3238,7 @@ static const struct v4l2_file_operations sn9c102_fops = { .owner = THIS_MODULE, .open = sn9c102_open, .release = sn9c102_release, - .ioctl = sn9c102_ioctl, + .unlocked_ioctl = sn9c102_ioctl, .read = sn9c102_read, .poll = sn9c102_poll, .mmap = sn9c102_mmap,
Signature · 1 line
1.7.0.4
RFC PATCH v2 10/15 et61x251_core: trivial conversion to unlocked_ioctl.
In reply to Hans Verkuil--- drivers/media/video/et61x251/et61x251_core.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/media/video/et61x251/et61x251_core.c +1 -1
@@ -2530,7 +2530,7 @@ static const struct v4l2_file_operations et61x251_fops = { .owner = THIS_MODULE, .open = et61x251_open, .release = et61x251_release, - .ioctl = et61x251_ioctl, + .unlocked_ioctl = et61x251_ioctl, .read = et61x251_read, .poll = et61x251_poll, .mmap = et61x251_mmap,
Signature · 1 line
1.7.0.4
RFC PATCH v2 11/15 cafe_ccic: replace ioctl by unlocked_ioctl.
In reply to Hans VerkuilTrivial change, approved by Jonathan Corbet <[email protected]>.
--- drivers/media/video/cafe_ccic.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/media/video/cafe_ccic.c +1 -1
@@ -1773,7 +1773,7 @@ static const struct v4l2_file_operations cafe_v4l_fops = { .read = cafe_v4l_read, .poll = cafe_v4l_poll, .mmap = cafe_v4l_mmap, - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static const struct v4l2_ioctl_ops cafe_v4l_ioctl_ops = {
Signature · 1 line
1.7.0.4
RFC PATCH v2 12/15 sh_vou: convert to unlocked_ioctl.
In reply to Hans Verkuil--- drivers/media/video/sh_vou.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-)
drivers/media/video/sh_vou.c +8 -5
@@ -75,6 +75,7 @@ struct sh_vou_device {int pix_idx;struct videobuf_buffer *active;enum sh_vou_status status; +struct mutex fop_lock; };struct sh_vou_file {
@@ -235,7 +236,7 @@ static void free_buffer(struct videobuf_queue *vq, struct videobuf_buffer *vb) vb->state =VIDEOBUF_NEEDS_INIT ; } -/* Locking: caller holds vq->vb_lock mutex */ +/* Locking: caller holds fop_lock mutex */ static int sh_vou_buf_setup (struct videobuf_queue *vq,unsigned int *count,unsigned int *size) {
@@ -257,7 +258,7 @@ static int sh_vou_buf_setup(struct videobuf_queue *vq, unsigned int *count,return 0 ; } -/* Locking: caller holds vq->vb_lock mutex */ +/* Locking: caller holds fop_lock mutex */ static int sh_vou_buf_prepare (struct videobuf_queue *vq,struct videobuf_buffer *vb,enum v4l2_field field)
@@ -306,7 +307,7 @@ static int sh_vou_buf_prepare(struct videobuf_queue *vq,return 0 ; } -/* Locking: caller holds vq->vb_lock mutex and vq->irqlock spinlock */ +/* Locking: caller holds fop_lock mutex and vq->irqlock spinlock */ static void sh_vou_buf_queue (struct videobuf_queue *vq,struct videobuf_buffer *vb) {
@@ -1190,7 +1191,7 @@ static int sh_vou_open(struct file *file)V4L2_BUF_TYPE_VIDEO_OUTPUT ,V4L2_FIELD_NONE ,sizeof (struct videobuf_buffer ), vdev, - NULL); + &vou_dev->fop_lock);return 0 ; }
@@ -1292,7 +1293,7 @@ static const struct v4l2_file_operations sh_vou_fops = { .owner = THIS_MODULE, .open = sh_vou_open, .release = sh_vou_release, - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, .mmap = sh_vou_mmap, .poll = sh_vou_poll, };
@@ -1331,6 +1332,7 @@ static int __devinit sh_vou_probe(struct platform_device *pdev)INIT_LIST_HEAD (&vou_dev->queue);spin_lock_init (&vou_dev->lock); +mutex_init (&vou_dev->fop_lock);atomic_set (&vou_dev->use_count,0 ); vou_dev->pdata = vou_pdata; vou_dev->status =SH_VOU_IDLE ;
@@ -1388,6 +1390,7 @@ static int __devinit sh_vou_probe(struct platform_device *pdev) vdev->tvnorms |=V4L2_STD_PAL ; vdev->v4l2_dev = &vou_dev->v4l2_dev; vdev->release = video_device_release; + vdev->lock = &vou_dev->fop_lock; vou_dev->vdev = vdev;video_set_drvdata (vdev, vou_dev);
Signature · 1 line
1.7.0.4
RFC PATCH v2 13/15 radio-timb: convert to unlocked_ioctl.
In reply to Hans Verkuil--- drivers/media/radio/radio-timb.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/media/radio/radio-timb.c +4 -1
@@ -34,6 +34,7 @@ struct timbradio {struct v4l2_subdev *sd_dsp;struct video_device video_dev;struct v4l2_device v4l2_dev; +struct mutex lock; };
@@ -142,7 +143,7 @@ static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {static const struct v4l2_file_operations timbradio_fops = { .owner =THIS_MODULE , - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, };static int __devinit timbradio_probe (struct platform_device *pdev)
@@ -164,6 +165,7 @@ static int __devinit timbradio_probe(struct platform_device *pdev) } tr->pdata = *pdata; +mutex_init (&tr->lock);strlcpy (tr->video_dev.name,"Timberdale Radio" ,sizeof (tr->video_dev.name));
@@ -171,6 +173,7 @@ static int __devinit timbradio_probe(struct platform_device *pdev) tr->video_dev.ioctl_ops = &timbradio_ioctl_ops; tr->video_dev.release = video_device_release_empty; tr->video_dev.minor =-1 ; + tr->video_dev.lock = &tr->lock;strlcpy (tr->v4l2_dev.name,DRIVER_NAME ,sizeof (tr->v4l2_dev.name)); err =v4l2_device_register (NULL , &tr->v4l2_dev);
Signature · 1 line
1.7.0.4
RFC PATCH v2 14/15 V4L: improve the BKL replacement heuristic
In reply to Hans VerkuilThe BKL replacement mutex had some serious performance side-effects on V4L drivers. It is replaced by a better heuristic that works around the worst of the side-effects.
Read the v4l2-dev.c comments for the whole sorry story. This is a temporary measure only until we can convert all v4l drivers to use unlocked_ioctl.
--- drivers/media/video/v4l2-dev.c | 37 ++++++++++++++++++++++++++++++++++--- drivers/media/video/v4l2-device.c | 1 + include/media/v4l2-dev.h | 2 +- include/media/v4l2-device.h | 2 ++ 4 files changed, 38 insertions(+), 4 deletions(-)
drivers/media/video/v4l2-dev.c +34 -3
@@ -258,11 +258,42 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)if (vdev->lock)mutex_unlock (vdev->lock); }else if (vdev->fops->ioctl) { -/* TODO: convert all drivers to unlocked_ioctl */ -lock_kernel (); +/* 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. +* +* There are two options: if the driver implements struct +* v4l2_device, then the lock defined there is used to +* serialize the ioctls. Otherwise the v4l2 core lock defined +* below is used. This lock is really bad since it serializes +* completely independent devices. +* +* Both variants suffer from the same problem: 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. +*/ +static DEFINE_MUTEX (v4l2_ioctl_mutex); +struct mutex *m = vdev->v4l2_dev ? + &vdev->v4l2_dev->ioctl_lock : &v4l2_ioctl_mutex; + +if (cmd !=VIDIOC_DQBUF ) { +int res =mutex_lock_interruptible (m); + +if (res) +return res; + }if (video_is_registered (vdev)) ret = vdev->fops->ioctl (filp, cmd, arg); -unlock_kernel (); +if (cmd !=VIDIOC_DQBUF ) +mutex_unlock (m); }else ret = -ENOTTY ;
drivers/media/video/v4l2-device.c +1 -0
@@ -35,6 +35,7 @@ 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_dev->dev = dev;if (dev ==NULL ) {/* If dev == NULL, then name must be filled in by the caller */
include/media/v4l2-dev.h +1 -1
@@ -39,7 +39,7 @@ 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 (*ioctl__deprecated ) (struct file *,unsigned int ,unsigned long );long (*unlocked_ioctl) (struct file *,unsigned int ,unsigned long );int (*mmap) (struct file *,struct vm_area_struct *);int (*open) (struct file *);
include/media/v4l2-device.h +2 -0
@@ -51,6 +51,8 @@ struct v4l2_device { unsigned int notification, void *arg);/* The control handler. May be NULL. */ struct v4l2_ctrl_handler *ctrl_handler; +/* BKL replacement mutex. Temporary solution only. */ +struct mutex ioctl_lock; };/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev.
Signature · 1 line
1.7.0.4
Re: [RFCv2 PATCH 14/15] V4L: improve the BKL replacement heuristic
Quoted 9 lines · On Tuesday 16 November 2010 22:56:45 Hans Verkuil wrote:
The BKL replacement mutex had some serious performance side-effects on V4L drivers. It is replaced by a better heuristic that works around the worst of the side-effects.
Read the
v4l2-dev.ccomments for the whole sorry story. This is a temporary measure only until we can convert all v4l drivers to useunlocked_ioctl.Signed-off-by Hans Verkuil <[email protected]>
Quoted 96 lines
--- drivers/media/video/v4l2-dev.c | 37 ++++++++++++++++++++++++++++++++++--- drivers/media/video/v4l2-device.c | 1 + include/media/v4l2-dev.h | 2 +- include/media/v4l2-device.h | 2 ++ 4 files changed, 38 insertions(+), 4 deletions(-)drivers/media/video/v4l2-dev.c +34
-3@@ -258,11 +258,42 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)if (vdev->lock)mutex_unlock (vdev->lock); }else if (vdev->fops->ioctl) { -/* TODO: convert all drivers to unlocked_ioctl */ -lock_kernel (); +/* 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. +* +* There are two options: if the driver implements struct +* v4l2_device, then the lock defined there is used to +* serialize the ioctls. Otherwise the v4l2 core lock defined +* below is used. This lock is really bad since it serializes +* completely independent devices. +* +* Both variants suffer from the same problem: 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. +*/ +static DEFINE_MUTEX (v4l2_ioctl_mutex); +struct mutex *m = vdev->v4l2_dev ? + &vdev->v4l2_dev->ioctl_lock : &v4l2_ioctl_mutex; + +if (cmd !=VIDIOC_DQBUF ) { +int res =mutex_lock_interruptible (m); + +if (res) +return res; + }if (video_is_registered (vdev)) ret = vdev->fops->ioctl (filp, cmd, arg); -unlock_kernel (); +if (cmd !=VIDIOC_DQBUF ) +mutex_unlock (m); }else ret = -ENOTTY ;drivers/media/video/v4l2-device.c +1
-0@@ -35,6 +35,7 @@ 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_dev->dev = dev;if (dev ==NULL ) {/* If dev == NULL, then name must be filled in by the caller */ include/media/v4l2-dev.h +1
-1@@ -39,7 +39,7 @@ 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 (*ioctl__deprecated ) (struct file *,unsigned int ,unsigned long );long (*unlocked_ioctl) (struct file *,unsigned int ,unsigned long );int (*mmap) (struct file *,struct vm_area_struct *);int (*open) (struct file *);include/media/v4l2-device.h +2
-0@@ -51,6 +51,8 @@ struct v4l2_device { unsigned int notification, void *arg);/* The control handler. May be NULL. */ struct v4l2_ctrl_handler *ctrl_handler; +/* BKL replacement mutex. Temporary solution only. */ +struct mutex ioctl_lock; };/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev.
RFC PATCH v2 15/15 cx18: convert to unlocked_ioctl.
In reply to Hans Verkuil--- drivers/media/video/cx18/cx18-streams.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/media/video/cx18/cx18-streams.c +1 -1
@@ -41,7 +41,7 @@ static struct v4l2_file_operations cx18_v4l2_enc_fops = { .read = cx18_v4l2_read, .open = cx18_v4l2_open, /* FIXME change to video_ioctl2 if serialization lock can be removed */ - .ioctl = cx18_v4l2_ioctl, + .unlocked_ioctl = cx18_v4l2_ioctl, .release = cx18_v4l2_close, .poll = cx18_v4l2_enc_poll, };
Signature · 1 line
1.7.0.4
Re: [RFCv2 PATCH 15/15] cx18: convert to unlocked_ioctl.
Quoted 10 lines · Hans Verkuil
Signed-off-by Hans Verkuil <[email protected]>--- drivers/media/video/cx18/cx18-streams.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/media/video/cx18/cx18-streams.c +0
-0
drivers/media/video/cx18/cx18-streams.c static struct v4l2_file_operations cx18_v4l2_enc_fops = { · line 47
Quoted 8 lines
drivers/media/video/cx18/cx18-streams.c +1
-1@@ -41,7 +41,7 @@ static struct v4l2_file_operations cx18_v4l2_enc_fops = { .read = cx18_v4l2_read, .open = cx18_v4l2_open, /* FIXME change to video_ioctl2 if serialization lock can be removed */ - .ioctl = cx18_v4l2_ioctl, + .unlocked_ioctl = cx18_v4l2_ioctl, .release = cx18_v4l2_close, .poll = cx18_v4l2_enc_poll, };
Hans,
Because I haven't done my homework on the ALSA API, could you also add snd_cx18_lock()/snd_cx18_unlock() in snd_cx18_pcm_ioctl()?
Devin,
Do you know off the top of your head if any other operations in cx18-alsa-* may need additional locking?
I am an ALSA API callback idiot. :)
Regards,
Andy