Commit a7813e6a authored by Kai Germaschewski's avatar Kai Germaschewski

ISDN/HiSax: config.c cleanup

Consolidate allocation / freeing of various data structures into
one function.
parent 122649d2
...@@ -814,12 +814,6 @@ static void ll_unload(struct IsdnCardState *cs) ...@@ -814,12 +814,6 @@ static void ll_unload(struct IsdnCardState *cs)
ic.command = ISDN_STAT_UNLOAD; ic.command = ISDN_STAT_UNLOAD;
ic.driver = cs->myid; ic.driver = cs->myid;
cs->iif.statcallb(&ic); cs->iif.statcallb(&ic);
if (cs->status_buf)
kfree(cs->status_buf);
cs->status_read = NULL;
cs->status_write = NULL;
cs->status_end = NULL;
kfree(cs->dlog);
} }
static void closecard(int cardnr) static void closecard(int cardnr)
...@@ -893,59 +887,97 @@ static int __devinit init_card(struct IsdnCardState *cs) ...@@ -893,59 +887,97 @@ static int __devinit init_card(struct IsdnCardState *cs)
return 3; return 3;
} }
static struct IsdnCardState *
alloc_IsdnCardState(void)
{
struct IsdnCardState *cs;
cs = kmalloc(sizeof(*cs), GFP_ATOMIC); // FIXME
if (!cs)
goto err;
memset(cs, 0, sizeof(*cs));
cs->dlog = kmalloc(MAX_DLOG_SPACE, GFP_ATOMIC);
if (!cs->dlog)
goto err_cs;
cs->status_buf = kmalloc(HISAX_STATUS_BUFSIZE, GFP_ATOMIC);
if (!cs->status_buf)
goto err_dlog;
cs->rcvbuf = kmalloc(MAX_DFRAME_LEN_L1, GFP_ATOMIC);
if (!cs->rcvbuf)
goto err_status_buf;
cs->chanlimit = 2; /* maximum B-channel number */
cs->debug = L1_DEB_WARN;
cs->irq_flags = I4L_IRQ_FLAG;
cs->stlist = NULL;
cs->status_read = cs->status_buf;
cs->status_write = cs->status_buf;
cs->status_end = cs->status_buf + HISAX_STATUS_BUFSIZE - 1;
cs->rcvidx = 0;
cs->tx_skb = NULL;
cs->tx_cnt = 0;
cs->event = 0;
skb_queue_head_init(&cs->rq);
skb_queue_head_init(&cs->sq);
spin_lock_init(&cs->lock);
resources_init(&cs->rs);
return cs;
err_status_buf:
kfree(cs->status_buf);
err_dlog:
kfree(cs->dlog);
err_cs:
kfree(cs);
err:
return NULL;
}
static void
free_IsdnCardState(struct IsdnCardState *cs)
{
kfree(cs->rcvbuf);
kfree(cs->status_buf);
kfree(cs->dlog);
kfree(cs);
}
static int __devinit checkcard(int cardnr, char *id, int *busy_flag) static int __devinit checkcard(int cardnr, char *id, int *busy_flag)
{ {
int ret = 0; int ret = 0;
struct IsdnCard *card = cards + cardnr; struct IsdnCard *card = cards + cardnr;
struct IsdnCardState *cs; struct IsdnCardState *cs;
cs = kmalloc(sizeof(struct IsdnCardState), GFP_ATOMIC); cs = alloc_IsdnCardState();
if (!cs) { if (!cs) {
printk(KERN_WARNING printk(KERN_WARNING
"HiSax: No memory for IsdnCardState(card %d)\n", "HiSax: No memory for IsdnCardState(card %d)\n",
cardnr + 1); cardnr + 1);
goto out; goto out;
} }
memset(cs, 0, sizeof(struct IsdnCardState));
card->cs = cs; card->cs = cs;
cs->chanlimit = 2; /* maximum B-channel number */
cs->logecho = 0; /* No echo logging */
cs->cardnr = cardnr;
cs->debug = L1_DEB_WARN;
cs->HW_Flags = 0;
cs->busy_flag = busy_flag;
cs->irq_flags = I4L_IRQ_FLAG;
#if TEI_PER_CARD #if TEI_PER_CARD
if (card->protocol == ISDN_PTYPE_NI1) if (card->protocol == ISDN_PTYPE_NI1)
test_and_set_bit(FLG_TWO_DCHAN, &cs->HW_Flags); test_and_set_bit(FLG_TWO_DCHAN, &cs->HW_Flags);
#else #else
test_and_set_bit(FLG_TWO_DCHAN, &cs->HW_Flags); test_and_set_bit(FLG_TWO_DCHAN, &cs->HW_Flags);
#endif #endif
cs->cardnr = cardnr;
cs->protocol = card->protocol; cs->protocol = card->protocol;
cs->typ = card->typ;
cs->busy_flag = busy_flag;
if (card->typ <= 0 || card->typ > ISDN_CTYPE_COUNT) { if (card->typ <= 0 || card->typ > ISDN_CTYPE_COUNT) {
printk(KERN_WARNING printk(KERN_WARNING
"HiSax: Card Type %d out of range\n", card->typ); "HiSax: Card Type %d out of range\n", card->typ);
goto outf_cs; goto outf_cs;
} }
if (!(cs->dlog = kmalloc(MAX_DLOG_SPACE, GFP_ATOMIC))) {
printk(KERN_WARNING
"HiSax: No memory for dlog(card %d)\n", cardnr + 1);
goto outf_cs;
}
if (!(cs->status_buf = kmalloc(HISAX_STATUS_BUFSIZE, GFP_ATOMIC))) {
printk(KERN_WARNING
"HiSax: No memory for status_buf(card %d)\n",
cardnr + 1);
goto outf_dlog;
}
cs->stlist = NULL;
cs->status_read = cs->status_buf;
cs->status_write = cs->status_buf;
cs->status_end = cs->status_buf + HISAX_STATUS_BUFSIZE - 1;
cs->typ = card->typ;
spin_lock_init(&cs->lock);
resources_init(&cs->rs);
SET_MODULE_OWNER(&cs->iif); SET_MODULE_OWNER(&cs->iif);
strcpy(cs->iif.id, id); strcpy(cs->iif.id, id);
cs->iif.channels = 2; cs->iif.channels = 2;
...@@ -1156,19 +1188,6 @@ static int __devinit checkcard(int cardnr, char *id, int *busy_flag) ...@@ -1156,19 +1188,6 @@ static int __devinit checkcard(int cardnr, char *id, int *busy_flag)
ll_unload(cs); ll_unload(cs);
goto outf_cs; goto outf_cs;
} }
if (!(cs->rcvbuf = kmalloc(MAX_DFRAME_LEN_L1, GFP_ATOMIC))) {
printk(KERN_WARNING "HiSax: No memory for isac rcvbuf\n");
ll_unload(cs);
goto outf_cs;
}
cs->rcvidx = 0;
cs->tx_skb = NULL;
cs->tx_cnt = 0;
cs->event = 0;
skb_queue_head_init(&cs->rq);
skb_queue_head_init(&cs->sq);
init_bcstate(cs, 0); init_bcstate(cs, 0);
init_bcstate(cs, 1); init_bcstate(cs, 1);
...@@ -1201,10 +1220,8 @@ static int __devinit checkcard(int cardnr, char *id, int *busy_flag) ...@@ -1201,10 +1220,8 @@ static int __devinit checkcard(int cardnr, char *id, int *busy_flag)
ret = 1; ret = 1;
goto out; goto out;
outf_dlog:
kfree(cs->dlog);
outf_cs: outf_cs:
kfree(cs); free_IsdnCardState(cs);
card->cs = NULL; card->cs = NULL;
out: out:
return ret; return ret;
...@@ -1253,8 +1270,8 @@ int __devinit HiSax_inithardware(int *busy_flag) ...@@ -1253,8 +1270,8 @@ int __devinit HiSax_inithardware(int *busy_flag)
i++; i++;
} else { } else {
printk(KERN_WARNING printk(KERN_WARNING
"HiSax: Card %s not installed !\n", "HiSax: Card type %d not installed !\n",
CardType[cards[i].typ]); cards[i].typ);
HiSax_shiftcards(i); HiSax_shiftcards(i);
nrcards--; nrcards--;
} }
......
...@@ -782,7 +782,6 @@ struct bkm_hw { ...@@ -782,7 +782,6 @@ struct bkm_hw {
struct gazel_hw { struct gazel_hw {
unsigned int cfg_reg; unsigned int cfg_reg;
unsigned int pciaddr[2];
signed int ipac; signed int ipac;
signed int isac; signed int isac;
signed int hscx[2]; signed int hscx[2];
......
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