[svn-commits] sruffell: linux/trunk r9590 - /linux/trunk/drivers/dahdi/dahdi-base.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jan 3 18:26:56 UTC 2011


Author: sruffell
Date: Mon Jan  3 12:26:52 2011
New Revision: 9590

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=9590
Log:
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 at digium.com>
Acked-by: Kinsey Moore <kmoore at digium.com>

Modified:
    linux/trunk/drivers/dahdi/dahdi-base.c

Modified: linux/trunk/drivers/dahdi/dahdi-base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/dahdi-base.c?view=diff&rev=9590&r1=9589&r2=9590
==============================================================================
--- linux/trunk/drivers/dahdi/dahdi-base.c (original)
+++ linux/trunk/drivers/dahdi/dahdi-base.c Mon Jan  3 12:26:52 2011
@@ -495,8 +495,15 @@
 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);
 
@@ -504,19 +511,13 @@
 	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 @@
 	list_for_each_entry_safe(cur, next, &ecfactory_list, list) {
 		if (cur->ec == ec) {
 			list_del(&cur->list);
+			kfree(cur);
 			break;
 		}
 	}




More information about the svn-commits mailing list