aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/uvc/uvc_queue.c57
-rw-r--r--drivers/media/video/uvc/uvc_v4l2.c2
2 files changed, 34 insertions, 25 deletions
diff --git a/drivers/media/video/uvc/uvc_queue.c b/drivers/media/video/uvc/uvc_queue.c
index ed6d5449741c..32c18229863b 100644
--- a/drivers/media/video/uvc/uvc_queue.c
+++ b/drivers/media/video/uvc/uvc_queue.c
@@ -90,6 +90,39 @@ void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
90} 90}
91 91
92/* 92/*
93 * Free the video buffers.
94 *
95 * This function must be called with the queue lock held.
96 */
97static int __uvc_free_buffers(struct uvc_video_queue *queue)
98{
99 unsigned int i;
100
101 for (i = 0; i < queue->count; ++i) {
102 if (queue->buffer[i].vma_use_count != 0)
103 return -EBUSY;
104 }
105
106 if (queue->count) {
107 vfree(queue->mem);
108 queue->count = 0;
109 }
110
111 return 0;
112}
113
114int uvc_free_buffers(struct uvc_video_queue *queue)
115{
116 int ret;
117
118 mutex_lock(&queue->mutex);
119 ret = __uvc_free_buffers(queue);
120 mutex_unlock(&queue->mutex);
121
122 return ret;
123}
124
125/*
93 * Allocate the video buffers. 126 * Allocate the video buffers.
94 * 127 *
95 * Pages are reserved to make sure they will not be swapped, as they will be 128 * Pages are reserved to make sure they will not be swapped, as they will be
@@ -110,7 +143,7 @@ int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers,
110 143
111 mutex_lock(&queue->mutex); 144 mutex_lock(&queue->mutex);
112 145
113 if ((ret = uvc_free_buffers(queue)) < 0) 146 if ((ret = __uvc_free_buffers(queue)) < 0)
114 goto done; 147 goto done;
115 148
116 /* Bail out if no buffers should be allocated. */ 149 /* Bail out if no buffers should be allocated. */
@@ -152,28 +185,6 @@ done:
152} 185}
153 186
154/* 187/*
155 * Free the video buffers.
156 *
157 * This function must be called with the queue lock held.
158 */
159int uvc_free_buffers(struct uvc_video_queue *queue)
160{
161 unsigned int i;
162
163 for (i = 0; i < queue->count; ++i) {
164 if (queue->buffer[i].vma_use_count != 0)
165 return -EBUSY;
166 }
167
168 if (queue->count) {
169 vfree(queue->mem);
170 queue->count = 0;
171 }
172
173 return 0;
174}
175
176/*
177 * Check if buffers have been allocated. 188 * Check if buffers have been allocated.
178 */ 189 */
179int uvc_queue_allocated(struct uvc_video_queue *queue) 190int uvc_queue_allocated(struct uvc_video_queue *queue)
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index 0f865e97cf48..0fd9848bd9d7 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -494,11 +494,9 @@ static int uvc_v4l2_release(struct file *file)
494 if (uvc_has_privileges(handle)) { 494 if (uvc_has_privileges(handle)) {
495 uvc_video_enable(stream, 0); 495 uvc_video_enable(stream, 0);
496 496
497 mutex_lock(&stream->queue.mutex);
498 if (uvc_free_buffers(&stream->queue) < 0) 497 if (uvc_free_buffers(&stream->queue) < 0)
499 uvc_printk(KERN_ERR, "uvc_v4l2_release: Unable to " 498 uvc_printk(KERN_ERR, "uvc_v4l2_release: Unable to "
500 "free buffers.\n"); 499 "free buffers.\n");
501 mutex_unlock(&stream->queue.mutex);
502 } 500 }
503 501
504 /* Release the file handle. */ 502 /* Release the file handle. */