Patchwork [net-next-2.6] af_packet: lock imbalance

login
register
mail settings
Submitter Eric Dumazet
Date July 7, 2011, 1:33 p.m.
Message ID <1310045587.2127.15.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>
Download mbox | patch
Permalink /patch/103664/
State Accepted
Delegated to: David Miller
Headers show

Comments

Eric Dumazet - July 7, 2011, 1:33 p.m.
fanout_add() might return with fanout_mutex held.

Reduce indentation level while we are at it

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 net/packet/af_packet.c |   62 +++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 31 deletions(-)



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - July 7, 2011, 1:41 p.m.
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 07 Jul 2011 15:33:07 +0200

> fanout_add() might return with fanout_mutex held.
> 
> Reduce indentation level while we are at it
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied, thanks for fixing this Eric.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index aec50a1..caa9fba 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -589,43 +589,43 @@  static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
 			break;
 		}
 	}
+	err = -EINVAL;
 	if (match && match->defrag != defrag)
-		return -EINVAL;
+		goto out;
 	if (!match) {
+		err = -ENOMEM;
 		match = kzalloc(sizeof(*match), GFP_KERNEL);
-		if (match) {
-			write_pnet(&match->net, sock_net(sk));
-			match->id = id;
-			match->type = type;
-			match->defrag = defrag;
-			atomic_set(&match->rr_cur, 0);
-			INIT_LIST_HEAD(&match->list);
-			spin_lock_init(&match->lock);
-			atomic_set(&match->sk_ref, 0);
-			match->prot_hook.type = po->prot_hook.type;
-			match->prot_hook.dev = po->prot_hook.dev;
-			match->prot_hook.func = packet_rcv_fanout;
-			match->prot_hook.af_packet_priv = match;
-			dev_add_pack(&match->prot_hook);
-			list_add(&match->list, &fanout_list);
-		}
+		if (!match)
+			goto out;
+		write_pnet(&match->net, sock_net(sk));
+		match->id = id;
+		match->type = type;
+		match->defrag = defrag;
+		atomic_set(&match->rr_cur, 0);
+		INIT_LIST_HEAD(&match->list);
+		spin_lock_init(&match->lock);
+		atomic_set(&match->sk_ref, 0);
+		match->prot_hook.type = po->prot_hook.type;
+		match->prot_hook.dev = po->prot_hook.dev;
+		match->prot_hook.func = packet_rcv_fanout;
+		match->prot_hook.af_packet_priv = match;
+		dev_add_pack(&match->prot_hook);
+		list_add(&match->list, &fanout_list);
 	}
-	err = -ENOMEM;
-	if (match) {
-		err = -EINVAL;
-		if (match->type == type &&
-		    match->prot_hook.type == po->prot_hook.type &&
-		    match->prot_hook.dev == po->prot_hook.dev) {
-			err = -ENOSPC;
-			if (atomic_read(&match->sk_ref) < PACKET_FANOUT_MAX) {
-				__dev_remove_pack(&po->prot_hook);
-				po->fanout = match;
-				atomic_inc(&match->sk_ref);
-				__fanout_link(sk, po);
-				err = 0;
-			}
+	err = -EINVAL;
+	if (match->type == type &&
+	    match->prot_hook.type == po->prot_hook.type &&
+	    match->prot_hook.dev == po->prot_hook.dev) {
+		err = -ENOSPC;
+		if (atomic_read(&match->sk_ref) < PACKET_FANOUT_MAX) {
+			__dev_remove_pack(&po->prot_hook);
+			po->fanout = match;
+			atomic_inc(&match->sk_ref);
+			__fanout_link(sk, po);
+			err = 0;
 		}
 	}
+out:
 	mutex_unlock(&fanout_mutex);
 	return err;
 }