From 133be4bb2759ebb0c353b095158be58dfcd36ae2 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Thu, 20 Oct 2011 20:53:05 +0000 Subject: [PATCH] wct4xxp: Trivial refactoring in t4_init_one(). Use some convenience pointers to make the function easier to read as opposed to indexing into the arrays. Signed-off-by: Shaun Ruffell Acked-by: Michael Spiceland Acked-by: Russ Meyerriecks git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@10245 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/wct4xxp/base.c | 38 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/dahdi/wct4xxp/base.c b/drivers/dahdi/wct4xxp/base.c index 76b7af0..238774b 100644 --- a/drivers/dahdi/wct4xxp/base.c +++ b/drivers/dahdi/wct4xxp/base.c @@ -4173,39 +4173,43 @@ static int __devinit t4_init_one(struct pci_dev *pdev, const struct pci_device_i /* Allocate pieces we need here */ for (x = 0; x < PORTS_PER_FRAMER; x++) { - if (!(wc->tspans[x] = kmalloc(sizeof(*wc->tspans[x]), GFP_KERNEL))) { + struct t4_span *ts; + + ts = kzalloc(sizeof(*ts), GFP_KERNEL); + if (!ts) { free_wc(wc); return -ENOMEM; } + wc->tspans[x] = ts; - memset(wc->tspans[x], 0, sizeof(*wc->tspans[x])); + if (wc->t1e1 & (1 << x)) + ts->spantype = TYPE_E1; + else + ts->spantype = (j1mode) ? TYPE_J1 : TYPE_T1; - if (wc->t1e1 & (1 << x)) { - wc->tspans[x]->spantype = TYPE_E1; - } else { - if (j1mode) - wc->tspans[x]->spantype = TYPE_J1; - else - wc->tspans[x]->spantype = TYPE_T1; - } + for (f = 0; f < (ts->spantype == TYPE_E1 ? 31 : 24); f++) { + struct dahdi_chan *chan; + struct dahdi_echocan_state *ec; - for (f = 0; f < (wc->tspans[x]->spantype == TYPE_E1 ? 31 : 24); f++) { - if (!(wc->tspans[x]->chans[f] = kmalloc(sizeof(*wc->tspans[x]->chans[f]), GFP_KERNEL))) { + chan = kzalloc(sizeof(*chan), GFP_KERNEL); + if (!chan) { free_wc(wc); return -ENOMEM; } - memset(wc->tspans[x]->chans[f], 0, sizeof(*wc->tspans[x]->chans[f])); - if (!(wc->tspans[x]->ec[f] = kmalloc(sizeof(*wc->tspans[x]->ec[f]), GFP_KERNEL))) { + ts->chans[f] = chan; + + ec = kzalloc(sizeof(*ec), GFP_KERNEL); + if (!ec) { free_wc(wc); return -ENOMEM; } - memset(wc->tspans[x]->ec[f], 0, sizeof(*wc->tspans[x]->ec[f])); + ts->ec[f] = ec; } #ifdef ENABLE_WORKQUEUES - INIT_WORK(&wc->tspans[x]->swork, workq_handlespan, wc->tspans[x]); + INIT_WORK(&ts->swork, workq_handlespan, ts); #endif - wc->tspans[x]->spanflags |= wc->devtype->flags; + ts->spanflags |= wc->devtype->flags; } /* Continue hardware intiialization */