mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-11-01 17:08:10 +00:00
[media] v4l2-dev: use mutex_lock_interruptible instead of plain mutex_lock
Where reasonable use mutex_lock_interruptible instead of mutex_lock. Also fix the poll, read and write error codes when called with an unregistered device (e.g. after a USB device was disconnected). Poll must return POLLERR|POLLHUP and read/write must return -ENODEV. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
parent
78b055be27
commit
2877842de8
1 changed files with 17 additions and 14 deletions
|
@ -186,12 +186,12 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf,
|
||||||
size_t sz, loff_t *off)
|
size_t sz, loff_t *off)
|
||||||
{
|
{
|
||||||
struct video_device *vdev = video_devdata(filp);
|
struct video_device *vdev = video_devdata(filp);
|
||||||
int ret = -EIO;
|
int ret = -ENODEV;
|
||||||
|
|
||||||
if (!vdev->fops->read)
|
if (!vdev->fops->read)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (vdev->lock)
|
if (vdev->lock && mutex_lock_interruptible(vdev->lock))
|
||||||
mutex_lock(vdev->lock);
|
return -ERESTARTSYS;
|
||||||
if (video_is_registered(vdev))
|
if (video_is_registered(vdev))
|
||||||
ret = vdev->fops->read(filp, buf, sz, off);
|
ret = vdev->fops->read(filp, buf, sz, off);
|
||||||
if (vdev->lock)
|
if (vdev->lock)
|
||||||
|
@ -203,12 +203,12 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf,
|
||||||
size_t sz, loff_t *off)
|
size_t sz, loff_t *off)
|
||||||
{
|
{
|
||||||
struct video_device *vdev = video_devdata(filp);
|
struct video_device *vdev = video_devdata(filp);
|
||||||
int ret = -EIO;
|
int ret = -ENODEV;
|
||||||
|
|
||||||
if (!vdev->fops->write)
|
if (!vdev->fops->write)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (vdev->lock)
|
if (vdev->lock && mutex_lock_interruptible(vdev->lock))
|
||||||
mutex_lock(vdev->lock);
|
return -ERESTARTSYS;
|
||||||
if (video_is_registered(vdev))
|
if (video_is_registered(vdev))
|
||||||
ret = vdev->fops->write(filp, buf, sz, off);
|
ret = vdev->fops->write(filp, buf, sz, off);
|
||||||
if (vdev->lock)
|
if (vdev->lock)
|
||||||
|
@ -219,10 +219,10 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf,
|
||||||
static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
|
static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
|
||||||
{
|
{
|
||||||
struct video_device *vdev = video_devdata(filp);
|
struct video_device *vdev = video_devdata(filp);
|
||||||
int ret = DEFAULT_POLLMASK;
|
int ret = POLLERR | POLLHUP;
|
||||||
|
|
||||||
if (!vdev->fops->poll)
|
if (!vdev->fops->poll)
|
||||||
return ret;
|
return DEFAULT_POLLMASK;
|
||||||
if (vdev->lock)
|
if (vdev->lock)
|
||||||
mutex_lock(vdev->lock);
|
mutex_lock(vdev->lock);
|
||||||
if (video_is_registered(vdev))
|
if (video_is_registered(vdev))
|
||||||
|
@ -238,8 +238,8 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
||||||
int ret = -ENODEV;
|
int ret = -ENODEV;
|
||||||
|
|
||||||
if (vdev->fops->unlocked_ioctl) {
|
if (vdev->fops->unlocked_ioctl) {
|
||||||
if (vdev->lock)
|
if (vdev->lock && mutex_lock_interruptible(vdev->lock))
|
||||||
mutex_lock(vdev->lock);
|
return -ERESTARTSYS;
|
||||||
if (video_is_registered(vdev))
|
if (video_is_registered(vdev))
|
||||||
ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
|
ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
|
||||||
if (vdev->lock)
|
if (vdev->lock)
|
||||||
|
@ -265,8 +265,8 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)
|
||||||
|
|
||||||
if (!vdev->fops->mmap)
|
if (!vdev->fops->mmap)
|
||||||
return ret;
|
return ret;
|
||||||
if (vdev->lock)
|
if (vdev->lock && mutex_lock_interruptible(vdev->lock))
|
||||||
mutex_lock(vdev->lock);
|
return -ERESTARTSYS;
|
||||||
if (video_is_registered(vdev))
|
if (video_is_registered(vdev))
|
||||||
ret = vdev->fops->mmap(filp, vm);
|
ret = vdev->fops->mmap(filp, vm);
|
||||||
if (vdev->lock)
|
if (vdev->lock)
|
||||||
|
@ -292,8 +292,10 @@ static int v4l2_open(struct inode *inode, struct file *filp)
|
||||||
video_get(vdev);
|
video_get(vdev);
|
||||||
mutex_unlock(&videodev_lock);
|
mutex_unlock(&videodev_lock);
|
||||||
if (vdev->fops->open) {
|
if (vdev->fops->open) {
|
||||||
if (vdev->lock)
|
if (vdev->lock && mutex_lock_interruptible(vdev->lock)) {
|
||||||
mutex_lock(vdev->lock);
|
ret = -ERESTARTSYS;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
if (video_is_registered(vdev))
|
if (video_is_registered(vdev))
|
||||||
ret = vdev->fops->open(filp);
|
ret = vdev->fops->open(filp);
|
||||||
else
|
else
|
||||||
|
@ -302,6 +304,7 @@ static int v4l2_open(struct inode *inode, struct file *filp)
|
||||||
mutex_unlock(vdev->lock);
|
mutex_unlock(vdev->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err:
|
||||||
/* decrease the refcount in case of an error */
|
/* decrease the refcount in case of an error */
|
||||||
if (ret)
|
if (ret)
|
||||||
video_put(vdev);
|
video_put(vdev);
|
||||||
|
|
Loading…
Reference in a new issue