Commit d0e068dc authored by Kai Germaschewski's avatar Kai Germaschewski

ISDN: cleanup AVM drivers

Allocate and free the avmcard structure using a shared function.
parent 7a21eb22
......@@ -57,6 +57,20 @@ typedef struct avmcard_dmainfo {
struct pci_dev *pcidev;
} avmcard_dmainfo;
typedef struct avmctrl_info {
char cardname[32];
int versionlen;
char versionbuf[1024];
char *version[AVM_MAXVERSION];
char infobuf[128]; /* for function procinfo */
struct avmcard *card;
struct capi_ctr *capi_ctrl;
} avmctrl_info;
typedef struct avmcard {
char name[32];
......@@ -76,25 +90,11 @@ typedef struct avmcard {
volatile u32 csr;
avmcard_dmainfo *dma;
struct avmctrl_info {
char cardname[32];
int versionlen;
char versionbuf[1024];
char *version[AVM_MAXVERSION];
char infobuf[128]; /* for function procinfo */
struct avmcard *card;
struct capi_ctr *capi_ctrl;
} *ctrlinfo;
struct avmctrl_info *ctrlinfo;
int nlogcontr;
} avmcard;
typedef struct avmctrl_info avmctrl_info;
extern int b1_irq_table[16];
/*
......@@ -536,6 +536,8 @@ static inline void b1_setinterrupt(unsigned int base, unsigned irq,
}
/* b1.c */
avmcard *b1_alloc_card(int nr_controllers);
void b1_free_card(avmcard *card);
int b1_detect(unsigned int base, enum avmcardtype cardtype);
void b1_getrevision(avmcard *card);
int b1_load_t4file(avmcard *card, capiloaddatapart * t4file);
......
......@@ -59,6 +59,44 @@ int b1_irq_table[16] =
/* ------------------------------------------------------------- */
avmcard *b1_alloc_card(int nr_controllers)
{
avmcard *card;
avmctrl_info *cinfo;
int i;
card = kmalloc(sizeof(*card), GFP_KERNEL);
if (!card)
return 0;
memset(card, 0, sizeof(*card));
cinfo = kmalloc(sizeof(*cinfo) * nr_controllers, GFP_KERNEL);
if (!cinfo) {
kfree(card);
return 0;
}
memset(cinfo, 0, sizeof(*cinfo));
card->ctrlinfo = cinfo;
for (i = 0; i < nr_controllers; i++) {
cinfo[i].card = card;
}
spin_lock_init(&card->lock);
return card;
}
/* ------------------------------------------------------------- */
void b1_free_card(avmcard *card)
{
kfree(card->ctrlinfo);
kfree(card);
}
/* ------------------------------------------------------------- */
int b1_detect(unsigned int base, enum avmcardtype cardtype)
{
int onoff, i;
......@@ -702,6 +740,8 @@ EXPORT_SYMBOL(avmcard_dma_free);
EXPORT_SYMBOL(b1_irq_table);
EXPORT_SYMBOL(b1_alloc_card);
EXPORT_SYMBOL(b1_free_card);
EXPORT_SYMBOL(b1_detect);
EXPORT_SYMBOL(b1_getrevision);
EXPORT_SYMBOL(b1_load_t4file);
......
......@@ -50,8 +50,7 @@ static void b1isa_remove_ctr(struct capi_ctr *ctrl)
di->detach_ctr(ctrl);
free_irq(card->irq, card);
release_region(card->port, AVMB1_PORTLEN);
kfree(card->ctrlinfo);
kfree(card);
b1_free_card(card);
MOD_DEC_USE_COUNT;
}
......@@ -66,86 +65,57 @@ static int b1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
MOD_INC_USE_COUNT;
card = (avmcard *) kmalloc(sizeof(avmcard), GFP_ATOMIC);
card = b1_alloc_card(1);
if (!card) {
printk(KERN_WARNING "b1isa: no memory.\n");
MOD_DEC_USE_COUNT;
return -ENOMEM;
}
memset(card, 0, sizeof(avmcard));
cinfo = (avmctrl_info *) kmalloc(sizeof(avmctrl_info), GFP_ATOMIC);
if (!cinfo) {
printk(KERN_WARNING "b1isa: no memory.\n");
kfree(card);
MOD_DEC_USE_COUNT;
return -ENOMEM;
retval = -ENOMEM;
goto err;
}
memset(cinfo, 0, sizeof(avmctrl_info));
card->ctrlinfo = cinfo;
cinfo->card = card;
cinfo = card->ctrlinfo;
sprintf(card->name, "b1isa-%x", p->port);
card->port = p->port;
card->irq = p->irq;
card->cardtype = avm_b1isa;
if (check_region(card->port, AVMB1_PORTLEN)) {
printk(KERN_WARNING
"b1isa: ports 0x%03x-0x%03x in use.\n",
card->port, card->port + AVMB1_PORTLEN);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EBUSY;
if ( card->port != 0x150 && card->port != 0x250
&& card->port != 0x300 && card->port != 0x340) {
printk(KERN_WARNING "b1isa: illegal port 0x%x.\n", card->port);
retval = -EINVAL;
goto err_free;
}
if (b1_irq_table[card->irq & 0xf] == 0) {
printk(KERN_WARNING "b1isa: irq %d not valid.\n", card->irq);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EINVAL;
retval = -EINVAL;
goto err_free;
}
if ( card->port != 0x150 && card->port != 0x250
&& card->port != 0x300 && card->port != 0x340) {
printk(KERN_WARNING "b1isa: illegal port 0x%x.\n", card->port);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EINVAL;
if (!request_region(card->port, AVMB1_PORTLEN, card->name)) {
printk(KERN_WARNING "b1isa: ports 0x%03x-0x%03x in use.\n",
card->port, card->port + AVMB1_PORTLEN);
retval = -EBUSY;
goto err_free;
}
retval = request_irq(card->irq, b1_interrupt, 0, card->name, card);
if (retval) {
printk(KERN_ERR "b1isa: unable to get IRQ %d.\n", card->irq);
goto err_release_region;
}
b1_reset(card->port);
if ((retval = b1_detect(card->port, card->cardtype)) != 0) {
printk(KERN_NOTICE "b1isa: NO card at 0x%x (%d)\n",
card->port, retval);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EIO;
retval = -ENODEV;
goto err_free_irq;
}
b1_reset(card->port);
b1_getrevision(card);
request_region(p->port, AVMB1_PORTLEN, card->name);
retval = request_irq(card->irq, b1_interrupt, 0, card->name, card);
if (retval) {
printk(KERN_ERR "b1isa: unable to get IRQ %d.\n", card->irq);
release_region(card->port, AVMB1_PORTLEN);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EBUSY;
}
cinfo->capi_ctrl = di->attach_ctr(driver, card->name, cinfo);
if (!cinfo->capi_ctrl) {
printk(KERN_ERR "b1isa: attach controller failed.\n");
free_irq(card->irq, card);
release_region(card->port, AVMB1_PORTLEN);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EBUSY;
retval = -EBUSY;
goto err_free_irq;
}
printk(KERN_INFO
......@@ -153,6 +123,16 @@ static int b1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
driver->name, card->port, card->irq, card->revision);
return 0;
err_free_irq:
free_irq(card->irq, card);
err_release_region:
release_region(card->port, AVMB1_PORTLEN);
err_free:
b1_free_card(card);
err:
MOD_DEC_USE_COUNT;
return retval;
}
static char *b1isa_procinfo(struct capi_ctr *ctrl)
......
......@@ -74,22 +74,14 @@ static int b1pci_add_card(struct capi_driver *driver,
MOD_INC_USE_COUNT;
retval = -ENOMEM;
card = kmalloc(sizeof(avmcard), GFP_KERNEL);
card = b1_alloc_card(1);
if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
retval = -ENOMEM;
goto err;
}
memset(card, 0, sizeof(avmcard));
cinfo = kmalloc(sizeof(avmctrl_info), GFP_KERNEL);
if (!cinfo) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
goto err_kfree;
}
memset(cinfo, 0, sizeof(avmctrl_info));
card->ctrlinfo = cinfo;
cinfo->card = card;
cinfo = card->ctrlinfo;
sprintf(card->name, "b1pci-%x", p->port);
card->port = p->port;
card->irq = p->irq;
......@@ -99,14 +91,15 @@ static int b1pci_add_card(struct capi_driver *driver,
printk(KERN_WARNING
"%s: ports 0x%03x-0x%03x in use.\n",
driver->name, card->port, card->port + AVMB1_PORTLEN);
goto err_kfree_ctrlinfo;
retval = -EBUSY;
goto err_free;
}
b1_reset(card->port);
retval = b1_detect(card->port, card->cardtype);
if (retval) {
printk(KERN_NOTICE "%s: NO card at 0x%x (%d)\n",
driver->name, card->port, retval);
retval = -EIO;
retval = -ENODEV;
goto err_release_region;
}
b1_reset(card->port);
......@@ -144,10 +137,8 @@ static int b1pci_add_card(struct capi_driver *driver,
free_irq(card->irq, card);
err_release_region:
release_region(card->port, AVMB1_PORTLEN);
err_kfree_ctrlinfo:
kfree(card->ctrlinfo);
err_kfree:
kfree(card);
err_free:
b1_free_card(card);
err:
MOD_DEC_USE_COUNT;
return retval;
......@@ -166,8 +157,7 @@ static void b1pci_remove_ctr(struct capi_ctr *ctrl)
free_irq(card->irq, card);
release_region(card->port, AVMB1_PORTLEN);
ctrl->driverdata = 0;
kfree(card->ctrlinfo);
kfree(card);
b1_free_card(card);
MOD_DEC_USE_COUNT;
}
......@@ -227,28 +217,21 @@ static int b1pciv4_add_card(struct capi_driver *driver,
MOD_INC_USE_COUNT;
retval = -ENOMEM;
card = kmalloc(sizeof(avmcard), GFP_KERNEL);
card = b1_alloc_card(1);
if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
retval = -ENOMEM;
goto err;
}
memset(card, 0, sizeof(avmcard));
spin_lock_init(&card->lock);
card->dma = avmcard_dma_alloc(driver->name, dev, 2048+128, 2048+128);
if (!card->dma) {
printk(KERN_WARNING "%s: dma alloc.\n", driver->name);
goto err_kfree;
}
cinfo = kmalloc(sizeof(avmctrl_info), GFP_KERNEL);
if (!cinfo) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
goto err_dma_free;
retval = -ENOMEM;
goto err_free;
}
memset(cinfo, 0, sizeof(avmctrl_info));
card->ctrlinfo = cinfo;
cinfo->card = card;
cinfo = card->ctrlinfo;
sprintf(card->name, "b1pciv4-%x", p->port);
card->port = p->port;
card->irq = p->irq;
......@@ -260,14 +243,14 @@ static int b1pciv4_add_card(struct capi_driver *driver,
"%s: ports 0x%03x-0x%03x in use.\n",
driver->name, card->port, card->port + AVMB1_PORTLEN);
retval = -EBUSY;
goto err_kfree_ctrlinfo;
goto err_free_dma;
}
card->mbase = ioremap_nocache(card->membase, 64);
if (!card->mbase) {
printk(KERN_NOTICE "%s: can't remap memory at 0x%lx\n",
driver->name, card->membase);
retval = -EIO;
retval = -ENOMEM;
goto err_release_region;
}
......@@ -277,7 +260,7 @@ static int b1pciv4_add_card(struct capi_driver *driver,
if (retval) {
printk(KERN_NOTICE "%s: NO card at 0x%x (%d)\n",
driver->name, card->port, retval);
retval = -EIO;
retval = -ENODEV;
goto err_unmap;
}
b1dma_reset(card);
......@@ -312,12 +295,10 @@ static int b1pciv4_add_card(struct capi_driver *driver,
iounmap(card->mbase);
err_release_region:
release_region(card->port, AVMB1_PORTLEN);
err_kfree_ctrlinfo:
kfree(card->ctrlinfo);
err_dma_free:
err_free_dma:
avmcard_dma_free(card->dma);
err_kfree:
kfree(card);
err_free:
b1_free_card(card);
err:
MOD_DEC_USE_COUNT;
return retval;
......@@ -336,9 +317,8 @@ static void b1pciv4_remove_ctr(struct capi_ctr *ctrl)
iounmap(card->mbase);
release_region(card->port, AVMB1_PORTLEN);
ctrl->driverdata = 0;
kfree(card->ctrlinfo);
avmcard_dma_free(card->dma);
kfree(card);
b1_free_card(card);
MOD_DEC_USE_COUNT;
}
......
......@@ -50,10 +50,7 @@ static void b1pcmcia_remove_ctr(struct capi_ctr *ctrl)
di->detach_ctr(ctrl);
free_irq(card->irq, card);
/* io addrsses managent by CardServices
* release_region(card->port, AVMB1_PORTLEN);
*/
kfree(card);
b1_free_card(card);
MOD_DEC_USE_COUNT;
}
......@@ -72,24 +69,14 @@ static int b1pcmcia_add_card(struct capi_driver *driver,
MOD_INC_USE_COUNT;
card = (avmcard *) kmalloc(sizeof(avmcard), GFP_ATOMIC);
card = b1_alloc_card(1);
if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
MOD_DEC_USE_COUNT;
return -ENOMEM;
retval = -ENOMEM;
goto err;
}
memset(card, 0, sizeof(avmcard));
cinfo = (avmctrl_info *) kmalloc(sizeof(avmctrl_info), GFP_ATOMIC);
if (!cinfo) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
kfree(card);
MOD_DEC_USE_COUNT;
return -ENOMEM;
}
memset(cinfo, 0, sizeof(avmctrl_info));
card->ctrlinfo = cinfo;
cinfo->card = card;
cinfo = card->ctrlinfo;
switch (cardtype) {
case avm_m1: sprintf(card->name, "m1-%x", port); break;
case avm_m2: sprintf(card->name, "m2-%x", port); break;
......@@ -99,37 +86,29 @@ static int b1pcmcia_add_card(struct capi_driver *driver,
card->irq = irq;
card->cardtype = cardtype;
retval = request_irq(card->irq, b1_interrupt, 0, card->name, card);
if (retval) {
printk(KERN_ERR "%s: unable to get IRQ %d.\n",
driver->name, card->irq);
retval = -EBUSY;
goto err_free;
}
b1_reset(card->port);
if ((retval = b1_detect(card->port, card->cardtype)) != 0) {
printk(KERN_NOTICE "%s: NO card at 0x%x (%d)\n",
driver->name, card->port, retval);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EIO;
retval = -ENODEV;
goto err_free_irq;
}
b1_reset(card->port);
b1_getrevision(card);
retval = request_irq(card->irq, b1_interrupt, 0, card->name, card);
if (retval) {
printk(KERN_ERR "%s: unable to get IRQ %d.\n",
driver->name, card->irq);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EBUSY;
}
cinfo->capi_ctrl = di->attach_ctr(driver, card->name, cinfo);
if (!cinfo->capi_ctrl) {
printk(KERN_ERR "%s: attach controller failed.\n",
driver->name);
free_irq(card->irq, card);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EBUSY;
retval = -EBUSY;
goto err_free_irq;
}
switch (cardtype) {
case avm_m1: cardname = "M1"; break;
......@@ -142,6 +121,14 @@ static int b1pcmcia_add_card(struct capi_driver *driver,
driver->name, cardname, card->port, card->irq, card->revision);
return cinfo->capi_ctrl->cnr;
err_free_irq:
free_irq(card->irq, card);
err_free:
b1_free_card(card);
err:
MOD_DEC_USE_COUNT;
return retval;
}
/* ------------------------------------------------------------- */
......
......@@ -927,9 +927,8 @@ static void c4_remove_ctr(struct capi_ctr *ctrl)
iounmap(card->mbase);
release_region(card->port, AVMB1_PORTLEN);
ctrl->driverdata = 0;
kfree(card->ctrlinfo);
avmcard_dma_free(card->dma);
kfree(card);
b1_free_card(card);
MOD_DEC_USE_COUNT;
}
......@@ -1108,51 +1107,40 @@ static int c4_read_proc(char *page, char **start, off_t off,
static int c4_add_card(struct capi_driver *driver,
struct capicardparams *p,
struct pci_dev *dev,
int nr)
int nr_controllers)
{
avmctrl_info *cinfo;
avmcard *card;
avmctrl_info *cinfo;
int retval;
int i;
MOD_INC_USE_COUNT;
retval = -ENOMEM;
card = kmalloc(sizeof(avmcard), GFP_ATOMIC);
card = b1_alloc_card(nr_controllers);
if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
retval = -ENOMEM;
goto err;
}
memset(card, 0, sizeof(avmcard));
card->dma = avmcard_dma_alloc(driver->name, dev, 2048+128, 2048+128);
if (!card->dma) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
goto err_kfree;
}
cinfo = (avmctrl_info *) kmalloc(sizeof(avmctrl_info)*4, GFP_ATOMIC);
if (!cinfo) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
goto err_dma_free;
}
memset(cinfo, 0, sizeof(avmctrl_info)*4);
card->ctrlinfo = cinfo;
for (i=0; i < 4; i++) {
cinfo = &card->ctrlinfo[i];
cinfo->card = card;
retval = -ENOMEM;
goto err_free;
}
sprintf(card->name, "%s-%x", driver->name, p->port);
card->port = p->port;
card->irq = p->irq;
card->membase = p->membase;
card->cardtype = nr == 4 ? avm_c4 : avm_c2;
card->cardtype = (nr_controllers == 4) ? avm_c4 : avm_c2;
if (!request_region(card->port, AVMB1_PORTLEN, card->name)) {
printk(KERN_WARNING
"%s: ports 0x%03x-0x%03x in use.\n",
driver->name, card->port, card->port + AVMB1_PORTLEN);
retval = -EBUSY;
goto err_kfree_ctrlinfo;
goto err_free_dma;
}
card->mbase = ioremap_nocache(card->membase, 128);
......@@ -1180,9 +1168,8 @@ static int c4_add_card(struct capi_driver *driver,
goto err_unmap;
}
for (i=0; i < nr ; i++) {
for (i=0; i < nr_controllers ; i++) {
cinfo = &card->ctrlinfo[i];
cinfo->card = card;
cinfo->capi_ctrl = di->attach_ctr(driver, card->name, cinfo);
if (!cinfo->capi_ctrl) {
printk(KERN_ERR "%s: attach controller failed (%d).\n",
......@@ -1197,9 +1184,9 @@ static int c4_add_card(struct capi_driver *driver,
card->cardnr = cinfo->capi_ctrl->cnr;
}
printk(KERN_INFO
"%s: AVM C%d at i/o %#x, irq %d, mem %#lx\n",
driver->name, nr, card->port, card->irq, card->membase);
printk(KERN_INFO "%s: AVM C%d at i/o %#x, irq %d, mem %#lx\n",
driver->name, nr_controllers, card->port, card->irq,
card->membase);
return 0;
......@@ -1209,12 +1196,10 @@ static int c4_add_card(struct capi_driver *driver,
iounmap(card->mbase);
err_release_region:
release_region(card->port, AVMB1_PORTLEN);
err_kfree_ctrlinfo:
kfree(card->ctrlinfo);
err_dma_free:
err_free_dma:
avmcard_dma_free(card->dma);
err_kfree:
kfree(card);
err_free:
b1_free_card(card);
err:
MOD_DEC_USE_COUNT;
return retval;
......
......@@ -128,8 +128,9 @@ static int t1_detectandinit(unsigned int base, unsigned irq, int cardnr)
return 0;
}
static void t1_handle_interrupt(avmcard * card)
static void t1isa_interrupt(int interrupt, void *devptr, struct pt_regs *regs)
{
avmcard *card = devptr;
avmctrl_info *cinfo = &card->ctrlinfo[0];
struct capi_ctr *ctrl = cinfo->capi_ctrl;
unsigned char b1cmd;
......@@ -261,15 +262,6 @@ static void t1_handle_interrupt(avmcard * card)
/* ------------------------------------------------------------- */
static void t1isa_interrupt(int interrupt, void *devptr, struct pt_regs *regs)
{
avmcard *card = devptr;
t1_handle_interrupt(card);
}
/* ------------------------------------------------------------- */
static int t1isa_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
{
avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
......@@ -342,8 +334,7 @@ static void t1isa_remove_ctr(struct capi_ctr *ctrl)
di->detach_ctr(ctrl);
free_irq(card->irq, card);
release_region(card->port, AVMB1_PORTLEN);
kfree(card->ctrlinfo);
kfree(card);
b1_free_card(card);
MOD_DEC_USE_COUNT;
}
......@@ -359,24 +350,14 @@ static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
MOD_INC_USE_COUNT;
card = (avmcard *) kmalloc(sizeof(avmcard), GFP_ATOMIC);
card = b1_alloc_card(1);
if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
MOD_DEC_USE_COUNT;
return -ENOMEM;
retval = -ENOMEM;
goto err;
}
memset(card, 0, sizeof(avmcard));
cinfo = (avmctrl_info *) kmalloc(sizeof(avmctrl_info), GFP_ATOMIC);
if (!cinfo) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
kfree(card);
MOD_DEC_USE_COUNT;
return -ENOMEM;
}
memset(cinfo, 0, sizeof(avmctrl_info));
card->ctrlinfo = cinfo;
cinfo->card = card;
cinfo = card->ctrlinfo;
sprintf(card->name, "t1isa-%x", p->port);
card->port = p->port;
card->irq = p->irq;
......@@ -386,74 +367,53 @@ static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
if (!(((card->port & 0x7) == 0) && ((card->port & 0x30) != 0x30))) {
printk(KERN_WARNING "%s: illegal port 0x%x.\n",
driver->name, card->port);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EINVAL;
}
if (check_region(card->port, AVMB1_PORTLEN)) {
printk(KERN_WARNING
"%s: ports 0x%03x-0x%03x in use.\n",
driver->name, card->port, card->port + AVMB1_PORTLEN);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EBUSY;
retval = -EINVAL;
goto err_free;
}
if (hema_irq_table[card->irq & 0xf] == 0) {
printk(KERN_WARNING "%s: irq %d not valid.\n",
driver->name, card->irq);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EINVAL;
retval = -EINVAL;
goto err_free;
}
for (ctrl = driver->controller; ctrl; ctrl = ctrl->next) {
avmcard *cardp = ((avmctrl_info *)(ctrl->driverdata))->card;
if (cardp->cardnr == card->cardnr) {
printk(KERN_WARNING "%s: card with number %d already installed at 0x%x.\n",
driver->name, card->cardnr, cardp->port);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EBUSY;
retval = -EINVAL;
goto err_free;
}
}
if ((retval = t1_detectandinit(card->port, card->irq, card->cardnr)) != 0) {
printk(KERN_NOTICE "%s: NO card at 0x%x (%d)\n",
driver->name, card->port, retval);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EIO;
if (!request_region(card->port, AVMB1_PORTLEN, card->name)) {
printk(KERN_WARNING "%s: ports 0x%03x-0x%03x in use.\n",
driver->name, card->port, card->port + AVMB1_PORTLEN);
retval = -EBUSY;
goto err_free;
}
t1_disable_irq(card->port);
b1_reset(card->port);
request_region(p->port, AVMB1_PORTLEN, card->name);
retval = request_irq(card->irq, t1isa_interrupt, 0, card->name, card);
if (retval) {
printk(KERN_ERR "%s: unable to get IRQ %d.\n",
driver->name, card->irq);
release_region(card->port, AVMB1_PORTLEN);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EBUSY;
retval = -EBUSY;
goto err_release_region;
}
if ((retval = t1_detectandinit(card->port, card->irq, card->cardnr)) != 0) {
printk(KERN_NOTICE "%s: NO card at 0x%x (%d)\n",
driver->name, card->port, retval);
retval = -ENODEV;
goto err_free_irq;
}
t1_disable_irq(card->port);
b1_reset(card->port);
cinfo->capi_ctrl = di->attach_ctr(driver, card->name, cinfo);
if (!cinfo->capi_ctrl) {
printk(KERN_ERR "%s: attach controller failed.\n",
driver->name);
free_irq(card->irq, card);
release_region(card->port, AVMB1_PORTLEN);
kfree(card->ctrlinfo);
kfree(card);
MOD_DEC_USE_COUNT;
return -EBUSY;
retval = -EBUSY;
goto err_free_irq;
}
printk(KERN_INFO
......@@ -461,6 +421,16 @@ static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
driver->name, card->port, card->irq, card->cardnr);
return 0;
err_free_irq:
free_irq(card->irq, card);
err_release_region:
release_region(card->port, AVMB1_PORTLEN);
err_free:
b1_free_card(card);
err:
MOD_DEC_USE_COUNT;
return retval;
}
static void t1isa_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
......
......@@ -59,28 +59,21 @@ static int t1pci_add_card(struct capi_driver *driver,
MOD_INC_USE_COUNT;
retval = -ENOMEM;
card = kmalloc(sizeof(avmcard), GFP_KERNEL);
card = b1_alloc_card(1);
if (!card) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
retval = -ENOMEM;
goto err;
}
memset(card, 0, sizeof(avmcard));
spin_lock_init(&card->lock);
card->dma = avmcard_dma_alloc(driver->name, dev, 2048+128, 2048+128);
if (!card->dma) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
goto err_kfree;
}
cinfo = kmalloc(sizeof(avmctrl_info), GFP_KERNEL);
if (!cinfo) {
printk(KERN_WARNING "%s: no memory.\n", driver->name);
goto err_dma_free;
retval = -ENOMEM;
goto err_free;
}
memset(cinfo, 0, sizeof(avmctrl_info));
card->ctrlinfo = cinfo;
cinfo->card = card;
cinfo = card->ctrlinfo;
sprintf(card->name, "t1pci-%x", p->port);
card->port = p->port;
card->irq = p->irq;
......@@ -92,7 +85,7 @@ static int t1pci_add_card(struct capi_driver *driver,
"%s: ports 0x%03x-0x%03x in use.\n",
driver->name, card->port, card->port + AVMB1_PORTLEN);
retval = -EBUSY;
goto err_kfree_ctrlinfo;
goto err_free_dma;
}
card->mbase = ioremap_nocache(card->membase, 64);
......@@ -146,12 +139,10 @@ static int t1pci_add_card(struct capi_driver *driver,
iounmap(card->mbase);
err_release_region:
release_region(card->port, AVMB1_PORTLEN);
err_kfree_ctrlinfo:
kfree(card->ctrlinfo);
err_dma_free:
err_free_dma:
avmcard_dma_free(card->dma);
err_kfree:
kfree(card);
err_free:
b1_free_card(card);
err:
MOD_DEC_USE_COUNT;
return retval;
......@@ -171,9 +162,8 @@ static void t1pci_remove_ctr(struct capi_ctr *ctrl)
iounmap(card->mbase);
release_region(card->port, AVMB1_PORTLEN);
ctrl->driverdata = 0;
kfree(card->ctrlinfo);
avmcard_dma_free(card->dma);
kfree(card);
b1_free_card(card);
MOD_DEC_USE_COUNT;
}
......
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