aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAndy Walls <awalls@md.metrocast.net>2011-01-26 20:04:24 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-22 18:23:52 -0400
commita30648550f2f758c9c00c493c8919f89f65438c4 (patch)
tree59815fdbb41ed4299f6da97f8a545661d683ad8e /drivers
parent5c07134fff9e6b1f9a3c75e62bbb827d1faa72eb (diff)
[media] lirc_zilog: Convert the instance open count to an atomic_t
The open count is simply used for deciding if the Rx polling thread needs to poll the IR chip for userspace. Simplify the manipulation of the open count by using an atomic_t and not requiring a lock The polling thread errantly didn't try to take the lock anyway. 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')
-rw-r--r--drivers/staging/lirc/lirc_zilog.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/drivers/staging/lirc/lirc_zilog.c b/drivers/staging/lirc/lirc_zilog.c
index 39f7b53f0785..c857b99e5ace 100644
--- a/drivers/staging/lirc/lirc_zilog.c
+++ b/drivers/staging/lirc/lirc_zilog.c
@@ -94,7 +94,7 @@ struct IR {
94 struct lirc_driver l; 94 struct lirc_driver l;
95 95
96 struct mutex ir_lock; 96 struct mutex ir_lock;
97 int open; 97 atomic_t open_count;
98 98
99 struct i2c_adapter *adapter; 99 struct i2c_adapter *adapter;
100 struct IR_rx *rx; 100 struct IR_rx *rx;
@@ -279,7 +279,7 @@ static int lirc_thread(void *arg)
279 set_current_state(TASK_INTERRUPTIBLE); 279 set_current_state(TASK_INTERRUPTIBLE);
280 280
281 /* if device not opened, we can sleep half a second */ 281 /* if device not opened, we can sleep half a second */
282 if (!ir->open) { 282 if (atomic_read(&ir->open_count) == 0) {
283 schedule_timeout(HZ/2); 283 schedule_timeout(HZ/2);
284 continue; 284 continue;
285 } 285 }
@@ -1094,10 +1094,7 @@ static int open(struct inode *node, struct file *filep)
1094 if (ir == NULL) 1094 if (ir == NULL)
1095 return -ENODEV; 1095 return -ENODEV;
1096 1096
1097 /* increment in use count */ 1097 atomic_inc(&ir->open_count);
1098 mutex_lock(&ir->ir_lock);
1099 ++ir->open;
1100 mutex_unlock(&ir->ir_lock);
1101 1098
1102 /* stash our IR struct */ 1099 /* stash our IR struct */
1103 filep->private_data = ir; 1100 filep->private_data = ir;
@@ -1115,10 +1112,7 @@ static int close(struct inode *node, struct file *filep)
1115 return -ENODEV; 1112 return -ENODEV;
1116 } 1113 }
1117 1114
1118 /* decrement in use count */ 1115 atomic_dec(&ir->open_count);
1119 mutex_lock(&ir->ir_lock);
1120 --ir->open;
1121 mutex_unlock(&ir->ir_lock);
1122 1116
1123 return 0; 1117 return 0;
1124} 1118}
@@ -1294,6 +1288,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1294 1288
1295 ir->adapter = adap; 1289 ir->adapter = adap;
1296 mutex_init(&ir->ir_lock); 1290 mutex_init(&ir->ir_lock);
1291 atomic_set(&ir->open_count, 0);
1297 1292
1298 /* set lirc_dev stuff */ 1293 /* set lirc_dev stuff */
1299 memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver)); 1294 memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver));