Skip to content

Commit

Permalink
[NET]: Undo code bloat in hot paths due to print_mac().
Browse files Browse the repository at this point in the history
If print_mac() is used inside of a pr_debug() the compiler
can't see that the call is redundant so still performs it
even of pr_debug() ends up being a nop.

So don't use print_mac() in such cases in hot code paths,
use MAC_FMT et al. instead.

As noted by Joe Perches, pr_debug() could be modified to
handle this better, but that is a change to an interface
used by the entire kernel and thus needs to be validated
carefully.  This here is thus the less risky fix for
2.6.25

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Apr 8, 2008
1 parent 6adb4f7 commit 21f644f
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 134 deletions.
11 changes: 5 additions & 6 deletions drivers/net/starfire.c
Original file line number Diff line number Diff line change
Expand Up @@ -1472,13 +1472,12 @@ static int __netdev_rx(struct net_device *dev, int *quota)
#ifndef final_version /* Remove after testing. */
/* You will want this info for the initial debug. */
if (debug > 5) {
DECLARE_MAC_BUF(mac);
DECLARE_MAC_BUF(mac2);

printk(KERN_DEBUG " Rx data %s %s"
printk(KERN_DEBUG " Rx data " MAC_FMT " " MAC_FMT
" %2.2x%2.2x.\n",
print_mac(mac, &skb->data[0]),
print_mac(mac2, &skb->data[6]),
skb->data[0], skb->data[1], skb->data[2],
skb->data[3], skb->data[4], skb->data[5],
skb->data[6], skb->data[7], skb->data[8],
skb->data[9], skb->data[10], skb->data[11],
skb->data[12], skb->data[13]);
}
#endif
Expand Down
15 changes: 10 additions & 5 deletions drivers/net/tokenring/olympic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1438,13 +1438,18 @@ static void olympic_arb_cmd(struct net_device *dev)

if (olympic_priv->olympic_network_monitor) {
struct trh_hdr *mac_hdr;
DECLARE_MAC_BUF(mac);
printk(KERN_WARNING "%s: Received MAC Frame, details: \n",dev->name);
mac_hdr = tr_hdr(mac_frame);
printk(KERN_WARNING "%s: MAC Frame Dest. Addr: %s\n",
dev->name, print_mac(mac, mac_hdr->daddr));
printk(KERN_WARNING "%s: MAC Frame Srce. Addr: %s\n",
dev->name, print_mac(mac, mac_hdr->saddr));
printk(KERN_WARNING "%s: MAC Frame Dest. Addr: "
MAC_FMT " \n", dev->name,
mac_hdr->daddr[0], mac_hdr->daddr[1],
mac_hdr->daddr[2], mac_hdr->daddr[3],
mac_hdr->daddr[4], mac_hdr->daddr[5]);
printk(KERN_WARNING "%s: MAC Frame Srce. Addr: "
MAC_FMT " \n", dev->name,
mac_hdr->saddr[0], mac_hdr->saddr[1],
mac_hdr->saddr[2], mac_hdr->saddr[3],
mac_hdr->saddr[4], mac_hdr->saddr[5]);
}
netif_rx(mac_frame);
dev->last_rx = jiffies;
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,12 @@ static int start_xmit(struct sk_buff *skb, struct net_device *dev)
struct scatterlist sg[1+MAX_SKB_FRAGS];
struct virtio_net_hdr *hdr;
const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
DECLARE_MAC_BUF(mac);

sg_init_table(sg, 1+MAX_SKB_FRAGS);

pr_debug("%s: xmit %p %s\n", dev->name, skb, print_mac(mac, dest));
pr_debug("%s: xmit %p " MAC_FMT "\n", dev->name, skb,
dest[0], dest[1], dest[2],
dest[3], dest[4], dest[5]);

/* Encode metadata header at front. */
hdr = skb_vnet_hdr(skb);
Expand Down
39 changes: 24 additions & 15 deletions drivers/net/wireless/hostap/hostap_80211_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
{
struct ieee80211_hdr_4addr *hdr;
int res, hdrlen;
DECLARE_MAC_BUF(mac);

if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
return 0;
Expand All @@ -647,8 +646,10 @@ hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
strcmp(crypt->ops->name, "TKIP") == 0) {
if (net_ratelimit()) {
printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
"received packet from %s\n",
local->dev->name, print_mac(mac, hdr->addr2));
"received packet from " MAC_FMT "\n",
local->dev->name,
hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
}
return -1;
}
Expand All @@ -657,9 +658,12 @@ hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
atomic_dec(&crypt->refcnt);
if (res < 0) {
printk(KERN_DEBUG "%s: decryption failed (SA=%s"
printk(KERN_DEBUG "%s: decryption failed (SA=" MAC_FMT
") res=%d\n",
local->dev->name, print_mac(mac, hdr->addr2), res);
local->dev->name,
hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
res);
local->comm_tallies.rx_discards_wep_undecryptable++;
return -1;
}
Expand Down Expand Up @@ -721,7 +725,6 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
struct ieee80211_crypt_data *crypt = NULL;
void *sta = NULL;
int keyidx = 0;
DECLARE_MAC_BUF(mac);

iface = netdev_priv(dev);
local = iface->local;
Expand Down Expand Up @@ -798,8 +801,10 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
* frames silently instead of filling system log with
* these reports. */
printk(KERN_DEBUG "%s: WEP decryption failed (not set)"
" (SA=%s)\n",
local->dev->name, print_mac(mac, hdr->addr2));
" (SA=" MAC_FMT ")\n",
local->dev->name,
hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
#endif
local->comm_tallies.rx_discards_wep_undecryptable++;
goto rx_dropped;
Expand All @@ -813,8 +818,9 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
(keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
{
printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
"from %s\n", dev->name,
print_mac(mac, hdr->addr2));
"from " MAC_FMT "\n", dev->name,
hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
/* TODO: could inform hostapd about this so that it
* could send auth failure report */
goto rx_dropped;
Expand Down Expand Up @@ -982,8 +988,10 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
"unencrypted EAPOL frame\n", local->dev->name);
} else {
printk(KERN_DEBUG "%s: encryption configured, but RX "
"frame not encrypted (SA=%s)\n",
local->dev->name, print_mac(mac, hdr->addr2));
"frame not encrypted (SA=" MAC_FMT ")\n",
local->dev->name,
hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
goto rx_dropped;
}
}
Expand All @@ -992,9 +1000,10 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
!hostap_is_eapol_frame(local, skb)) {
if (net_ratelimit()) {
printk(KERN_DEBUG "%s: dropped unencrypted RX data "
"frame from %s"
" (drop_unencrypted=1)\n",
dev->name, print_mac(mac, hdr->addr2));
"frame from " MAC_FMT " (drop_unencrypted=1)\n",
dev->name,
hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
}
goto rx_dropped;
}
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/wireless/hostap/hostap_80211_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ static struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
struct ieee80211_hdr_4addr *hdr;
u16 fc;
int prefix_len, postfix_len, hdr_len, res;
DECLARE_MAC_BUF(mac);

iface = netdev_priv(skb->dev);
local = iface->local;
Expand All @@ -329,8 +328,10 @@ static struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
hdr = (struct ieee80211_hdr_4addr *) skb->data;
if (net_ratelimit()) {
printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
"TX packet to %s\n",
local->dev->name, print_mac(mac, hdr->addr1));
"TX packet to " MAC_FMT "\n",
local->dev->name,
hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
hdr->addr1[3], hdr->addr1[4], hdr->addr1[5]);
}
kfree_skb(skb);
return NULL;
Expand Down
Loading

0 comments on commit 21f644f

Please sign in to comment.