diff options
author | Andy Walls <awalls@md.metrocast.net> | 2011-01-27 20:32:44 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-22 18:23:56 -0400 |
commit | bcbd165509da05a2317ac7dce3c6b952e98a01ef (patch) | |
tree | 52df6f258b3b5166351b91374f434868e5d03d05 /drivers/staging | |
parent | 8152b760effbff11cb4eef6292ae3b47719ee792 (diff) |
[media] lirc_zilog: Always allocate a Rx lirc_buffer object
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>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | 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 a62b94bf6a1a..053fddb8e448 100644 --- a/drivers/staging/lirc/lirc_zilog.c +++ b/drivers/staging/lirc/lirc_zilog.c | |||
@@ -67,9 +67,6 @@ struct IR_rx { | |||
67 | /* RX device */ | 67 | /* RX device */ |
68 | struct i2c_client *c; | 68 | struct i2c_client *c; |
69 | 69 | ||
70 | /* RX device buffer */ | ||
71 | struct lirc_buffer buf; | ||
72 | |||
73 | /* RX polling thread data */ | 70 | /* RX polling thread data */ |
74 | struct task_struct *task; | 71 | struct task_struct *task; |
75 | 72 | ||
@@ -91,6 +88,7 @@ struct IR { | |||
91 | struct list_head list; | 88 | struct list_head list; |
92 | 89 | ||
93 | struct lirc_driver l; | 90 | struct lirc_driver l; |
91 | struct lirc_buffer rbuf; | ||
94 | 92 | ||
95 | struct mutex ir_lock; | 93 | struct mutex ir_lock; |
96 | atomic_t open_count; | 94 | atomic_t open_count; |
@@ -157,12 +155,13 @@ static int add_to_buf(struct IR *ir) | |||
157 | int ret; | 155 | int ret; |
158 | int failures = 0; | 156 | int failures = 0; |
159 | unsigned char sendbuf[1] = { 0 }; | 157 | unsigned char sendbuf[1] = { 0 }; |
158 | struct lirc_buffer *rbuf = ir->l.rbuf; | ||
160 | struct IR_rx *rx = ir->rx; | 159 | struct IR_rx *rx = ir->rx; |
161 | 160 | ||
162 | if (rx == NULL) | 161 | if (rx == NULL) |
163 | return -ENXIO; | 162 | return -ENXIO; |
164 | 163 | ||
165 | if (lirc_buffer_full(&rx->buf)) { | 164 | if (lirc_buffer_full(rbuf)) { |
166 | dprintk("buffer overflow\n"); | 165 | dprintk("buffer overflow\n"); |
167 | return -EOVERFLOW; | 166 | return -EOVERFLOW; |
168 | } | 167 | } |
@@ -250,9 +249,9 @@ static int add_to_buf(struct IR *ir) | |||
250 | codes[1] = code & 0xff; | 249 | codes[1] = code & 0xff; |
251 | 250 | ||
252 | /* return it */ | 251 | /* return it */ |
253 | lirc_buffer_write(&rx->buf, codes); | 252 | lirc_buffer_write(rbuf, codes); |
254 | ++got_data; | 253 | ++got_data; |
255 | } while (!lirc_buffer_full(&rx->buf)); | 254 | } while (!lirc_buffer_full(rbuf)); |
256 | 255 | ||
257 | return 0; | 256 | return 0; |
258 | } | 257 | } |
@@ -270,7 +269,7 @@ static int add_to_buf(struct IR *ir) | |||
270 | static int lirc_thread(void *arg) | 269 | static int lirc_thread(void *arg) |
271 | { | 270 | { |
272 | struct IR *ir = arg; | 271 | struct IR *ir = arg; |
273 | struct IR_rx *rx = ir->rx; | 272 | struct lirc_buffer *rbuf = ir->l.rbuf; |
274 | 273 | ||
275 | dprintk("poll thread started\n"); | 274 | dprintk("poll thread started\n"); |
276 | 275 | ||
@@ -297,7 +296,7 @@ static int lirc_thread(void *arg) | |||
297 | if (kthread_should_stop()) | 296 | if (kthread_should_stop()) |
298 | break; | 297 | break; |
299 | if (!add_to_buf(ir)) | 298 | if (!add_to_buf(ir)) |
300 | wake_up_interruptible(&rx->buf.wait_poll); | 299 | wake_up_interruptible(&rbuf->wait_poll); |
301 | } | 300 | } |
302 | 301 | ||
303 | dprintk("poll thread ended\n"); | 302 | dprintk("poll thread ended\n"); |
@@ -716,6 +715,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) | |||
716 | { | 715 | { |
717 | struct IR *ir = filep->private_data; | 716 | struct IR *ir = filep->private_data; |
718 | struct IR_rx *rx = ir->rx; | 717 | struct IR_rx *rx = ir->rx; |
718 | struct lirc_buffer *rbuf = ir->l.rbuf; | ||
719 | int ret = 0, written = 0; | 719 | int ret = 0, written = 0; |
720 | unsigned int m; | 720 | unsigned int m; |
721 | DECLARE_WAITQUEUE(wait, current); | 721 | DECLARE_WAITQUEUE(wait, current); |
@@ -724,7 +724,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) | |||
724 | if (rx == NULL) | 724 | if (rx == NULL) |
725 | return -ENODEV; | 725 | return -ENODEV; |
726 | 726 | ||
727 | if (n % rx->buf.chunk_size) { | 727 | if (n % rbuf->chunk_size) { |
728 | dprintk("read result = -EINVAL\n"); | 728 | dprintk("read result = -EINVAL\n"); |
729 | return -EINVAL; | 729 | return -EINVAL; |
730 | } | 730 | } |
@@ -734,7 +734,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) | |||
734 | * to avoid losing scan code (in case when queue is awaken somewhere | 734 | * to avoid losing scan code (in case when queue is awaken somewhere |
735 | * between while condition checking and scheduling) | 735 | * between while condition checking and scheduling) |
736 | */ | 736 | */ |
737 | add_wait_queue(&rx->buf.wait_poll, &wait); | 737 | add_wait_queue(&rbuf->wait_poll, &wait); |
738 | set_current_state(TASK_INTERRUPTIBLE); | 738 | set_current_state(TASK_INTERRUPTIBLE); |
739 | 739 | ||
740 | /* | 740 | /* |
@@ -742,7 +742,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) | |||
742 | * mode and 'copy_to_user' is happy, wait for data. | 742 | * mode and 'copy_to_user' is happy, wait for data. |
743 | */ | 743 | */ |
744 | while (written < n && ret == 0) { | 744 | while (written < n && ret == 0) { |
745 | if (lirc_buffer_empty(&rx->buf)) { | 745 | if (lirc_buffer_empty(rbuf)) { |
746 | /* | 746 | /* |
747 | * According to the read(2) man page, 'written' can be | 747 | * According to the read(2) man page, 'written' can be |
748 | * returned as less than 'n', instead of blocking | 748 | * 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) | |||
762 | schedule(); | 762 | schedule(); |
763 | set_current_state(TASK_INTERRUPTIBLE); | 763 | set_current_state(TASK_INTERRUPTIBLE); |
764 | } else { | 764 | } else { |
765 | unsigned char buf[rx->buf.chunk_size]; | 765 | unsigned char buf[rbuf->chunk_size]; |
766 | m = lirc_buffer_read(&rx->buf, buf); | 766 | m = lirc_buffer_read(rbuf, buf); |
767 | if (m == rx->buf.chunk_size) { | 767 | if (m == rbuf->chunk_size) { |
768 | ret = copy_to_user((void *)outbuf+written, buf, | 768 | ret = copy_to_user((void *)outbuf+written, buf, |
769 | rx->buf.chunk_size); | 769 | rbuf->chunk_size); |
770 | written += rx->buf.chunk_size; | 770 | written += rbuf->chunk_size; |
771 | } | 771 | } |
772 | } | 772 | } |
773 | } | 773 | } |
774 | 774 | ||
775 | remove_wait_queue(&rx->buf.wait_poll, &wait); | 775 | remove_wait_queue(&rbuf->wait_poll, &wait); |
776 | set_current_state(TASK_RUNNING); | 776 | set_current_state(TASK_RUNNING); |
777 | 777 | ||
778 | dprintk("read result = %d (%s)\n", ret, ret ? "Error" : "OK"); | 778 | dprintk("read result = %d (%s)\n", ret, ret ? "Error" : "OK"); |
@@ -978,6 +978,7 @@ static unsigned int poll(struct file *filep, poll_table *wait) | |||
978 | { | 978 | { |
979 | struct IR *ir = filep->private_data; | 979 | struct IR *ir = filep->private_data; |
980 | struct IR_rx *rx = ir->rx; | 980 | struct IR_rx *rx = ir->rx; |
981 | struct lirc_buffer *rbuf = ir->l.rbuf; | ||
981 | unsigned int ret; | 982 | unsigned int ret; |
982 | 983 | ||
983 | dprintk("poll called\n"); | 984 | dprintk("poll called\n"); |
@@ -995,10 +996,10 @@ static unsigned int poll(struct file *filep, poll_table *wait) | |||
995 | * Add our lirc_buffer's wait_queue to the poll_table. A wake up on | 996 | * Add our lirc_buffer's wait_queue to the poll_table. A wake up on |
996 | * that buffer's wait queue indicates we may have a new poll status. | 997 | * that buffer's wait queue indicates we may have a new poll status. |
997 | */ | 998 | */ |
998 | poll_wait(filep, &rx->buf.wait_poll, wait); | 999 | poll_wait(filep, &rbuf->wait_poll, wait); |
999 | 1000 | ||
1000 | /* Indicate what ops could happen immediately without blocking */ | 1001 | /* Indicate what ops could happen immediately without blocking */ |
1001 | ret = lirc_buffer_empty(&rx->buf) ? 0 : (POLLIN|POLLRDNORM); | 1002 | ret = lirc_buffer_empty(rbuf) ? 0 : (POLLIN|POLLRDNORM); |
1002 | 1003 | ||
1003 | dprintk("poll result = %s\n", ret ? "POLLIN|POLLRDNORM" : "none"); | 1004 | dprintk("poll result = %s\n", ret ? "POLLIN|POLLRDNORM" : "none"); |
1004 | return ret; | 1005 | return ret; |
@@ -1209,8 +1210,6 @@ static int ir_remove(struct i2c_client *client) | |||
1209 | /* Good-bye Rx */ | 1210 | /* Good-bye Rx */ |
1210 | destroy_rx_kthread(ir->rx); | 1211 | destroy_rx_kthread(ir->rx); |
1211 | if (ir->rx != NULL) { | 1212 | if (ir->rx != NULL) { |
1212 | if (ir->rx->buf.fifo_initialized) | ||
1213 | lirc_buffer_free(&ir->rx->buf); | ||
1214 | i2c_set_clientdata(ir->rx->c, NULL); | 1213 | i2c_set_clientdata(ir->rx->c, NULL); |
1215 | kfree(ir->rx); | 1214 | kfree(ir->rx); |
1216 | } | 1215 | } |
@@ -1222,6 +1221,8 @@ static int ir_remove(struct i2c_client *client) | |||
1222 | } | 1221 | } |
1223 | 1222 | ||
1224 | /* Good-bye IR */ | 1223 | /* Good-bye IR */ |
1224 | if (ir->rbuf.fifo_initialized) | ||
1225 | lirc_buffer_free(&ir->rbuf); | ||
1225 | del_ir_device(ir); | 1226 | del_ir_device(ir); |
1226 | kfree(ir); | 1227 | kfree(ir); |
1227 | 1228 | ||
@@ -1292,11 +1293,17 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1292 | memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver)); | 1293 | memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver)); |
1293 | ir->l.minor = minor; /* module option */ | 1294 | ir->l.minor = minor; /* module option */ |
1294 | ir->l.code_length = 13; | 1295 | ir->l.code_length = 13; |
1295 | ir->l.rbuf = NULL; | 1296 | ir->l.chunk_size = 2; |
1297 | ir->l.buffer_size = BUFLEN / 2; | ||
1298 | ir->l.rbuf = &ir->rbuf; | ||
1296 | ir->l.fops = &lirc_fops; | 1299 | ir->l.fops = &lirc_fops; |
1297 | ir->l.data = ir; | 1300 | ir->l.data = ir; |
1298 | ir->l.dev = &adap->dev; | 1301 | ir->l.dev = &adap->dev; |
1299 | ir->l.sample_rate = 0; | 1302 | ir->l.sample_rate = 0; |
1303 | ret = lirc_buffer_init(ir->l.rbuf, | ||
1304 | ir->l.chunk_size, ir->l.buffer_size); | ||
1305 | if (ret) | ||
1306 | goto out_free_ir; | ||
1300 | } | 1307 | } |
1301 | 1308 | ||
1302 | if (tx_probe) { | 1309 | if (tx_probe) { |
@@ -1319,16 +1326,9 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1319 | goto out_free_xx; | 1326 | goto out_free_xx; |
1320 | } | 1327 | } |
1321 | 1328 | ||
1322 | ret = lirc_buffer_init(&ir->rx->buf, 2, BUFLEN / 2); | ||
1323 | if (ret) | ||
1324 | goto out_free_xx; | ||
1325 | |||
1326 | ir->rx->c = client; | 1329 | ir->rx->c = client; |
1327 | ir->rx->hdpvr_data_fmt = | 1330 | ir->rx->hdpvr_data_fmt = |
1328 | (id->driver_data & ID_FLAG_HDPVR) ? true : false; | 1331 | (id->driver_data & ID_FLAG_HDPVR) ? true : false; |
1329 | |||
1330 | /* set lirc_dev stuff */ | ||
1331 | ir->l.rbuf = &ir->rx->buf; | ||
1332 | } | 1332 | } |
1333 | 1333 | ||
1334 | i2c_set_clientdata(client, ir); | 1334 | i2c_set_clientdata(client, ir); |
@@ -1388,8 +1388,6 @@ out_free_thread: | |||
1388 | destroy_rx_kthread(ir->rx); | 1388 | destroy_rx_kthread(ir->rx); |
1389 | out_free_xx: | 1389 | out_free_xx: |
1390 | if (ir->rx != NULL) { | 1390 | if (ir->rx != NULL) { |
1391 | if (ir->rx->buf.fifo_initialized) | ||
1392 | lirc_buffer_free(&ir->rx->buf); | ||
1393 | if (ir->rx->c != NULL) | 1391 | if (ir->rx->c != NULL) |
1394 | i2c_set_clientdata(ir->rx->c, NULL); | 1392 | i2c_set_clientdata(ir->rx->c, NULL); |
1395 | kfree(ir->rx); | 1393 | kfree(ir->rx); |
@@ -1399,6 +1397,8 @@ out_free_xx: | |||
1399 | i2c_set_clientdata(ir->tx->c, NULL); | 1397 | i2c_set_clientdata(ir->tx->c, NULL); |
1400 | kfree(ir->tx); | 1398 | kfree(ir->tx); |
1401 | } | 1399 | } |
1400 | if (ir->rbuf.fifo_initialized) | ||
1401 | lirc_buffer_free(&ir->rbuf); | ||
1402 | out_free_ir: | 1402 | out_free_ir: |
1403 | del_ir_device(ir); | 1403 | del_ir_device(ir); |
1404 | kfree(ir); | 1404 | kfree(ir); |