diff options
author | Mauro Carvalho Chehab <mchehab@infradead.org> | 2007-11-11 02:08:26 -0200 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2007-11-11 02:08:26 -0200 |
commit | cab6c5e66d150f790c08e02b7d29b2ca207af15e (patch) | |
tree | 142fe7a0097224e043f36dbff942d9717afbf94f /linux/drivers/media/video/em28xx/em28xx-video.c | |
parent | db4dfb55bb265896e57c870771ddfcbcfde7ecf5 (diff) | |
download | mediapointer-dvb-s2-cab6c5e66d150f790c08e02b7d29b2ca207af15e.tar.gz mediapointer-dvb-s2-cab6c5e66d150f790c08e02b7d29b2ca207af15e.tar.bz2 |
Fix em28xx read stream locking
From: Mauro Carvalho Chehab <mchehab@infradead.org>
On some situations, closing an streaming application and re-opening were
returning -EBUSY.
Uses the same locking schema also present on cx88.
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'linux/drivers/media/video/em28xx/em28xx-video.c')
-rw-r--r-- | linux/drivers/media/video/em28xx/em28xx-video.c | 77 |
1 files changed, 56 insertions, 21 deletions
diff --git a/linux/drivers/media/video/em28xx/em28xx-video.c b/linux/drivers/media/video/em28xx/em28xx-video.c index a416dbc83..55a494727 100644 --- a/linux/drivers/media/video/em28xx/em28xx-video.c +++ b/linux/drivers/media/video/em28xx/em28xx-video.c @@ -245,6 +245,44 @@ static void video_mux(struct em28xx *dev, int index) } } +/* Usage lock check functions */ +static int res_get(struct em28xx_fh *fh) +{ + struct em28xx *dev = fh->dev; + int rc = 0; + + /* This instance already has stream_on */ + if (fh->stream_on) + return rc; + + mutex_lock(&dev->lock); + + if (dev->stream_on) + rc = -EINVAL; + else { + dev->stream_on = 1; + fh->stream_on = 1; + } + + mutex_unlock(&dev->lock); + return rc; +} + +static int res_check(struct em28xx_fh *fh) +{ + return (fh->stream_on); +} + +static void res_free(struct em28xx_fh *fh) +{ + struct em28xx *dev = fh->dev; + + mutex_lock(&dev->lock); + fh->stream_on = 0; + dev->stream_on = 0; + mutex_unlock(&dev->lock); +} + /* * em28xx_v4l2_open() * inits the device and starts isoc transfer @@ -356,15 +394,16 @@ static int em28xx_v4l2_close(struct inode *inode, struct file *filp) em28xx_videodbg("users=%d\n", dev->users); + + if (res_check(fh)) + res_free(fh); + mutex_lock(&dev->lock); - if (fh->reader == 1) - fh->reader = 0; if (dev->users == 1) { - dev->reader = 0; - em28xx_uninit_isoc(dev); em28xx_release_buffers(dev); + dev->io = IO_NONE; /* the device is already disconnect, free the remaining resources */ @@ -405,16 +444,15 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count, struct em28xx_fh *fh = filp->private_data; struct em28xx *dev = fh->dev; + + if (unlikely(res_get(fh) < 0)) + return -EBUSY; + mutex_lock(&dev->lock); if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) em28xx_videodbg("V4l2_Buf_type_videocapture is set\n"); - if (dev->reader > 0 && fh->reader == 0) { - mutex_unlock(&dev->lock); - return -EBUSY; - } - if (dev->type == V4L2_BUF_TYPE_VBI_CAPTURE) { em28xx_videodbg("V4L2_BUF_TYPE_VBI_CAPTURE is set\n"); em28xx_videodbg("not supported yet! ...\n"); @@ -453,9 +491,6 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count, " the device again to choose the read method\n"); mutex_unlock(&dev->lock); return -EINVAL; - } else { - dev->reader = 1; - fh->reader = 1; } if (dev->io == IO_NONE) { @@ -527,6 +562,9 @@ static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait) struct em28xx_fh *fh = filp->private_data; struct em28xx *dev = fh->dev; + if (unlikely(res_get(fh) < 0)) + return POLLERR; + mutex_lock(&dev->lock); if (dev->state & DEV_DISCONNECTED) { @@ -600,15 +638,10 @@ static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) void *pos; u32 i; - mutex_lock(&dev->lock); - - if (dev->reader > 0 && fh->reader == 0) { - mutex_unlock(&dev->lock); + if (unlikely(res_get(fh) < 0)) return -EBUSY; - } else { - dev->reader = 1; - fh->reader = 1; - } + + mutex_lock(&dev->lock); if (dev->state & DEV_DISCONNECTED) { em28xx_videodbg("mmap: device not present\n"); @@ -1285,6 +1318,9 @@ static int em28xx_do_ioctl(struct inode *inode, struct file *filp, if (list_empty(&dev->inqueue)) return -EINVAL; + if (unlikely(res_get(fh) < 0)) + return -EBUSY; + dev->stream = STREAM_ON; /* FIXME: Start video capture here? */ em28xx_videodbg("VIDIOC_STREAMON: starting stream\n"); @@ -1309,7 +1345,6 @@ static int em28xx_do_ioctl(struct inode *inode, struct file *filp, } } - fh->reader = 0; em28xx_empty_framequeues(dev); mutex_unlock(&dev->lock); |