Skip to content

Commit

Permalink
[media] usbvision: remove V4L2_FL_LOCK_ALL_FOPS
Browse files Browse the repository at this point in the history
Add proper locking to the file operations, allowing for the removal
of the V4L2_FL_LOCK_ALL_FOPS flag.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Aug 9, 2012
1 parent d76ebb6 commit 4d34570
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions drivers/media/video/usbvision/usbvision-video.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ static int usbvision_v4l2_open(struct file *file)

PDEBUG(DBG_IO, "open");

if (mutex_lock_interruptible(&usbvision->v4l2_lock))
return -ERESTARTSYS;
usbvision_reset_power_off_timer(usbvision);

if (usbvision->user)
Expand Down Expand Up @@ -402,6 +404,7 @@ static int usbvision_v4l2_open(struct file *file)

/* prepare queues */
usbvision_empty_framequeues(usbvision);
mutex_unlock(&usbvision->v4l2_lock);

PDEBUG(DBG_IO, "success");
return err_code;
Expand All @@ -421,6 +424,7 @@ static int usbvision_v4l2_close(struct file *file)

PDEBUG(DBG_IO, "close");

mutex_lock(&usbvision->v4l2_lock);
usbvision_audio_off(usbvision);
usbvision_restart_isoc(usbvision);
usbvision_stop_isoc(usbvision);
Expand All @@ -443,6 +447,7 @@ static int usbvision_v4l2_close(struct file *file)
printk(KERN_INFO "%s: Final disconnect\n", __func__);
usbvision_release(usbvision);
}
mutex_unlock(&usbvision->v4l2_lock);

PDEBUG(DBG_IO, "success");
return 0;
Expand Down Expand Up @@ -956,7 +961,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
return 0;
}

static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
static ssize_t usbvision_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
struct usb_usbvision *usbvision = video_drvdata(file);
Expand Down Expand Up @@ -1060,7 +1065,20 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
return count;
}

static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
struct usb_usbvision *usbvision = video_drvdata(file);
int res;

if (mutex_lock_interruptible(&usbvision->v4l2_lock))
return -ERESTARTSYS;
res = usbvision_read(file, buf, count, ppos);
mutex_unlock(&usbvision->v4l2_lock);
return res;
}

static int usbvision_mmap(struct file *file, struct vm_area_struct *vma)
{
unsigned long size = vma->vm_end - vma->vm_start,
start = vma->vm_start;
Expand Down Expand Up @@ -1107,6 +1125,17 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
return 0;
}

static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
{
struct usb_usbvision *usbvision = video_drvdata(file);
int res;

if (mutex_lock_interruptible(&usbvision->v4l2_lock))
return -ERESTARTSYS;
res = usbvision_mmap(file, vma);
mutex_unlock(&usbvision->v4l2_lock);
return res;
}

/*
* Here comes the stuff for radio on usbvision based devices
Expand All @@ -1119,6 +1148,8 @@ static int usbvision_radio_open(struct file *file)

PDEBUG(DBG_IO, "%s:", __func__);

if (mutex_lock_interruptible(&usbvision->v4l2_lock))
return -ERESTARTSYS;
if (usbvision->user) {
dev_err(&usbvision->rdev->dev,
"%s: Someone tried to open an already opened USBVision Radio!\n",
Expand Down Expand Up @@ -1156,6 +1187,7 @@ static int usbvision_radio_open(struct file *file)
}
}
out:
mutex_unlock(&usbvision->v4l2_lock);
return err_code;
}

Expand All @@ -1167,6 +1199,7 @@ static int usbvision_radio_close(struct file *file)

PDEBUG(DBG_IO, "");

mutex_lock(&usbvision->v4l2_lock);
/* Set packet size to 0 */
usbvision->iface_alt = 0;
err_code = usb_set_interface(usbvision->dev, usbvision->iface,
Expand All @@ -1186,6 +1219,7 @@ static int usbvision_radio_close(struct file *file)
usbvision_release(usbvision);
}

mutex_unlock(&usbvision->v4l2_lock);
PDEBUG(DBG_IO, "success");
return err_code;
}
Expand Down Expand Up @@ -1296,10 +1330,6 @@ static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
if (NULL == vdev)
return NULL;
*vdev = *vdev_template;
/* Locking in file operations other than ioctl should be done
by the driver, not the V4L2 core.
This driver needs auditing so that this flag can be removed. */
set_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags);
vdev->lock = &usbvision->v4l2_lock;
vdev->v4l2_dev = &usbvision->v4l2_dev;
snprintf(vdev->name, sizeof(vdev->name), "%s", name);
Expand Down

0 comments on commit 4d34570

Please sign in to comment.