mirror of https://gitee.com/openkylin/linux.git
[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>
This commit is contained in:
parent
9b28500a59
commit
5c07134fff
|
@ -89,6 +89,8 @@ struct IR_tx {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IR {
|
struct IR {
|
||||||
|
struct list_head list;
|
||||||
|
|
||||||
struct lirc_driver l;
|
struct lirc_driver l;
|
||||||
|
|
||||||
struct mutex ir_lock;
|
struct mutex ir_lock;
|
||||||
|
@ -99,9 +101,9 @@ struct IR {
|
||||||
struct IR_tx *tx;
|
struct IR_tx *tx;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Minor -> data mapping */
|
/* IR transceiver instance object list */
|
||||||
static struct mutex ir_devices_lock;
|
static DEFINE_MUTEX(ir_devices_lock);
|
||||||
static struct IR *ir_devices[MAX_IRCTL_DEVICES];
|
static LIST_HEAD(ir_devices_list);
|
||||||
|
|
||||||
/* Block size for IR transmitter */
|
/* Block size for IR transmitter */
|
||||||
#define TX_BLOCK_SIZE 99
|
#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 */
|
/* ir_devices_lock must be held */
|
||||||
static struct IR *find_ir_device_by_minor(unsigned int minor)
|
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 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 */
|
/* ir_devices_lock must be held */
|
||||||
static int add_ir_device(struct IR *ir)
|
static int add_ir_device(struct IR *ir)
|
||||||
{
|
{
|
||||||
int i;
|
list_add_tail(&ir->list, &ir_devices_list);
|
||||||
|
return 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ir_devices_lock must be held */
|
/* ir_devices_lock must be held */
|
||||||
static void del_ir_device(struct IR *ir)
|
static void del_ir_device(struct IR *ir)
|
||||||
{
|
{
|
||||||
int i;
|
struct IR *p;
|
||||||
|
|
||||||
for (i = 0; i < MAX_IRCTL_DEVICES; i++)
|
if (list_empty(&ir_devices_list))
|
||||||
if (ir_devices[i] == ir) {
|
return;
|
||||||
ir_devices[i] = NULL;
|
|
||||||
|
list_for_each_entry(p, &ir_devices_list, list)
|
||||||
|
if (p == ir) {
|
||||||
|
list_del(&p->list);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1237,17 +1241,16 @@ static int ir_remove(struct i2c_client *client)
|
||||||
/* ir_devices_lock must be held */
|
/* ir_devices_lock must be held */
|
||||||
static struct IR *find_ir_device_by_adapter(struct i2c_adapter *adapter)
|
static struct IR *find_ir_device_by_adapter(struct i2c_adapter *adapter)
|
||||||
{
|
{
|
||||||
int i;
|
struct IR *ir;
|
||||||
struct IR *ir = NULL;
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_IRCTL_DEVICES; i++)
|
if (list_empty(&ir_devices_list))
|
||||||
if (ir_devices[i] != NULL &&
|
return NULL;
|
||||||
ir_devices[i]->adapter == adapter) {
|
|
||||||
ir = ir_devices[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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)
|
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;
|
goto out_no_ir;
|
||||||
}
|
}
|
||||||
/* store for use in ir_probe() again, and open() later on */
|
/* store for use in ir_probe() again, and open() later on */
|
||||||
|
INIT_LIST_HEAD(&ir->list);
|
||||||
ret = add_ir_device(ir);
|
ret = add_ir_device(ir);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_free_ir;
|
goto out_free_ir;
|
||||||
|
@ -1421,7 +1425,6 @@ static int __init zilog_init(void)
|
||||||
zilog_notify("Zilog/Hauppauge IR driver initializing\n");
|
zilog_notify("Zilog/Hauppauge IR driver initializing\n");
|
||||||
|
|
||||||
mutex_init(&tx_data_lock);
|
mutex_init(&tx_data_lock);
|
||||||
mutex_init(&ir_devices_lock);
|
|
||||||
|
|
||||||
request_module("firmware_class");
|
request_module("firmware_class");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue