diff options
author | Shaun Ruffell <sruffell@digium.com> | 2011-01-03 18:26:52 +0000 |
---|---|---|
committer | Shaun Ruffell <sruffell@digium.com> | 2011-01-03 18:26:52 +0000 |
commit | 5ac383cd1f7dc7d84f5851cfbd842136a10c2b99 (patch) | |
tree | b3a1714678967f30c598473cc44d8c6208fa69d2 | |
parent | 35bf424396fdae7f8cddf3ecc5bcc76630eff769 (diff) |
dahdi: Minor fix for alloc/free of 'struct ecfactory'
Do not allocate the structure with GFP_KERNEL under the lock in
dahdi_echocan_factory_register and closes a leak in
dahdi_echocan_factory_unregister.
Signed-off-by: Shaun Ruffell <sruffell@digium.com>
Acked-by: Kinsey Moore <kmoore@digium.com>
git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9590 a0bf4364-ded3-4de4-8d8a-66a801d63aff
-rw-r--r-- | drivers/dahdi/dahdi-base.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c index bfe3a98..ac5b77e 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -495,28 +495,29 @@ struct ecfactory { int dahdi_register_echocan_factory(const struct dahdi_echocan_factory *ec) { struct ecfactory *cur; + struct ecfactory *new; WARN_ON(!ec->owner); + new = kzalloc(sizeof(*new), GFP_KERNEL); + if (!new) + return -ENOMEM; + + INIT_LIST_HEAD(&new->list); + spin_lock(&ecfactory_list_lock); /* make sure it isn't already registered */ list_for_each_entry(cur, &ecfactory_list, list) { if (cur->ec == ec) { spin_unlock(&ecfactory_list_lock); + kfree(new); return -EPERM; } } - if (!(cur = kzalloc(sizeof(*cur), GFP_KERNEL))) { - spin_unlock(&ecfactory_list_lock); - return -ENOMEM; - } - - cur->ec = ec; - INIT_LIST_HEAD(&cur->list); - - list_add_tail(&cur->list, &ecfactory_list); + new->ec = ec; + list_add_tail(&new->list, &ecfactory_list); spin_unlock(&ecfactory_list_lock); @@ -532,6 +533,7 @@ void dahdi_unregister_echocan_factory(const struct dahdi_echocan_factory *ec) list_for_each_entry_safe(cur, next, &ecfactory_list, list) { if (cur->ec == ec) { list_del(&cur->list); + kfree(cur); break; } } |