summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Walls <awalls@md.metrocast.net>2011-01-27 03:48:32 +0300
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-23 01:23:51 +0300
commit5c07134fff9e6b1f9a3c75e62bbb827d1faa72eb (patch)
treee9082d2141f17eb1eaa7829d9d89a807570c6cf3
parent9b28500a59d7ee5da5adb43bcb384391cac401c4 (diff)
downloadlinux-5c07134fff9e6b1f9a3c75e62bbb827d1faa72eb.tar.xz
[media] lirc_zilog: Convert ir_device instance array to a linked list
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>
-rw-r--r--drivers/staging/lirc/lirc_zilog.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/drivers/staging/lirc/lirc_zilog.c b/drivers/staging/lirc/lirc_zilog.c
index 3a912575e12d..39f7b53f0785 100644
--- a/drivers/staging/lirc/lirc_zilog.c
+++ b/drivers/staging/lirc/lirc_zilog.c
@@ -89,6 +89,8 @@ struct IR_tx {
};
struct IR {
+ struct list_head list;
+
struct lirc_driver l;
struct mutex ir_lock;
@@ -99,9 +101,9 @@ struct IR {
struct IR_tx *tx;
};
-/* Minor -> data mapping */
-static struct mutex ir_devices_lock;
-static struct IR *ir_devices[MAX_IRCTL_DEVICES];
+/* IR transceiver instance object list */
+static DEFINE_MUTEX(ir_devices_lock);
+static LIST_HEAD(ir_devices_list);
/* Block size for IR transmitter */
#define TX_BLOCK_SIZE 99
@@ -1063,10 +1065,16 @@ static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
/* ir_devices_lock must be held */
static struct IR *find_ir_device_by_minor(unsigned int minor)
{
- if (minor >= MAX_IRCTL_DEVICES)
+ struct IR *ir;
+
+ if (list_empty(&ir_devices_list))
return NULL;
- return ir_devices[minor];
+ list_for_each_entry(ir, &ir_devices_list, list)
+ if (ir->l.minor == minor)
+ return ir;
+
+ return NULL;
}
/*
@@ -1172,25 +1180,21 @@ static void destroy_rx_kthread(struct IR_rx *rx)
/* ir_devices_lock must be held */
static int add_ir_device(struct IR *ir)
{
- int i;
-
- for (i = 0; i < MAX_IRCTL_DEVICES; i++)
- if (ir_devices[i] == NULL) {
- ir_devices[i] = ir;
- break;
- }
-
- return i == MAX_IRCTL_DEVICES ? -ENOMEM : i;
+ list_add_tail(&ir->list, &ir_devices_list);
+ return 0;
}
/* ir_devices_lock must be held */
static void del_ir_device(struct IR *ir)
{
- int i;
+ struct IR *p;
+
+ if (list_empty(&ir_devices_list))
+ return;
- for (i = 0; i < MAX_IRCTL_DEVICES; i++)
- if (ir_devices[i] == ir) {
- ir_devices[i] = NULL;
+ list_for_each_entry(p, &ir_devices_list, list)
+ if (p == ir) {
+ list_del(&p->list);
break;
}
}
@@ -1237,17 +1241,16 @@ static int ir_remove(struct i2c_client *client)
/* ir_devices_lock must be held */
static struct IR *find_ir_device_by_adapter(struct i2c_adapter *adapter)
{
- int i;
- struct IR *ir = NULL;
+ struct IR *ir;
- for (i = 0; i < MAX_IRCTL_DEVICES; i++)
- if (ir_devices[i] != NULL &&
- ir_devices[i]->adapter == adapter) {
- ir = ir_devices[i];
- break;
- }
+ if (list_empty(&ir_devices_list))
+ return NULL;
+
+ list_for_each_entry(ir, &ir_devices_list, list)
+ if (ir->adapter == adapter)
+ return ir;
- return ir;
+ return NULL;
}
static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
@@ -1284,6 +1287,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
goto out_no_ir;
}
/* store for use in ir_probe() again, and open() later on */
+ INIT_LIST_HEAD(&ir->list);
ret = add_ir_device(ir);
if (ret)
goto out_free_ir;
@@ -1421,7 +1425,6 @@ static int __init zilog_init(void)
zilog_notify("Zilog/Hauppauge IR driver initializing\n");
mutex_init(&tx_data_lock);
- mutex_init(&ir_devices_lock);
request_module("firmware_class");