Commit 2e025886 authored by Kai Germaschewski's avatar Kai Germaschewski

ISDN: Usage count for CAPI controllers

We now control rely on ->owner and the upper level to control the
module use count.
parent e79275e2
...@@ -1198,6 +1198,7 @@ static int old_capi_manufacturer(unsigned int cmd, void *data) ...@@ -1198,6 +1198,7 @@ static int old_capi_manufacturer(unsigned int cmd, void *data)
return retval; return retval;
} }
card = get_capi_ctr_by_nr(ldef.contr); card = get_capi_ctr_by_nr(ldef.contr);
card = capi_ctr_get(card);
if (!card) if (!card)
return -ESRCH; return -ESRCH;
if (card->driver->load_firmware == 0) { if (card->driver->load_firmware == 0) {
...@@ -1231,6 +1232,7 @@ static int old_capi_manufacturer(unsigned int cmd, void *data) ...@@ -1231,6 +1232,7 @@ static int old_capi_manufacturer(unsigned int cmd, void *data)
if (retval) { if (retval) {
card->cardstate = CARD_DETECTED; card->cardstate = CARD_DETECTED;
capi_ctr_put(card);
return retval; return retval;
} }
...@@ -1239,9 +1241,12 @@ static int old_capi_manufacturer(unsigned int cmd, void *data) ...@@ -1239,9 +1241,12 @@ static int old_capi_manufacturer(unsigned int cmd, void *data)
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(HZ/10); /* 0.1 sec */ schedule_timeout(HZ/10); /* 0.1 sec */
if (signal_pending(current)) if (signal_pending(current)) {
capi_ctr_put(card);
return -EINTR; return -EINTR;
}
} }
capi_ctr_put(card);
return 0; return 0;
case AVMB1_RESETCARD: case AVMB1_RESETCARD:
......
...@@ -47,8 +47,6 @@ static void b1isa_remove_ctr(struct capi_ctr *ctrl) ...@@ -47,8 +47,6 @@ static void b1isa_remove_ctr(struct capi_ctr *ctrl)
free_irq(card->irq, card); free_irq(card->irq, card);
release_region(card->port, AVMB1_PORTLEN); release_region(card->port, AVMB1_PORTLEN);
b1_free_card(card); b1_free_card(card);
MOD_DEC_USE_COUNT;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
...@@ -59,8 +57,6 @@ static int b1isa_add_card(struct capi_driver *driver, struct capicardparams *p) ...@@ -59,8 +57,6 @@ static int b1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
avmcard *card; avmcard *card;
int retval; int retval;
MOD_INC_USE_COUNT;
card = b1_alloc_card(1); card = b1_alloc_card(1);
if (!card) { if (!card) {
printk(KERN_WARNING "b1isa: no memory.\n"); printk(KERN_WARNING "b1isa: no memory.\n");
...@@ -127,7 +123,6 @@ static int b1isa_add_card(struct capi_driver *driver, struct capicardparams *p) ...@@ -127,7 +123,6 @@ static int b1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
err_free: err_free:
b1_free_card(card); b1_free_card(card);
err: err:
MOD_DEC_USE_COUNT;
return retval; return retval;
} }
......
...@@ -68,8 +68,6 @@ static int b1pci_add_card(struct capi_driver *driver, ...@@ -68,8 +68,6 @@ static int b1pci_add_card(struct capi_driver *driver,
avmctrl_info *cinfo; avmctrl_info *cinfo;
int retval; int retval;
MOD_INC_USE_COUNT;
card = b1_alloc_card(1); card = b1_alloc_card(1);
if (!card) { if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name); printk(KERN_WARNING "%s: no memory.\n", driver->name);
...@@ -136,7 +134,6 @@ static int b1pci_add_card(struct capi_driver *driver, ...@@ -136,7 +134,6 @@ static int b1pci_add_card(struct capi_driver *driver,
err_free: err_free:
b1_free_card(card); b1_free_card(card);
err: err:
MOD_DEC_USE_COUNT;
return retval; return retval;
} }
...@@ -154,8 +151,6 @@ static void b1pci_remove_ctr(struct capi_ctr *ctrl) ...@@ -154,8 +151,6 @@ static void b1pci_remove_ctr(struct capi_ctr *ctrl)
release_region(card->port, AVMB1_PORTLEN); release_region(card->port, AVMB1_PORTLEN);
ctrl->driverdata = 0; ctrl->driverdata = 0;
b1_free_card(card); b1_free_card(card);
MOD_DEC_USE_COUNT;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
...@@ -208,8 +203,6 @@ static int b1pciv4_add_card(struct capi_driver *driver, ...@@ -208,8 +203,6 @@ static int b1pciv4_add_card(struct capi_driver *driver,
avmctrl_info *cinfo; avmctrl_info *cinfo;
int retval; int retval;
MOD_INC_USE_COUNT;
card = b1_alloc_card(1); card = b1_alloc_card(1);
if (!card) { if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name); printk(KERN_WARNING "%s: no memory.\n", driver->name);
...@@ -293,7 +286,6 @@ static int b1pciv4_add_card(struct capi_driver *driver, ...@@ -293,7 +286,6 @@ static int b1pciv4_add_card(struct capi_driver *driver,
err_free: err_free:
b1_free_card(card); b1_free_card(card);
err: err:
MOD_DEC_USE_COUNT;
return retval; return retval;
} }
...@@ -312,8 +304,6 @@ static void b1pciv4_remove_ctr(struct capi_ctr *ctrl) ...@@ -312,8 +304,6 @@ static void b1pciv4_remove_ctr(struct capi_ctr *ctrl)
ctrl->driverdata = 0; ctrl->driverdata = 0;
avmcard_dma_free(card->dma); avmcard_dma_free(card->dma);
b1_free_card(card); b1_free_card(card);
MOD_DEC_USE_COUNT;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
...@@ -405,7 +395,7 @@ static int __init b1pci_init(void) ...@@ -405,7 +395,7 @@ static int __init b1pci_init(void)
struct capi_driver *driverv4 = &b1pciv4_driver; struct capi_driver *driverv4 = &b1pciv4_driver;
#endif #endif
char *p; char *p;
int ncards; int retval;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
...@@ -434,19 +424,21 @@ static int __init b1pci_init(void) ...@@ -434,19 +424,21 @@ static int __init b1pci_init(void)
attach_capi_driver(driverv4); attach_capi_driver(driverv4);
#endif #endif
ncards = pci_register_driver(&b1pci_pci_driver); retval = pci_module_init(&b1pci_pci_driver);
if (ncards) { if (retval < 0)
printk(KERN_INFO "%s: %d B1-PCI card(s) detected\n", goto err;
driver->name, ncards);
MOD_DEC_USE_COUNT; printk(KERN_INFO "%s: %d B1-PCI card(s) detected\n",
return 0; driver->name, retval);
} retval = 0;
printk(KERN_ERR "%s: NO B1-PCI card detected\n", driver->name); goto out;
pci_unregister_driver(&b1pci_pci_driver);
err:
detach_capi_driver(driver); detach_capi_driver(driver);
#ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
detach_capi_driver(driverv4); detach_capi_driver(driverv4);
#endif #endif
out:
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return -ENODEV; return -ENODEV;
} }
......
...@@ -47,8 +47,6 @@ static void b1pcmcia_remove_ctr(struct capi_ctr *ctrl) ...@@ -47,8 +47,6 @@ static void b1pcmcia_remove_ctr(struct capi_ctr *ctrl)
detach_capi_ctr(ctrl); detach_capi_ctr(ctrl);
free_irq(card->irq, card); free_irq(card->irq, card);
b1_free_card(card); b1_free_card(card);
MOD_DEC_USE_COUNT;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
...@@ -63,8 +61,6 @@ static int b1pcmcia_add_card(struct capi_driver *driver, ...@@ -63,8 +61,6 @@ static int b1pcmcia_add_card(struct capi_driver *driver,
char *cardname; char *cardname;
int retval; int retval;
MOD_INC_USE_COUNT;
card = b1_alloc_card(1); card = b1_alloc_card(1);
if (!card) { if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name); printk(KERN_WARNING "%s: no memory.\n", driver->name);
...@@ -123,7 +119,6 @@ static int b1pcmcia_add_card(struct capi_driver *driver, ...@@ -123,7 +119,6 @@ static int b1pcmcia_add_card(struct capi_driver *driver,
err_free: err_free:
b1_free_card(card); b1_free_card(card);
err: err:
MOD_DEC_USE_COUNT;
return retval; return retval;
} }
...@@ -231,7 +226,7 @@ static int __init b1pcmcia_init(void) ...@@ -231,7 +226,7 @@ static int __init b1pcmcia_init(void)
static void __exit b1pcmcia_exit(void) static void __exit b1pcmcia_exit(void)
{ {
detach_capi_driver(&b1pcmcia_driver); detach_capi_driver(&b1pcmcia_driver);
} }
module_init(b1pcmcia_init); module_init(b1pcmcia_init);
......
...@@ -923,8 +923,6 @@ static void c4_remove_ctr(struct capi_ctr *ctrl) ...@@ -923,8 +923,6 @@ static void c4_remove_ctr(struct capi_ctr *ctrl)
ctrl->driverdata = 0; ctrl->driverdata = 0;
avmcard_dma_free(card->dma); avmcard_dma_free(card->dma);
b1_free_card(card); b1_free_card(card);
MOD_DEC_USE_COUNT;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
...@@ -1121,8 +1119,6 @@ static int c4_add_card(struct capi_driver *driver, ...@@ -1121,8 +1119,6 @@ static int c4_add_card(struct capi_driver *driver,
int retval; int retval;
int i; int i;
MOD_INC_USE_COUNT;
card = b1_alloc_card(nr_controllers); card = b1_alloc_card(nr_controllers);
if (!card) { if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name); printk(KERN_WARNING "%s: no memory.\n", driver->name);
...@@ -1208,7 +1204,6 @@ static int c4_add_card(struct capi_driver *driver, ...@@ -1208,7 +1204,6 @@ static int c4_add_card(struct capi_driver *driver,
err_free: err_free:
b1_free_card(card); b1_free_card(card);
err: err:
MOD_DEC_USE_COUNT;
return retval; return retval;
} }
...@@ -1250,7 +1245,7 @@ static struct capi_driver c4_driver = { ...@@ -1250,7 +1245,7 @@ static struct capi_driver c4_driver = {
add_card: 0, /* no add_card function */ add_card: 0, /* no add_card function */
}; };
static int c4_attach_driver (struct capi_driver * driver) static void c4_attach_driver (struct capi_driver * driver)
{ {
char *p; char *p;
if ((p = strchr(revision, ':')) != 0 && p[1]) { if ((p = strchr(revision, ':')) != 0 && p[1]) {
...@@ -1263,7 +1258,6 @@ static int c4_attach_driver (struct capi_driver * driver) ...@@ -1263,7 +1258,6 @@ static int c4_attach_driver (struct capi_driver * driver)
printk(KERN_INFO "%s: revision %s\n", driver->name, driver->revision); printk(KERN_INFO "%s: revision %s\n", driver->name, driver->revision);
attach_capi_driver(driver); attach_capi_driver(driver);
return 0;
} }
static int __devinit c4_probe(struct pci_dev *dev, static int __devinit c4_probe(struct pci_dev *dev,
...@@ -1308,35 +1302,28 @@ static struct pci_driver c4_pci_driver = { ...@@ -1308,35 +1302,28 @@ static struct pci_driver c4_pci_driver = {
static int __init c4_init(void) static int __init c4_init(void)
{ {
int retval; int retval;
int ncards;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
retval = c4_attach_driver (&c4_driver); c4_attach_driver (&c4_driver);
if (retval) { c4_attach_driver (&c2_driver);
MOD_DEC_USE_COUNT;
return retval;
}
retval = c4_attach_driver (&c2_driver); retval = pci_module_init(&c4_pci_driver);
if (retval) { if (retval < 0)
MOD_DEC_USE_COUNT; goto err;
return retval;
}
ncards = pci_register_driver(&c4_pci_driver); printk(KERN_INFO "%s: %d C4/C2 card(s) detected\n",
if (ncards) { c4_driver.name, retval);
printk(KERN_INFO "%s: %d C4/C2 card(s) detected\n",
c4_driver.name, ncards); retval = 0;
MOD_DEC_USE_COUNT; goto out;
return 0;
} err:
printk(KERN_ERR "%s: NO C4/C2 card detected\n", c4_driver.name);
pci_unregister_driver(&c4_pci_driver);
detach_capi_driver(&c4_driver);
detach_capi_driver(&c2_driver); detach_capi_driver(&c2_driver);
detach_capi_driver(&c4_driver);
out:
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return -ENODEV; return retval;
} }
static void __exit c4_exit(void) static void __exit c4_exit(void)
......
...@@ -338,8 +338,6 @@ static void t1isa_remove_ctr(struct capi_ctr *ctrl) ...@@ -338,8 +338,6 @@ static void t1isa_remove_ctr(struct capi_ctr *ctrl)
free_irq(card->irq, card); free_irq(card->irq, card);
release_region(card->port, AVMB1_PORTLEN); release_region(card->port, AVMB1_PORTLEN);
b1_free_card(card); b1_free_card(card);
MOD_DEC_USE_COUNT;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
...@@ -352,8 +350,6 @@ static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p) ...@@ -352,8 +350,6 @@ static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
avmcard *card; avmcard *card;
int retval; int retval;
MOD_INC_USE_COUNT;
card = b1_alloc_card(1); card = b1_alloc_card(1);
if (!card) { if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name); printk(KERN_WARNING "%s: no memory.\n", driver->name);
...@@ -436,7 +432,6 @@ static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p) ...@@ -436,7 +432,6 @@ static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
err_free: err_free:
b1_free_card(card); b1_free_card(card);
err: err:
MOD_DEC_USE_COUNT;
return retval; return retval;
} }
......
...@@ -53,8 +53,6 @@ static int t1pci_add_card(struct capi_driver *driver, ...@@ -53,8 +53,6 @@ static int t1pci_add_card(struct capi_driver *driver,
avmctrl_info *cinfo; avmctrl_info *cinfo;
int retval; int retval;
MOD_INC_USE_COUNT;
card = b1_alloc_card(1); card = b1_alloc_card(1);
if (!card) { if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name); printk(KERN_WARNING "%s: no memory.\n", driver->name);
...@@ -140,7 +138,6 @@ static int t1pci_add_card(struct capi_driver *driver, ...@@ -140,7 +138,6 @@ static int t1pci_add_card(struct capi_driver *driver,
err_free: err_free:
b1_free_card(card); b1_free_card(card);
err: err:
MOD_DEC_USE_COUNT;
return retval; return retval;
} }
...@@ -160,8 +157,6 @@ static void t1pci_remove_ctr(struct capi_ctr *ctrl) ...@@ -160,8 +157,6 @@ static void t1pci_remove_ctr(struct capi_ctr *ctrl)
ctrl->driverdata = 0; ctrl->driverdata = 0;
avmcard_dma_free(card->dma); avmcard_dma_free(card->dma);
b1_free_card(card); b1_free_card(card);
MOD_DEC_USE_COUNT;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
...@@ -246,7 +241,7 @@ static int __init t1pci_init(void) ...@@ -246,7 +241,7 @@ static int __init t1pci_init(void)
{ {
struct capi_driver *driver = &t1pci_driver; struct capi_driver *driver = &t1pci_driver;
char *p; char *p;
int ncards; int retval;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
...@@ -260,18 +255,20 @@ static int __init t1pci_init(void) ...@@ -260,18 +255,20 @@ static int __init t1pci_init(void)
attach_capi_driver(&t1pci_driver); attach_capi_driver(&t1pci_driver);
ncards = pci_register_driver(&t1pci_pci_driver); retval = pci_register_driver(&t1pci_pci_driver);
if (ncards) { if (retval < 0)
printk(KERN_INFO "%s: %d T1-PCI card(s) detected\n", goto err;
driver->name, ncards);
MOD_DEC_USE_COUNT; printk(KERN_INFO "%s: %d T1-PCI card(s) detected\n",
return 0; driver->name, retval);
} retval = 0;
printk(KERN_ERR "%s: NO T1-PCI card detected\n", driver->name); goto out;
pci_unregister_driver(&t1pci_pci_driver);
err:
detach_capi_driver(&t1pci_driver); detach_capi_driver(&t1pci_driver);
out:
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return -ENODEV; return retval;
} }
static void __exit t1pci_exit(void) static void __exit t1pci_exit(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment