packet: fix warnings in rollover lock contention
authorWillem de Bruijn <willemb@google.com>
Thu, 14 May 2015 19:25:02 +0000 (15:25 -0400)
committerDavid S. Miller <davem@davemloft.net>
Thu, 14 May 2015 21:40:54 +0000 (17:40 -0400)
Avoid two xchg calls whose return values were unused, causing a
warning on some architectures.

The relevant variable is a hint and read without mutual exclusion.
This fix makes all writers hold the receive_queue lock.

Suggested-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/packet/af_packet.c

index 31d58565726c4d72d48ce105a774901c767ced5e..c30d14781576d6af236277e7ebcca37bf905a2de 100644 (file)
@@ -1301,17 +1301,12 @@ static int packet_rcv_has_room(struct packet_sock *po, struct sk_buff *skb)
        int ret;
        bool has_room;
 
-       if (po->prot_hook.func == tpacket_rcv) {
-               spin_lock(&po->sk.sk_receive_queue.lock);
-               ret = __packet_rcv_has_room(po, skb);
-               spin_unlock(&po->sk.sk_receive_queue.lock);
-       } else {
-               ret = __packet_rcv_has_room(po, skb);
-       }
-
+       spin_lock_bh(&po->sk.sk_receive_queue.lock);
+       ret = __packet_rcv_has_room(po, skb);
        has_room = ret == ROOM_NORMAL;
        if (po->pressure == has_room)
-               xchg(&po->pressure, !has_room);
+               po->pressure = !has_room;
+       spin_unlock_bh(&po->sk.sk_receive_queue.lock);
 
        return ret;
 }
@@ -3814,7 +3809,7 @@ static unsigned int packet_poll(struct file *file, struct socket *sock,
                        mask |= POLLIN | POLLRDNORM;
        }
        if (po->pressure && __packet_rcv_has_room(po, NULL) == ROOM_NORMAL)
-               xchg(&po->pressure, 0);
+               po->pressure = 0;
        spin_unlock_bh(&sk->sk_receive_queue.lock);
        spin_lock_bh(&sk->sk_write_queue.lock);
        if (po->tx_ring.pg_vec) {