CAPI: Switch capiminor list to array
Using a plain array of pointers simplifies the management of capiminors. Signed-off-by: Jan Kiszka <jan.kiszka@web.de> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
884f5c4479
commit
81d17fe5e2
@ -85,7 +85,6 @@ struct datahandle_queue {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct capiminor {
|
struct capiminor {
|
||||||
struct list_head list;
|
|
||||||
struct capincci *nccip;
|
struct capincci *nccip;
|
||||||
unsigned int minor;
|
unsigned int minor;
|
||||||
struct dentry *capifs_dentry;
|
struct dentry *capifs_dentry;
|
||||||
@ -151,8 +150,8 @@ static LIST_HEAD(capidev_list);
|
|||||||
|
|
||||||
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
|
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
|
||||||
|
|
||||||
static DEFINE_RWLOCK(capiminor_list_lock);
|
static DEFINE_RWLOCK(capiminors_lock);
|
||||||
static LIST_HEAD(capiminor_list);
|
static struct capiminor **capiminors;
|
||||||
|
|
||||||
/* -------- datahandles --------------------------------------------- */
|
/* -------- datahandles --------------------------------------------- */
|
||||||
|
|
||||||
@ -213,8 +212,8 @@ static void capiminor_del_all_ack(struct capiminor *mp)
|
|||||||
|
|
||||||
static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci)
|
static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci)
|
||||||
{
|
{
|
||||||
struct capiminor *mp, *p;
|
struct capiminor *mp;
|
||||||
unsigned int minor = 0;
|
unsigned int minor;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
mp = kzalloc(sizeof(*mp), GFP_KERNEL);
|
mp = kzalloc(sizeof(*mp), GFP_KERNEL);
|
||||||
@ -233,31 +232,23 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci)
|
|||||||
skb_queue_head_init(&mp->inqueue);
|
skb_queue_head_init(&mp->inqueue);
|
||||||
skb_queue_head_init(&mp->outqueue);
|
skb_queue_head_init(&mp->outqueue);
|
||||||
|
|
||||||
/* Allocate the least unused minor number.
|
/* Allocate the least unused minor number. */
|
||||||
*/
|
write_lock_irqsave(&capiminors_lock, flags);
|
||||||
write_lock_irqsave(&capiminor_list_lock, flags);
|
for (minor = 0; minor < capi_ttyminors; minor++)
|
||||||
if (list_empty(&capiminor_list))
|
if (!capiminors[minor]) {
|
||||||
list_add(&mp->list, &capiminor_list);
|
capiminors[minor] = mp;
|
||||||
else {
|
break;
|
||||||
list_for_each_entry(p, &capiminor_list, list) {
|
|
||||||
if (p->minor > minor)
|
|
||||||
break;
|
|
||||||
minor++;
|
|
||||||
}
|
}
|
||||||
|
write_unlock_irqrestore(&capiminors_lock, flags);
|
||||||
if (minor < capi_ttyminors) {
|
|
||||||
mp->minor = minor;
|
|
||||||
list_add(&mp->list, p->list.prev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
write_unlock_irqrestore(&capiminor_list_lock, flags);
|
|
||||||
|
|
||||||
if (!(minor < capi_ttyminors)) {
|
if (minor == capi_ttyminors) {
|
||||||
printk(KERN_NOTICE "capi: out of minors\n");
|
printk(KERN_NOTICE "capi: out of minors\n");
|
||||||
kfree(mp);
|
kfree(mp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mp->minor = minor;
|
||||||
|
|
||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,9 +256,9 @@ static void capiminor_free(struct capiminor *mp)
|
|||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
write_lock_irqsave(&capiminor_list_lock, flags);
|
write_lock_irqsave(&capiminors_lock, flags);
|
||||||
list_del(&mp->list);
|
capiminors[mp->minor] = NULL;
|
||||||
write_unlock_irqrestore(&capiminor_list_lock, flags);
|
write_unlock_irqrestore(&capiminors_lock, flags);
|
||||||
|
|
||||||
kfree_skb(mp->ttyskb);
|
kfree_skb(mp->ttyskb);
|
||||||
mp->ttyskb = NULL;
|
mp->ttyskb = NULL;
|
||||||
@ -279,20 +270,16 @@ static void capiminor_free(struct capiminor *mp)
|
|||||||
|
|
||||||
static struct capiminor *capiminor_find(unsigned int minor)
|
static struct capiminor *capiminor_find(unsigned int minor)
|
||||||
{
|
{
|
||||||
struct list_head *l;
|
struct capiminor *mp;
|
||||||
struct capiminor *p = NULL;
|
|
||||||
|
|
||||||
read_lock(&capiminor_list_lock);
|
if (minor >= capi_ttyminors)
|
||||||
list_for_each(l, &capiminor_list) {
|
|
||||||
p = list_entry(l, struct capiminor, list);
|
|
||||||
if (p->minor == minor)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
read_unlock(&capiminor_list_lock);
|
|
||||||
if (l == &capiminor_list)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return p;
|
read_lock(&capiminors_lock);
|
||||||
|
mp = capiminors[minor];
|
||||||
|
read_unlock(&capiminors_lock);
|
||||||
|
|
||||||
|
return mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------- struct capincci ----------------------------------------- */
|
/* -------- struct capincci ----------------------------------------- */
|
||||||
@ -1329,10 +1316,16 @@ static int capinc_tty_init(void)
|
|||||||
if (capi_ttyminors <= 0)
|
if (capi_ttyminors <= 0)
|
||||||
capi_ttyminors = CAPINC_NR_PORTS;
|
capi_ttyminors = CAPINC_NR_PORTS;
|
||||||
|
|
||||||
drv = alloc_tty_driver(capi_ttyminors);
|
capiminors = kzalloc(sizeof(struct capi_minor *) * capi_ttyminors,
|
||||||
if (!drv)
|
GFP_KERNEL);
|
||||||
|
if (!capiminors)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
drv = alloc_tty_driver(capi_ttyminors);
|
||||||
|
if (!drv) {
|
||||||
|
kfree(capiminors);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
drv->owner = THIS_MODULE;
|
drv->owner = THIS_MODULE;
|
||||||
drv->driver_name = "capi_nc";
|
drv->driver_name = "capi_nc";
|
||||||
drv->name = "capi";
|
drv->name = "capi";
|
||||||
@ -1349,6 +1342,7 @@ static int capinc_tty_init(void)
|
|||||||
tty_set_operations(drv, &capinc_ops);
|
tty_set_operations(drv, &capinc_ops);
|
||||||
if (tty_register_driver(drv)) {
|
if (tty_register_driver(drv)) {
|
||||||
put_tty_driver(drv);
|
put_tty_driver(drv);
|
||||||
|
kfree(capiminors);
|
||||||
printk(KERN_ERR "Couldn't register capi_nc driver\n");
|
printk(KERN_ERR "Couldn't register capi_nc driver\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1363,6 +1357,7 @@ static void capinc_tty_exit(void)
|
|||||||
if ((retval = tty_unregister_driver(drv)))
|
if ((retval = tty_unregister_driver(drv)))
|
||||||
printk(KERN_ERR "capi: failed to unregister capi_nc driver (%d)\n", retval);
|
printk(KERN_ERR "capi: failed to unregister capi_nc driver (%d)\n", retval);
|
||||||
put_tty_driver(drv);
|
put_tty_driver(drv);
|
||||||
|
kfree(capiminors);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */
|
#else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user