V4L/DVB (9800): cx18: Eliminate q_io from stream buffer handling

Eliminate q_io from stream buffer handling in anticipation of upcoming
changes in buffer handling.  q_io was a holdover from ivtv and it's function
in cx18 was trivial and not necessary.  We just push things back onto the
front of q_full now, instead of maintaining a 1 buffer q_io queue.

Signed-off-by: Andy Walls <awalls@radix.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
diff --git a/drivers/media/video/cx18/cx18-driver.h b/drivers/media/video/cx18/cx18-driver.h
index 94c196a..f88d823 100644
--- a/drivers/media/video/cx18/cx18-driver.h
+++ b/drivers/media/video/cx18/cx18-driver.h
@@ -290,7 +290,6 @@
 	/* Buffer Queues */
 	struct cx18_queue q_free;	/* free buffers */
 	struct cx18_queue q_full;	/* full buffers */
-	struct cx18_queue q_io;		/* waiting for I/O */
 
 	/* DVB / Digital Transport */
 	struct cx18_dvb dvb;
diff --git a/drivers/media/video/cx18/cx18-fileops.c b/drivers/media/video/cx18/cx18-fileops.c
index 2c81175..504a1f9 100644
--- a/drivers/media/video/cx18/cx18-fileops.c
+++ b/drivers/media/video/cx18/cx18-fileops.c
@@ -195,11 +195,6 @@
 				return buf;
 		}
 
-		/* do we have leftover data? */
-		buf = cx18_dequeue(s, &s->q_io);
-		if (buf)
-			return buf;
-
 		/* do we have new data? */
 		buf = cx18_dequeue(s, &s->q_full);
 		if (buf) {
@@ -375,7 +370,7 @@
 					  cx->enc_mem,
 					1, buf->id, s->buf_size);
 			} else
-				cx18_enqueue(s, buf, &s->q_io);
+				cx18_push(s, buf, &s->q_full);
 		} else if (buf->readpos == buf->bytesused) {
 			int idx = cx->vbi.inserted_frame % CX18_VBI_FRAMES;
 
@@ -519,7 +514,7 @@
 	CX18_DEBUG_HI_FILE("Encoder poll\n");
 	poll_wait(filp, &s->waitq, wait);
 
-	if (atomic_read(&s->q_full.buffers) || atomic_read(&s->q_io.buffers))
+	if (atomic_read(&s->q_full.buffers))
 		return POLLIN | POLLRDNORM;
 	if (eof)
 		return POLLHUP;
diff --git a/drivers/media/video/cx18/cx18-queue.c b/drivers/media/video/cx18/cx18-queue.c
index 7b09c9a..fdfc83e 100644
--- a/drivers/media/video/cx18/cx18-queue.c
+++ b/drivers/media/video/cx18/cx18-queue.c
@@ -42,8 +42,8 @@
 	q->bytesused = 0;
 }
 
-void cx18_enqueue(struct cx18_stream *s, struct cx18_buffer *buf,
-		struct cx18_queue *q)
+void _cx18_enqueue(struct cx18_stream *s, struct cx18_buffer *buf,
+		   struct cx18_queue *q, int to_front)
 {
 	/* clear the buffer if it is going to be enqueued to the free queue */
 	if (q == &s->q_free) {
@@ -53,7 +53,10 @@
 		buf->skipped = 0;
 	}
 	mutex_lock(&s->qlock);
-	list_add_tail(&buf->list, &q->list);
+	if (to_front)
+		list_add(&buf->list, &q->list); /* LIFO */
+	else
+		list_add_tail(&buf->list, &q->list); /* FIFO */
 	atomic_inc(&q->buffers);
 	q->bytesused += buf->bytesused - buf->readpos;
 	mutex_unlock(&s->qlock);
@@ -159,7 +162,6 @@
 
 void cx18_flush_queues(struct cx18_stream *s)
 {
-	cx18_queue_flush(s, &s->q_io);
 	cx18_queue_flush(s, &s->q_full);
 }
 
diff --git a/drivers/media/video/cx18/cx18-queue.h b/drivers/media/video/cx18/cx18-queue.h
index ff50a2b..d184e55 100644
--- a/drivers/media/video/cx18/cx18-queue.h
+++ b/drivers/media/video/cx18/cx18-queue.h
@@ -43,9 +43,24 @@
 void cx18_buf_swap(struct cx18_buffer *buf);
 
 /* cx18_queue utility functions */
-void cx18_queue_init(struct cx18_queue *q);
+void _cx18_enqueue(struct cx18_stream *s, struct cx18_buffer *buf,
+		   struct cx18_queue *q, int to_front);
+
+static inline
 void cx18_enqueue(struct cx18_stream *s, struct cx18_buffer *buf,
-	struct cx18_queue *q);
+		  struct cx18_queue *q)
+{
+	_cx18_enqueue(s, buf, q, 0); /* FIFO */
+}
+
+static inline
+void cx18_push(struct cx18_stream *s, struct cx18_buffer *buf,
+	       struct cx18_queue *q)
+{
+	_cx18_enqueue(s, buf, q, 1); /* LIFO */
+}
+
+void cx18_queue_init(struct cx18_queue *q);
 struct cx18_buffer *cx18_dequeue(struct cx18_stream *s, struct cx18_queue *q);
 struct cx18_buffer *cx18_queue_get_buf(struct cx18_stream *s, u32 id,
 	u32 bytesused);
diff --git a/drivers/media/video/cx18/cx18-streams.c b/drivers/media/video/cx18/cx18-streams.c
index 8c8e92b..a1cf434 100644
--- a/drivers/media/video/cx18/cx18-streams.c
+++ b/drivers/media/video/cx18/cx18-streams.c
@@ -138,7 +138,6 @@
 	s->id = -1;
 	cx18_queue_init(&s->q_free);
 	cx18_queue_init(&s->q_full);
-	cx18_queue_init(&s->q_io);
 }
 
 static int cx18_prep_dev(struct cx18 *cx, int type)