aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-06-23 06:56:21 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-08-09 18:44:33 -0400
commitd76ebb67cc608f75af5e5d07c032036cbf43f675 (patch)
tree3a91709c3e7c89762a6ad6aa3e2ca1a0f9428a51 /drivers
parent6de7d14d7ab89454926d58cac40b46106ae2ed79 (diff)
[media] cpia2: 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')
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index a62a7b739991..5ca6f44b4c63 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -84,21 +84,26 @@ MODULE_VERSION(CPIA_VERSION);
84static int cpia2_open(struct file *file) 84static int cpia2_open(struct file *file)
85{ 85{
86 struct camera_data *cam = video_drvdata(file); 86 struct camera_data *cam = video_drvdata(file);
87 int retval = v4l2_fh_open(file); 87 int retval;
88 88
89 if (mutex_lock_interruptible(&cam->v4l2_lock))
90 return -ERESTARTSYS;
91 retval = v4l2_fh_open(file);
89 if (retval) 92 if (retval)
90 return retval; 93 goto open_unlock;
91 94
92 if (v4l2_fh_is_singular_file(file)) { 95 if (v4l2_fh_is_singular_file(file)) {
93 if (cpia2_allocate_buffers(cam)) { 96 if (cpia2_allocate_buffers(cam)) {
94 v4l2_fh_release(file); 97 v4l2_fh_release(file);
95 return -ENOMEM; 98 retval = -ENOMEM;
99 goto open_unlock;
96 } 100 }
97 101
98 /* reset the camera */ 102 /* reset the camera */
99 if (cpia2_reset_camera(cam) < 0) { 103 if (cpia2_reset_camera(cam) < 0) {
100 v4l2_fh_release(file); 104 v4l2_fh_release(file);
101 return -EIO; 105 retval = -EIO;
106 goto open_unlock;
102 } 107 }
103 108
104 cam->APP_len = 0; 109 cam->APP_len = 0;
@@ -106,7 +111,9 @@ static int cpia2_open(struct file *file)
106 } 111 }
107 112
108 cpia2_dbg_dump_registers(cam); 113 cpia2_dbg_dump_registers(cam);
109 return 0; 114open_unlock:
115 mutex_unlock(&cam->v4l2_lock);
116 return retval;
110} 117}
111 118
112/****************************************************************************** 119/******************************************************************************
@@ -119,6 +126,7 @@ static int cpia2_close(struct file *file)
119 struct video_device *dev = video_devdata(file); 126 struct video_device *dev = video_devdata(file);
120 struct camera_data *cam = video_get_drvdata(dev); 127 struct camera_data *cam = video_get_drvdata(dev);
121 128
129 mutex_lock(&cam->v4l2_lock);
122 if (video_is_registered(&cam->vdev) && v4l2_fh_is_singular_file(file)) { 130 if (video_is_registered(&cam->vdev) && v4l2_fh_is_singular_file(file)) {
123 cpia2_usb_stream_stop(cam); 131 cpia2_usb_stream_stop(cam);
124 132
@@ -133,6 +141,7 @@ static int cpia2_close(struct file *file)
133 cam->stream_fh = NULL; 141 cam->stream_fh = NULL;
134 cam->mmapped = 0; 142 cam->mmapped = 0;
135 } 143 }
144 mutex_unlock(&cam->v4l2_lock);
136 return v4l2_fh_release(file); 145 return v4l2_fh_release(file);
137} 146}
138 147
@@ -146,11 +155,16 @@ static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
146{ 155{
147 struct camera_data *cam = video_drvdata(file); 156 struct camera_data *cam = video_drvdata(file);
148 int noblock = file->f_flags&O_NONBLOCK; 157 int noblock = file->f_flags&O_NONBLOCK;
158 ssize_t ret;
149 159
150 if(!cam) 160 if(!cam)
151 return -EINVAL; 161 return -EINVAL;
152 162
153 return cpia2_read(cam, buf, count, noblock); 163 if (mutex_lock_interruptible(&cam->v4l2_lock))
164 return -ERESTARTSYS;
165 ret = cpia2_read(cam, buf, count, noblock);
166 mutex_unlock(&cam->v4l2_lock);
167 return ret;
154} 168}
155 169
156 170
@@ -162,8 +176,12 @@ static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
162static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait) 176static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait)
163{ 177{
164 struct camera_data *cam = video_drvdata(filp); 178 struct camera_data *cam = video_drvdata(filp);
179 unsigned int res;
165 180
166 return cpia2_poll(cam, filp, wait); 181 mutex_lock(&cam->v4l2_lock);
182 res = cpia2_poll(cam, filp, wait);
183 mutex_unlock(&cam->v4l2_lock);
184 return res;
167} 185}
168 186
169 187
@@ -987,10 +1005,13 @@ static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
987 struct camera_data *cam = video_drvdata(file); 1005 struct camera_data *cam = video_drvdata(file);
988 int retval; 1006 int retval;
989 1007
1008 if (mutex_lock_interruptible(&cam->v4l2_lock))
1009 return -ERESTARTSYS;
990 retval = cpia2_remap_buffer(cam, area); 1010 retval = cpia2_remap_buffer(cam, area);
991 1011
992 if(!retval) 1012 if(!retval)
993 cam->stream_fh = file->private_data; 1013 cam->stream_fh = file->private_data;
1014 mutex_unlock(&cam->v4l2_lock);
994 return retval; 1015 return retval;
995} 1016}
996 1017
@@ -1147,10 +1168,6 @@ int cpia2_register_camera(struct camera_data *cam)
1147 cam->vdev.ctrl_handler = hdl; 1168 cam->vdev.ctrl_handler = hdl;
1148 cam->vdev.v4l2_dev = &cam->v4l2_dev; 1169 cam->vdev.v4l2_dev = &cam->v4l2_dev;
1149 set_bit(V4L2_FL_USE_FH_PRIO, &cam->vdev.flags); 1170 set_bit(V4L2_FL_USE_FH_PRIO, &cam->vdev.flags);
1150 /* Locking in file operations other than ioctl should be done
1151 by the driver, not the V4L2 core.
1152 This driver needs auditing so that this flag can be removed. */
1153 set_bit(V4L2_FL_LOCK_ALL_FOPS, &cam->vdev.flags);
1154 1171
1155 reset_camera_struct_v4l(cam); 1172 reset_camera_struct_v4l(cam);
1156 1173