From 922364777bed26997dbd4efd34b6855bc399baf6 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Sat, 4 Dec 2010 15:25:35 -0600 Subject: [PATCH] dahdi: Prevent unloadable module on failed open. If the chan->span->ops->open fails the module implementing the board driver will not be released. 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 --- 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 5cf6257..e2fa2eb 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -2780,6 +2780,7 @@ static int dahdi_specchan_open(struct file *file) 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 */ @@ -2787,13 +2788,17 @@ static int dahdi_specchan_open(struct file *file) return res; } spin_lock_irqsave(&chan->lock, flags); + ops = chan->span->ops; if (is_pseudo_chan(chan)) chan->flags |= DAHDI_FLAG_AUDIO; if (chan->span) { - if (!try_module_get(chan->span->ops->owner)) + 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; -- 1.7.3.2.245.g03276