summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorShaun Ruffell <sruffell@digium.com>2009-06-29 20:56:07 +0000
committerShaun Ruffell <sruffell@digium.com>2009-06-29 20:56:07 +0000
commit0b13254ec47e0e72bcfd29c170f5752f87e957ce (patch)
tree00d903d8f17c3be33730d4e25b453306db83eca8 /drivers
parent9a504db54b889af1d6b3b59a96a16109c814c709 (diff)
dahdi-base: Enable DAHDI to manage the reference counts for the board drivers.
Adds a struct module 'owner' member to the dahdi_span structure and updates all the board drivers to set this member before registering the span. This allows the core of dahdi to maintain the reference counts on the channels itself. (closes issue #10601) Reported by: Matti git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@6794 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'drivers')
-rw-r--r--drivers/dahdi/dahdi-base.c67
-rw-r--r--drivers/dahdi/dahdi_dummy.c1
-rw-r--r--drivers/dahdi/dahdi_dynamic.c4
-rw-r--r--drivers/dahdi/pciradio.c1
-rw-r--r--drivers/dahdi/tor2.c1
-rw-r--r--drivers/dahdi/wcb4xxp/base.c7
-rw-r--r--drivers/dahdi/wcfxo.c1
-rw-r--r--drivers/dahdi/wct1xxp.c1
-rw-r--r--drivers/dahdi/wct4xxp/base.c5
-rw-r--r--drivers/dahdi/wctdm.c3
-rw-r--r--drivers/dahdi/wctdm24xxp/base.c3
-rw-r--r--drivers/dahdi/wcte11xp.c2
-rw-r--r--drivers/dahdi/wcte12xp/base.c7
-rw-r--r--drivers/dahdi/xpp/card_bri.c1
-rw-r--r--drivers/dahdi/xpp/card_fxo.c1
-rw-r--r--drivers/dahdi/xpp/card_fxs.c1
-rw-r--r--drivers/dahdi/xpp/card_pri.c1
-rw-r--r--drivers/dahdi/xpp/xpp_dahdi.c2
18 files changed, 58 insertions, 51 deletions
diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c
index b29e645..71b2063 100644
--- a/drivers/dahdi/dahdi-base.c
+++ b/drivers/dahdi/dahdi-base.c
@@ -15,7 +15,7 @@
* from Cisco 3620 to IBM x305 here in F1 Group
*
* Copyright (C) 2001 Jim Dixon / Zapata Telephony.
- * Copyright (C) 2001 - 2008 Digium, Inc.
+ * Copyright (C) 2001 - 2009 Digium, Inc.
*
* All rights reserved.
*
@@ -2649,39 +2649,44 @@ static int dahdi_timer_release(struct inode *inode, struct file *file)
static int dahdi_specchan_open(struct inode *inode, struct file *file, int unit)
{
int res = 0;
+ struct dahdi_chan *const chan = chans[unit];
- if (chans[unit] && chans[unit]->sig) {
+ if (chan && chan->sig) {
/* Make sure we're not already open, a net device, or a slave device */
- if (chans[unit]->flags & DAHDI_FLAG_NETDEV)
+ if (chan->flags & DAHDI_FLAG_NETDEV)
res = -EBUSY;
- else if (chans[unit]->master != chans[unit])
+ else if (chan->master != chan)
res = -EBUSY;
- else if ((chans[unit]->sig & __DAHDI_SIG_DACS) == __DAHDI_SIG_DACS)
+ else if ((chan->sig & __DAHDI_SIG_DACS) == __DAHDI_SIG_DACS)
res = -EBUSY;
- else if (!test_and_set_bit(DAHDI_FLAGBIT_OPEN, &chans[unit]->flags)) {
+ else if (!test_and_set_bit(DAHDI_FLAGBIT_OPEN, &chan->flags)) {
unsigned long flags;
- res = initialize_channel(chans[unit]);
+ res = initialize_channel(chan);
if (res) {
/* Reallocbufs must have failed */
- clear_bit(DAHDI_FLAGBIT_OPEN, &chans[unit]->flags);
+ clear_bit(DAHDI_FLAGBIT_OPEN, &chan->flags);
return res;
}
- spin_lock_irqsave(&chans[unit]->lock, flags);
- if (chans[unit]->flags & DAHDI_FLAG_PSEUDO)
- chans[unit]->flags |= DAHDI_FLAG_AUDIO;
- if (chans[unit]->span && chans[unit]->span->open) {
- res = chans[unit]->span->open(chans[unit]);
+ spin_lock_irqsave(&chan->lock, flags);
+ if (chan->flags & DAHDI_FLAG_PSEUDO)
+ chan->flags |= DAHDI_FLAG_AUDIO;
+ if (chan->span) {
+ if (!try_module_get(chan->span->owner))
+ res = -ENXIO;
+ else if (chan->span->open)
+ res = chan->span->open(chan);
}
if (!res) {
- chans[unit]->file = file;
- spin_unlock_irqrestore(&chans[unit]->lock, flags);
+ chan->file = file;
+ spin_unlock_irqrestore(&chan->lock, flags);
} else {
- spin_unlock_irqrestore(&chans[unit]->lock, flags);
- close_channel(chans[unit]);
- clear_bit(DAHDI_FLAGBIT_OPEN, &chans[unit]->flags);
+ spin_unlock_irqrestore(&chan->lock, flags);
+ close_channel(chan);
+ clear_bit(DAHDI_FLAGBIT_OPEN, &chan->flags);
}
- } else
+ } else {
res = -EBUSY;
+ }
} else
res = -ENXIO;
return res;
@@ -2691,18 +2696,22 @@ static int dahdi_specchan_release(struct inode *node, struct file *file, int uni
{
int res=0;
unsigned long flags;
+ struct dahdi_chan *const chan = chans[unit];
- if (chans[unit]) {
+ if (chan) {
/* Chan lock protects contents against potentially non atomic accesses.
* So if the pointer setting is not atomic, we should protect */
- spin_lock_irqsave(&chans[unit]->lock, flags);
- chans[unit]->file = NULL;
- spin_unlock_irqrestore(&chans[unit]->lock, flags);
- close_channel(chans[unit]);
- if (chans[unit]->span && chans[unit]->span->close)
- res = chans[unit]->span->close(chans[unit]);
+ spin_lock_irqsave(&chan->lock, flags);
+ chan->file = NULL;
+ spin_unlock_irqrestore(&chan->lock, flags);
+ close_channel(chan);
+ if (chan->span) {
+ if (chan->span->close)
+ res = chan->span->close(chan);
+ module_put(chan->span->owner);
+ }
/* The channel might be destroyed by low-level driver span->close() */
- if(chans[unit])
+ if (chans[unit])
clear_bit(DAHDI_FLAGBIT_OPEN, &chans[unit]->flags);
} else
res = -ENXIO;
@@ -3851,8 +3860,10 @@ static int dahdi_ctl_ioctl(struct inode *inode, struct file *file, unsigned int
CHECK_VALID_SPAN(j);
if (spans[j]->flags & DAHDI_FLAG_RUNNING)
return 0;
+
if (spans[j]->startup)
res = spans[j]->startup(spans[j]);
+
if (!res) {
/* Mark as running and hangup any channels */
spans[j]->flags |= DAHDI_FLAG_RUNNING;
@@ -5499,6 +5510,8 @@ int dahdi_register(struct dahdi_span *span, int prefmaster)
if (!span)
return -EINVAL;
+ WARN_ON(!span->owner);
+
if (test_bit(DAHDI_FLAGBIT_REGISTERED, &span->flags)) {
module_printk(KERN_ERR, "Span %s already appears to be registered\n", span->name);
return -EBUSY;
diff --git a/drivers/dahdi/dahdi_dummy.c b/drivers/dahdi/dahdi_dummy.c
index 97949e3..d0297c3 100644
--- a/drivers/dahdi/dahdi_dummy.c
+++ b/drivers/dahdi/dahdi_dummy.c
@@ -189,6 +189,7 @@ static int dahdi_dummy_initialize(struct dahdi_dummy *ztd)
sprintf(ztd->chan->name, "DAHDI_DUMMY/%d/%d", 1, 0);
dahdi_copy_string(ztd->span.devicetype, "DAHDI Dummy Timing", sizeof(ztd->span.devicetype));
ztd->chan->chanpos = 1;
+ ztd->span.owner = THIS_MODULE;
ztd->span.chans = &ztd->chan;
ztd->span.channels = 0; /* no channels on our span */
ztd->span.deflaw = DAHDI_LAW_MULAW;
diff --git a/drivers/dahdi/dahdi_dynamic.c b/drivers/dahdi/dahdi_dynamic.c
index 2a5c267..e83fb80 100644
--- a/drivers/dahdi/dahdi_dynamic.c
+++ b/drivers/dahdi/dahdi_dynamic.c
@@ -516,8 +516,6 @@ static int ztd_open(struct dahdi_chan *chan)
return -ENODEV;
z->usecount++;
}
- if(!try_module_get(THIS_MODULE))
- printk(KERN_NOTICE "TDMoX: Unable to increment module use count\n");
return 0;
}
@@ -534,7 +532,6 @@ static int ztd_close(struct dahdi_chan *chan)
z->usecount--;
if (z->dead && !z->usecount)
dynamic_destroy(z);
- module_put(THIS_MODULE);
return 0;
}
@@ -604,6 +601,7 @@ static int create_dynamic(struct dahdi_dynamic_span *zds)
z->timing = zds->timing;
sprintf(z->span.name, "DYN/%s/%s", zds->driver, zds->addr);
sprintf(z->span.desc, "Dynamic '%s' span at '%s'", zds->driver, zds->addr);
+ z->span.owner = THIS_MODULE;
z->span.channels = zds->numchans;
z->span.pvt = z;
z->span.deflaw = DAHDI_LAW_MULAW;
diff --git a/drivers/dahdi/pciradio.c b/drivers/dahdi/pciradio.c
index 6b64e7e..48d86b4 100644
--- a/drivers/dahdi/pciradio.c
+++ b/drivers/dahdi/pciradio.c
@@ -1462,6 +1462,7 @@ static int pciradio_initialize(struct pciradio *rad)
int x;
/* DAHDI stuff */
+ rad->span.owner = THIS_MODULE;
sprintf(rad->span.name, "PCIRADIO/%d", rad->pos);
sprintf(rad->span.desc, "Board %d", rad->pos + 1);
rad->span.deflaw = DAHDI_LAW_MULAW;
diff --git a/drivers/dahdi/tor2.c b/drivers/dahdi/tor2.c
index 9ae8169..0be1793 100644
--- a/drivers/dahdi/tor2.c
+++ b/drivers/dahdi/tor2.c
@@ -272,6 +272,7 @@ static void init_spans(struct tor2 *tor)
dahdi_copy_string(tor->spans[x].devicetype, tor->type, sizeof(tor->spans[x].devicetype));
snprintf(tor->spans[x].location, sizeof(tor->spans[x].location) - 1,
"PCI Bus %02d Slot %02d", tor->pci->bus->number, PCI_SLOT(tor->pci->devfn) + 1);
+ tor->spans[x].owner = THIS_MODULE;
tor->spans[x].spanconfig = tor2_spanconfig;
tor->spans[x].chanconfig = tor2_chanconfig;
tor->spans[x].startup = tor2_startup;
diff --git a/drivers/dahdi/wcb4xxp/base.c b/drivers/dahdi/wcb4xxp/base.c
index f5db389..71e8255 100644
--- a/drivers/dahdi/wcb4xxp/base.c
+++ b/drivers/dahdi/wcb4xxp/base.c
@@ -2084,10 +2084,6 @@ static int b4xxp_open(struct dahdi_chan *chan)
struct b4xxp *b4 = chan->pvt;
struct b4xxp_span *bspan = &b4->spans[chan->span->offset];
- if (!try_module_get(THIS_MODULE)) {
- return -EBUSY;
- }
-
if (DBG_FOPS && DBG_SPANFILTER)
dev_info(b4->dev, "open() on chan %s (%i/%i)\n", chan->name, chan->channo, chan->chanpos);
@@ -2101,8 +2097,6 @@ static int b4xxp_close(struct dahdi_chan *chan)
struct b4xxp *b4 = chan->pvt;
struct b4xxp_span *bspan = &b4->spans[chan->span->offset];
- module_put(THIS_MODULE);
-
if (DBG_FOPS && DBG_SPANFILTER)
dev_info(b4->dev, "close() on chan %s (%i/%i)\n", chan->name, chan->channo, chan->chanpos);
@@ -2166,6 +2160,7 @@ static void init_spans(struct b4xxp *b4)
sprintf(bspan->span.location, "PCI Bus %02d Slot %02d",
b4->pdev->bus->number, PCI_SLOT(b4->pdev->devfn) + 1);
+ bspan->span.owner = THIS_MODULE;
bspan->span.spanconfig = b4xxp_spanconfig;
bspan->span.chanconfig = b4xxp_chanconfig;
bspan->span.startup = b4xxp_startup;
diff --git a/drivers/dahdi/wcfxo.c b/drivers/dahdi/wcfxo.c
index 7f8a210..69b42a0 100644
--- a/drivers/dahdi/wcfxo.c
+++ b/drivers/dahdi/wcfxo.c
@@ -636,6 +636,7 @@ static int wcfxo_hooksig(struct dahdi_chan *chan, enum dahdi_txsig txsig)
static int wcfxo_initialize(struct wcfxo *wc)
{
/* DAHDI stuff */
+ wc->span.owner = THIS_MODULE;
sprintf(wc->span.name, "WCFXO/%d", wc->pos);
snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Board %d", wc->variety, wc->pos + 1);
sprintf(wc->chan->name, "WCFXO/%d/%d", wc->pos, 0);
diff --git a/drivers/dahdi/wct1xxp.c b/drivers/dahdi/wct1xxp.c
index 0eaaf2f..09a87c5 100644
--- a/drivers/dahdi/wct1xxp.c
+++ b/drivers/dahdi/wct1xxp.c
@@ -759,6 +759,7 @@ static int t1xxp_software_init(struct t1xxp *wc)
dahdi_copy_string(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype));
snprintf(wc->span.location, sizeof(wc->span.location) - 1,
"PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
+ wc->span.owner = THIS_MODULE;
wc->span.spanconfig = t1xxp_spanconfig;
wc->span.chanconfig = t1xxp_chanconfig;
wc->span.irq = wc->dev->irq;
diff --git a/drivers/dahdi/wct4xxp/base.c b/drivers/dahdi/wct4xxp/base.c
index d3dcdda..60b5d14 100644
--- a/drivers/dahdi/wct4xxp/base.c
+++ b/drivers/dahdi/wct4xxp/base.c
@@ -1573,15 +1573,11 @@ static int t4_chanconfig(struct dahdi_chan *chan, int sigtype)
static int t4_open(struct dahdi_chan *chan)
{
- try_module_get(THIS_MODULE);
-
return 0;
}
static int t4_close(struct dahdi_chan *chan)
{
- module_put(THIS_MODULE);
-
return 0;
}
@@ -1631,6 +1627,7 @@ static void init_spans(struct t4 *wc)
ts->span.spantype = "J1";
break;
}
+ ts->span.owner = THIS_MODULE;
ts->span.spanconfig = t4_spanconfig;
ts->span.chanconfig = t4_chanconfig;
ts->span.irq = wc->dev->irq;
diff --git a/drivers/dahdi/wctdm.c b/drivers/dahdi/wctdm.c
index d6722a8..a20c9f9 100644
--- a/drivers/dahdi/wctdm.c
+++ b/drivers/dahdi/wctdm.c
@@ -1992,7 +1992,6 @@ static int wctdm_open(struct dahdi_chan *chan)
if (wc->dead)
return -ENODEV;
wc->usecount++;
- try_module_get(THIS_MODULE);
return 0;
}
@@ -2007,7 +2006,6 @@ static int wctdm_close(struct dahdi_chan *chan)
{
struct wctdm *wc = chan->pvt;
wc->usecount--;
- module_put(THIS_MODULE);
if (wc->modtype[chan->chanpos - 1] == MOD_TYPE_FXS) {
wc->mod[chan->chanpos - 1].fxs.idletxhookstate = POLARITY_XOR(chan->chanpos - 1) ? 0x5 : 0x1;
}
@@ -2105,6 +2103,7 @@ static int wctdm_initialize(struct wctdm *wc)
wc->chans[x]->chanpos = x+1;
wc->chans[x]->pvt = wc;
}
+ wc->span.owner = THIS_MODULE;
wc->span.chans = wc->chans;
wc->span.channels = NUM_CARDS;
wc->span.hooksig = wctdm_hooksig;
diff --git a/drivers/dahdi/wctdm24xxp/base.c b/drivers/dahdi/wctdm24xxp/base.c
index e4f8bf1..b3103ee 100644
--- a/drivers/dahdi/wctdm24xxp/base.c
+++ b/drivers/dahdi/wctdm24xxp/base.c
@@ -2960,7 +2960,6 @@ static int wctdm_open(struct dahdi_chan *chan)
if (wc->dead)
return -ENODEV;
wc->usecount++;
- try_module_get(THIS_MODULE);
/* Reset the mwi indicators */
spin_lock_irqsave(&wc->reglock, flags);
@@ -2984,7 +2983,6 @@ static int wctdm_close(struct dahdi_chan *chan)
int x;
signed char reg;
wc->usecount--;
- module_put(THIS_MODULE);
for (x=0;x<wc->cards;x++) {
if (wc->modtype[x] == MOD_TYPE_FXS) {
wc->mods[x].fxs.idletxhookstate = POLARITY_XOR(x) ? 5 : 1;
@@ -3226,6 +3224,7 @@ static int wctdm_initialize(struct wctdm *wc)
wc->chans[x]->chanpos = x+1;
wc->chans[x]->pvt = wc;
}
+ wc->span.owner = THIS_MODULE;
wc->span.chans = wc->chans;
wc->span.channels = wc->type;
wc->span.irq = pdev->irq;
diff --git a/drivers/dahdi/wcte11xp.c b/drivers/dahdi/wcte11xp.c
index 26f47fa..dec6d65 100644
--- a/drivers/dahdi/wcte11xp.c
+++ b/drivers/dahdi/wcte11xp.c
@@ -230,7 +230,6 @@ static int t1xxp_open(struct dahdi_chan *chan)
if (wc->dead)
return -ENODEV;
wc->usecount++;
- try_module_get(THIS_MODULE);
return 0;
}
@@ -355,7 +354,6 @@ static int t1xxp_close(struct dahdi_chan *chan)
struct t1 *wc = chan->pvt;
wc->usecount--;
- module_put(THIS_MODULE);
/* If we're dead, release us now */
if (!wc->usecount && wc->dead)
t1xxp_release(wc);
diff --git a/drivers/dahdi/wcte12xp/base.c b/drivers/dahdi/wcte12xp/base.c
index 83b87a8..29ce990 100644
--- a/drivers/dahdi/wcte12xp/base.c
+++ b/drivers/dahdi/wcte12xp/base.c
@@ -1142,15 +1142,11 @@ static int t1xxp_maint(struct dahdi_span *span, int cmd)
static int t1xxp_open(struct dahdi_chan *chan)
{
- if (!try_module_get(THIS_MODULE))
- return -ENXIO;
- else
- return 0;
+ return 0;
}
static int t1xxp_close(struct dahdi_chan *chan)
{
- module_put(THIS_MODULE);
return 0;
}
@@ -1226,6 +1222,7 @@ static int t1_software_init(struct t1 *wc)
snprintf(wc->span.location, sizeof(wc->span.location) - 1,
"PCI Bus %02d Slot %02d", dev->bus->number, PCI_SLOT(dev->devfn) + 1);
+ wc->span.owner = THIS_MODULE;
wc->span.spanconfig = t1xxp_spanconfig;
wc->span.chanconfig = t1xxp_chanconfig;
wc->span.irq = dev->irq;
diff --git a/drivers/dahdi/xpp/card_bri.c b/drivers/dahdi/xpp/card_bri.c
index a749f9d..81fb3ea 100644
--- a/drivers/dahdi/xpp/card_bri.c
+++ b/drivers/dahdi/xpp/card_bri.c
@@ -872,6 +872,7 @@ static int BRI_card_dahdi_preregistration(xpd_t *xpd, bool on)
/* Nothing to do yet */
return 0;
}
+ xpd->span.owner = THIS_MODULE;
xpd->span.spantype = "BRI";
xpd->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_CCS;
xpd->span.deflaw = DAHDI_LAW_ALAW;
diff --git a/drivers/dahdi/xpp/card_fxo.c b/drivers/dahdi/xpp/card_fxo.c
index b06fb3b..49ede03 100644
--- a/drivers/dahdi/xpp/card_fxo.c
+++ b/drivers/dahdi/xpp/card_fxo.c
@@ -509,6 +509,7 @@ static int FXO_card_dahdi_preregistration(xpd_t *xpd, bool on)
BUG_ON(!priv);
timer_count = xpd->timer_count;
XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF");
+ xpd->span.owner = THIS_MODULE;
xpd->span.spantype = "FXO";
for_each_line(xpd, i) {
struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i);
diff --git a/drivers/dahdi/xpp/card_fxs.c b/drivers/dahdi/xpp/card_fxs.c
index 26ba327..0bc94f1 100644
--- a/drivers/dahdi/xpp/card_fxs.c
+++ b/drivers/dahdi/xpp/card_fxs.c
@@ -494,6 +494,7 @@ static int FXS_card_dahdi_preregistration(xpd_t *xpd, bool on)
priv = xpd->priv;
BUG_ON(!priv);
XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off");
+ xpd->span.owner = THIS_MODULE;
xpd->span.spantype = "FXS";
for_each_line(xpd, i) {
struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i);
diff --git a/drivers/dahdi/xpp/card_pri.c b/drivers/dahdi/xpp/card_pri.c
index 93b43b0..94c8650 100644
--- a/drivers/dahdi/xpp/card_pri.c
+++ b/drivers/dahdi/xpp/card_pri.c
@@ -1017,6 +1017,7 @@ static int PRI_card_dahdi_preregistration(xpd_t *xpd, bool on)
/* Nothing to do yet */
return 0;
}
+ xpd->span.owner = THIS_MODULE;
xpd->span.spantype = pri_protocol_name(priv->pri_protocol);
xpd->span.linecompat = pri_linecompat(priv->pri_protocol);
xpd->span.deflaw = priv->deflaw;
diff --git a/drivers/dahdi/xpp/xpp_dahdi.c b/drivers/dahdi/xpp/xpp_dahdi.c
index 6e7ee85..a6f7cc8 100644
--- a/drivers/dahdi/xpp/xpp_dahdi.c
+++ b/drivers/dahdi/xpp/xpp_dahdi.c
@@ -1056,6 +1056,8 @@ int dahdi_register_xpd(xpd_t *xpd)
const xops_t *xops;
BUG_ON(!xpd);
+ WARN_ON(!xpd->span.owner);
+
xops = xpd->xops;
xbus = xpd->xbus;