diff options
author | Shaun Ruffell <sruffell@digium.com> | 2011-01-21 05:31:26 +0000 |
---|---|---|
committer | Shaun Ruffell <sruffell@digium.com> | 2011-01-21 05:31:26 +0000 |
commit | cb62a33adbe1a73f1c8fe2ce69997ce5d1ff6ae8 (patch) | |
tree | 5cba77686d55e04ba2ce728c8912c94ce68b6ab1 | |
parent | 5c604ecea172a1e9768a5fe803d82a1706191f3b (diff) |
dahdi: Prevent unloadable module on failed open.
If chan->span->ops->open() fails then the reference count of the module
implementing the board driver will not be decremented. The result is a
module that would always be "in use" and unloadable.
This change makes sure to release that reference when open failed.
(closes issue #18422)
Reported by: avarvit
Signed-off-by: Shaun Ruffell <sruffell@digium.com>
Acked-by: Angelos Varvitsiotis <avarvit@admin.grnet.gr>
Origin: http://svnview.digium.com/svn/dahdi?view=rev&rev=9510
git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/branches/2.4@9682 a0bf4364-ded3-4de4-8d8a-66a801d63aff
-rw-r--r-- | drivers/dahdi/dahdi-base.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c index 3ecd5c8..247f1f5 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -2789,6 +2789,7 @@ static int dahdi_specchan_open(struct file *file, int unit) res = -EBUSY; else if (!test_and_set_bit(DAHDI_FLAGBIT_OPEN, &chan->flags)) { unsigned long flags; + const struct dahdi_span_ops *ops; res = initialize_channel(chan); if (res) { /* Reallocbufs must have failed */ @@ -2799,10 +2800,14 @@ static int dahdi_specchan_open(struct file *file, int unit) if (chan->flags & DAHDI_FLAG_PSEUDO) chan->flags |= DAHDI_FLAG_AUDIO; if (chan->span) { - if (!try_module_get(chan->span->ops->owner)) + ops = chan->span->ops; + if (!try_module_get(ops->owner)) { res = -ENXIO; - else if (chan->span->ops->open) - res = chan->span->ops->open(chan); + } else if (ops->open) { + res = ops->open(chan); + if (res) + module_put(ops->owner); + } } if (!res) { chan->file = file; |