public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Walls <awalls@md.metrocast.net>
To: linux-media@vger.kernel.org
Subject: [PATCH 08/13] lirc_zilog: Always allocate a Rx lirc_buffer object
Date: Thu, 17 Feb 2011 20:18:30 -0500	[thread overview]
Message-ID: <1297991910.9399.24.camel@localhost> (raw)
In-Reply-To: <1297991502.9399.16.camel@localhost>


Always allocate a lirc_buffer object, instead of just upon setup of
the Rx i2c_client.  If we do not allocate a lirc_buffer object, because
we are not handling the Rx i2c_client, lirc_dev will allocate its own
lirc_buffer anyway and not tell us about its location.

Signed-off-by: Andy Walls <awalls@md.metrocast.net>
---
 drivers/staging/lirc/lirc_zilog.c |   62 ++++++++++++++++++------------------
 1 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/lirc/lirc_zilog.c b/drivers/staging/lirc/lirc_zilog.c
index 0f2fa58..a94b10a 100644
--- a/drivers/staging/lirc/lirc_zilog.c
+++ b/drivers/staging/lirc/lirc_zilog.c
@@ -67,9 +67,6 @@ struct IR_rx {
 	/* RX device */
 	struct i2c_client *c;
 
-	/* RX device buffer */
-	struct lirc_buffer buf;
-
 	/* RX polling thread data */
 	struct task_struct *task;
 
@@ -91,6 +88,7 @@ struct IR {
 	struct list_head list;
 
 	struct lirc_driver l;
+	struct lirc_buffer rbuf;
 
 	struct mutex ir_lock;
 	atomic_t open_count;
@@ -157,12 +155,13 @@ static int add_to_buf(struct IR *ir)
 	int ret;
 	int failures = 0;
 	unsigned char sendbuf[1] = { 0 };
+	struct lirc_buffer *rbuf = ir->l.rbuf;
 	struct IR_rx *rx = ir->rx;
 
 	if (rx == NULL)
 		return -ENXIO;
 
-	if (lirc_buffer_full(&rx->buf)) {
+	if (lirc_buffer_full(rbuf)) {
 		dprintk("buffer overflow\n");
 		return -EOVERFLOW;
 	}
@@ -250,9 +249,9 @@ static int add_to_buf(struct IR *ir)
 		codes[1] = code & 0xff;
 
 		/* return it */
-		lirc_buffer_write(&rx->buf, codes);
+		lirc_buffer_write(rbuf, codes);
 		++got_data;
-	} while (!lirc_buffer_full(&rx->buf));
+	} while (!lirc_buffer_full(rbuf));
 
 	return 0;
 }
@@ -270,7 +269,7 @@ static int add_to_buf(struct IR *ir)
 static int lirc_thread(void *arg)
 {
 	struct IR *ir = arg;
-	struct IR_rx *rx = ir->rx;
+	struct lirc_buffer *rbuf = ir->l.rbuf;
 
 	dprintk("poll thread started\n");
 
@@ -297,7 +296,7 @@ static int lirc_thread(void *arg)
 		if (kthread_should_stop())
 			break;
 		if (!add_to_buf(ir))
-			wake_up_interruptible(&rx->buf.wait_poll);
+			wake_up_interruptible(&rbuf->wait_poll);
 	}
 
 	dprintk("poll thread ended\n");
@@ -716,6 +715,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
 {
 	struct IR *ir = filep->private_data;
 	struct IR_rx *rx = ir->rx;
+	struct lirc_buffer *rbuf = ir->l.rbuf;
 	int ret = 0, written = 0;
 	unsigned int m;
 	DECLARE_WAITQUEUE(wait, current);
@@ -724,7 +724,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
 	if (rx == NULL)
 		return -ENODEV;
 
-	if (n % rx->buf.chunk_size) {
+	if (n % rbuf->chunk_size) {
 		dprintk("read result = -EINVAL\n");
 		return -EINVAL;
 	}
@@ -734,7 +734,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
 	 * to avoid losing scan code (in case when queue is awaken somewhere
 	 * between while condition checking and scheduling)
 	 */
-	add_wait_queue(&rx->buf.wait_poll, &wait);
+	add_wait_queue(&rbuf->wait_poll, &wait);
 	set_current_state(TASK_INTERRUPTIBLE);
 
 	/*
@@ -742,7 +742,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
 	 * mode and 'copy_to_user' is happy, wait for data.
 	 */
 	while (written < n && ret == 0) {
-		if (lirc_buffer_empty(&rx->buf)) {
+		if (lirc_buffer_empty(rbuf)) {
 			/*
 			 * According to the read(2) man page, 'written' can be
 			 * returned as less than 'n', instead of blocking
@@ -762,17 +762,17 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
 			schedule();
 			set_current_state(TASK_INTERRUPTIBLE);
 		} else {
-			unsigned char buf[rx->buf.chunk_size];
-			m = lirc_buffer_read(&rx->buf, buf);
-			if (m == rx->buf.chunk_size) {
+			unsigned char buf[rbuf->chunk_size];
+			m = lirc_buffer_read(rbuf, buf);
+			if (m == rbuf->chunk_size) {
 				ret = copy_to_user((void *)outbuf+written, buf,
-						   rx->buf.chunk_size);
-				written += rx->buf.chunk_size;
+						   rbuf->chunk_size);
+				written += rbuf->chunk_size;
 			}
 		}
 	}
 
-	remove_wait_queue(&rx->buf.wait_poll, &wait);
+	remove_wait_queue(&rbuf->wait_poll, &wait);
 	set_current_state(TASK_RUNNING);
 
 	dprintk("read result = %d (%s)\n", ret, ret ? "Error" : "OK");
@@ -978,6 +978,7 @@ static unsigned int poll(struct file *filep, poll_table *wait)
 {
 	struct IR *ir = filep->private_data;
 	struct IR_rx *rx = ir->rx;
+	struct lirc_buffer *rbuf = ir->l.rbuf;
 	unsigned int ret;
 
 	dprintk("poll called\n");
@@ -995,10 +996,10 @@ static unsigned int poll(struct file *filep, poll_table *wait)
 	 * Add our lirc_buffer's wait_queue to the poll_table. A wake up on
 	 * that buffer's wait queue indicates we may have a new poll status.
 	 */
-	poll_wait(filep, &rx->buf.wait_poll, wait);
+	poll_wait(filep, &rbuf->wait_poll, wait);
 
 	/* Indicate what ops could happen immediately without blocking */
-	ret = lirc_buffer_empty(&rx->buf) ? 0 : (POLLIN|POLLRDNORM);
+	ret = lirc_buffer_empty(rbuf) ? 0 : (POLLIN|POLLRDNORM);
 
 	dprintk("poll result = %s\n", ret ? "POLLIN|POLLRDNORM" : 0);
 	return ret;
@@ -1209,8 +1210,6 @@ static int ir_remove(struct i2c_client *client)
 	/* Good-bye Rx */
 	destroy_rx_kthread(ir->rx);
 	if (ir->rx != NULL) {
-		if (ir->rx->buf.fifo_initialized)
-			lirc_buffer_free(&ir->rx->buf);
 		i2c_set_clientdata(ir->rx->c, NULL);
 		kfree(ir->rx);
 	}
@@ -1222,6 +1221,8 @@ static int ir_remove(struct i2c_client *client)
 	}
 
 	/* Good-bye IR */
+	if (ir->rbuf.fifo_initialized)
+		lirc_buffer_free(&ir->rbuf);
 	del_ir_device(ir);
 	kfree(ir);
 
@@ -1292,11 +1293,17 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver));
 		ir->l.minor       = minor; /* module option */
 		ir->l.code_length = 13;
-		ir->l.rbuf	  = NULL;
+		ir->l.chunk_size  = 2;
+		ir->l.buffer_size = BUFLEN / 2;
+		ir->l.rbuf	  = &ir->rbuf;
 		ir->l.fops	  = &lirc_fops;
 		ir->l.data	  = ir;
 		ir->l.dev         = &adap->dev;
 		ir->l.sample_rate = 0;
+		ret = lirc_buffer_init(ir->l.rbuf,
+				       ir->l.chunk_size, ir->l.buffer_size);
+		if (ret)
+			goto out_free_ir;
 	}
 
 	if (tx_probe) {
@@ -1319,16 +1326,9 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
 			goto out_free_xx;
 		}
 
-		ret = lirc_buffer_init(&ir->rx->buf, 2, BUFLEN / 2);
-		if (ret)
-			goto out_free_xx;
-
 		ir->rx->c = client;
 		ir->rx->hdpvr_data_fmt =
 			       (id->driver_data & ID_FLAG_HDPVR) ? true : false;
-
-		/* set lirc_dev stuff */
-		ir->l.rbuf = &ir->rx->buf;
 	}
 
 	i2c_set_clientdata(client, ir);
@@ -1388,8 +1388,6 @@ out_free_thread:
 	destroy_rx_kthread(ir->rx);
 out_free_xx:
 	if (ir->rx != NULL) {
-		if (ir->rx->buf.fifo_initialized)
-			lirc_buffer_free(&ir->rx->buf);
 		if (ir->rx->c != NULL)
 			i2c_set_clientdata(ir->rx->c, NULL);
 		kfree(ir->rx);
@@ -1399,6 +1397,8 @@ out_free_xx:
 			i2c_set_clientdata(ir->tx->c, NULL);
 		kfree(ir->tx);
 	}
+	if (ir->rbuf.fifo_initialized)
+		lirc_buffer_free(&ir->rbuf);
 out_free_ir:
 	del_ir_device(ir);
 	kfree(ir);
-- 
1.7.2.1




  parent reply	other threads:[~2011-02-18  1:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18  1:11 [PATCH 0/13] lirc_zilog: Ref-counting and locking cleanup Andy Walls
2011-02-18  1:12 ` [PATCH 01/13] lirc_zilog: Restore checks for existence of the IR_tx object Andy Walls
2011-02-18  1:13 ` [PATCH 02/13] lirc_zilog: Remove broken, ineffective reference counting Andy Walls
2011-02-18  1:14 ` [PATCH 03/13] lirc_zilog: Convert ir_device instance array to a linked list Andy Walls
2011-02-18  1:15 ` [PATCH 04/13] lirc_zilog: Convert the instance open count to an atomic_t Andy Walls
2011-02-18  1:15 ` [PATCH 05/13] lirc_zilog: Use kernel standard methods for marking device non-seekable Andy Walls
2011-02-18  1:16 ` [PATCH 06/13] lirc_zilog: Don't acquire the rx->buf_lock in the poll() function Andy Walls
2011-02-18  1:17 ` [PATCH 07/13] lirc_zilog: Remove unneeded rx->buf_lock Andy Walls
2011-02-18  1:18 ` Andy Walls [this message]
2011-02-18  1:19 ` [PATCH 09/13] lirc_zilog: Move constants from ir_probe() into the lirc_driver template Andy Walls
2011-02-18  1:20 ` [PATCH 10/13] lirc_zilog: Add ref counting of struct IR, IR_tx, and IR_rx Andy Walls
2011-02-18  1:20 ` [PATCH 11/13] lirc_zilog: Add locking of the i2c_clients when in use Andy Walls
2011-02-18  1:21 ` [PATCH 12/13] lirc_zilog: Fix somewhat confusing information messages in ir_probe() Andy Walls
2011-02-18  1:22 ` [PATCH 13/13] lirc_zilog: Update TODO list based on work completed and revised plans Andy Walls
2011-03-06  4:00 ` [PATCH 0/13] lirc_zilog: Ref-counting and locking cleanup Jarod Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1297991910.9399.24.camel@localhost \
    --to=awalls@md.metrocast.net \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox