Browse Source

batman-adv: don't switch byte order too often if not needed

If possible, operations like ntohs/ntohl should not be
performed too often. Use a variable to locally store the
converted value and then use it.

Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
Antonio Quartulli 12 years ago
parent
commit
3fba7325bb
1 changed files with 5 additions and 3 deletions
  1. 5 3
      net/batman-adv/routing.c

+ 5 - 3
net/batman-adv/routing.c

@@ -1135,6 +1135,7 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
 	int hdr_size = sizeof(*bcast_packet);
 	int hdr_size = sizeof(*bcast_packet);
 	int ret = NET_RX_DROP;
 	int ret = NET_RX_DROP;
 	int32_t seq_diff;
 	int32_t seq_diff;
+	uint32_t seqno;
 
 
 	/* drop packet if it has not necessary minimum size */
 	/* drop packet if it has not necessary minimum size */
 	if (unlikely(!pskb_may_pull(skb, hdr_size)))
 	if (unlikely(!pskb_may_pull(skb, hdr_size)))
@@ -1170,12 +1171,13 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
 
 
 	spin_lock_bh(&orig_node->bcast_seqno_lock);
 	spin_lock_bh(&orig_node->bcast_seqno_lock);
 
 
+	seqno = ntohl(bcast_packet->seqno);
 	/* check whether the packet is a duplicate */
 	/* check whether the packet is a duplicate */
 	if (batadv_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno,
 	if (batadv_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno,
-			    ntohl(bcast_packet->seqno)))
+			    seqno))
 		goto spin_unlock;
 		goto spin_unlock;
 
 
-	seq_diff = ntohl(bcast_packet->seqno) - orig_node->last_bcast_seqno;
+	seq_diff = seqno - orig_node->last_bcast_seqno;
 
 
 	/* check whether the packet is old and the host just restarted. */
 	/* check whether the packet is old and the host just restarted. */
 	if (batadv_window_protected(bat_priv, seq_diff,
 	if (batadv_window_protected(bat_priv, seq_diff,
@@ -1186,7 +1188,7 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
 	 * if required.
 	 * if required.
 	 */
 	 */
 	if (batadv_bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1))
 	if (batadv_bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1))
-		orig_node->last_bcast_seqno = ntohl(bcast_packet->seqno);
+		orig_node->last_bcast_seqno = seqno;
 
 
 	spin_unlock_bh(&orig_node->bcast_seqno_lock);
 	spin_unlock_bh(&orig_node->bcast_seqno_lock);