aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-06-23 07:03:50 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-08-09 18:45:19 -0400
commit4d345708ca2688a06ca22e758d3eecc0352f5461 (patch)
treefcc159e1d7998106efc930e9b0028ae268fd248b /drivers/media
parentd76ebb67cc608f75af5e5d07c032036cbf43f675 (diff)
[media] usbvision: remove V4L2_FL_LOCK_ALL_FOPS
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>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 9bd8f084f348..8a4317979a43 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -349,6 +349,8 @@ static int usbvision_v4l2_open(struct file *file)
349 349
350 PDEBUG(DBG_IO, "open"); 350 PDEBUG(DBG_IO, "open");
351 351
352 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
353 return -ERESTARTSYS;
352 usbvision_reset_power_off_timer(usbvision); 354 usbvision_reset_power_off_timer(usbvision);
353 355
354 if (usbvision->user) 356 if (usbvision->user)
@@ -402,6 +404,7 @@ static int usbvision_v4l2_open(struct file *file)
402 404
403 /* prepare queues */ 405 /* prepare queues */
404 usbvision_empty_framequeues(usbvision); 406 usbvision_empty_framequeues(usbvision);
407 mutex_unlock(&usbvision->v4l2_lock);
405 408
406 PDEBUG(DBG_IO, "success"); 409 PDEBUG(DBG_IO, "success");
407 return err_code; 410 return err_code;
@@ -421,6 +424,7 @@ static int usbvision_v4l2_close(struct file *file)
421 424
422 PDEBUG(DBG_IO, "close"); 425 PDEBUG(DBG_IO, "close");
423 426
427 mutex_lock(&usbvision->v4l2_lock);
424 usbvision_audio_off(usbvision); 428 usbvision_audio_off(usbvision);
425 usbvision_restart_isoc(usbvision); 429 usbvision_restart_isoc(usbvision);
426 usbvision_stop_isoc(usbvision); 430 usbvision_stop_isoc(usbvision);
@@ -443,6 +447,7 @@ static int usbvision_v4l2_close(struct file *file)
443 printk(KERN_INFO "%s: Final disconnect\n", __func__); 447 printk(KERN_INFO "%s: Final disconnect\n", __func__);
444 usbvision_release(usbvision); 448 usbvision_release(usbvision);
445 } 449 }
450 mutex_unlock(&usbvision->v4l2_lock);
446 451
447 PDEBUG(DBG_IO, "success"); 452 PDEBUG(DBG_IO, "success");
448 return 0; 453 return 0;
@@ -956,7 +961,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
956 return 0; 961 return 0;
957} 962}
958 963
959static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf, 964static ssize_t usbvision_read(struct file *file, char __user *buf,
960 size_t count, loff_t *ppos) 965 size_t count, loff_t *ppos)
961{ 966{
962 struct usb_usbvision *usbvision = video_drvdata(file); 967 struct usb_usbvision *usbvision = video_drvdata(file);
@@ -1060,7 +1065,20 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1060 return count; 1065 return count;
1061} 1066}
1062 1067
1063static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma) 1068static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1069 size_t count, loff_t *ppos)
1070{
1071 struct usb_usbvision *usbvision = video_drvdata(file);
1072 int res;
1073
1074 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
1075 return -ERESTARTSYS;
1076 res = usbvision_read(file, buf, count, ppos);
1077 mutex_unlock(&usbvision->v4l2_lock);
1078 return res;
1079}
1080
1081static int usbvision_mmap(struct file *file, struct vm_area_struct *vma)
1064{ 1082{
1065 unsigned long size = vma->vm_end - vma->vm_start, 1083 unsigned long size = vma->vm_end - vma->vm_start,
1066 start = vma->vm_start; 1084 start = vma->vm_start;
@@ -1107,6 +1125,17 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1107 return 0; 1125 return 0;
1108} 1126}
1109 1127
1128static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1129{
1130 struct usb_usbvision *usbvision = video_drvdata(file);
1131 int res;
1132
1133 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
1134 return -ERESTARTSYS;
1135 res = usbvision_mmap(file, vma);
1136 mutex_unlock(&usbvision->v4l2_lock);
1137 return res;
1138}
1110 1139
1111/* 1140/*
1112 * Here comes the stuff for radio on usbvision based devices 1141 * Here comes the stuff for radio on usbvision based devices
@@ -1119,6 +1148,8 @@ static int usbvision_radio_open(struct file *file)
1119 1148
1120 PDEBUG(DBG_IO, "%s:", __func__); 1149 PDEBUG(DBG_IO, "%s:", __func__);
1121 1150
1151 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
1152 return -ERESTARTSYS;
1122 if (usbvision->user) { 1153 if (usbvision->user) {
1123 dev_err(&usbvision->rdev->dev, 1154 dev_err(&usbvision->rdev->dev,
1124 "%s: Someone tried to open an already opened USBVision Radio!\n", 1155 "%s: Someone tried to open an already opened USBVision Radio!\n",
@@ -1156,6 +1187,7 @@ static int usbvision_radio_open(struct file *file)
1156 } 1187 }
1157 } 1188 }
1158out: 1189out:
1190 mutex_unlock(&usbvision->v4l2_lock);
1159 return err_code; 1191 return err_code;
1160} 1192}
1161 1193
@@ -1167,6 +1199,7 @@ static int usbvision_radio_close(struct file *file)
1167 1199
1168 PDEBUG(DBG_IO, ""); 1200 PDEBUG(DBG_IO, "");
1169 1201
1202 mutex_lock(&usbvision->v4l2_lock);
1170 /* Set packet size to 0 */ 1203 /* Set packet size to 0 */
1171 usbvision->iface_alt = 0; 1204 usbvision->iface_alt = 0;
1172 err_code = usb_set_interface(usbvision->dev, usbvision->iface, 1205 err_code = usb_set_interface(usbvision->dev, usbvision->iface,
@@ -1186,6 +1219,7 @@ static int usbvision_radio_close(struct file *file)
1186 usbvision_release(usbvision); 1219 usbvision_release(usbvision);
1187 } 1220 }
1188 1221
1222 mutex_unlock(&usbvision->v4l2_lock);
1189 PDEBUG(DBG_IO, "success"); 1223 PDEBUG(DBG_IO, "success");
1190 return err_code; 1224 return err_code;
1191} 1225}
@@ -1296,10 +1330,6 @@ static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
1296 if (NULL == vdev) 1330 if (NULL == vdev)
1297 return NULL; 1331 return NULL;
1298 *vdev = *vdev_template; 1332 *vdev = *vdev_template;
1299 /* Locking in file operations other than ioctl should be done
1300 by the driver, not the V4L2 core.
1301 This driver needs auditing so that this flag can be removed. */
1302 set_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags);
1303 vdev->lock = &usbvision->v4l2_lock; 1333 vdev->lock = &usbvision->v4l2_lock;
1304 vdev->v4l2_dev = &usbvision->v4l2_dev; 1334 vdev->v4l2_dev = &usbvision->v4l2_dev;
1305 snprintf(vdev->name, sizeof(vdev->name), "%s", name); 1335 snprintf(vdev->name, sizeof(vdev->name), "%s", name);