Skip to content

Commit 23f1f4e

Browse files
Stephen HemmingerDavid S. Miller
authored andcommitted
[NET] ethernet: optimize memcpy and memset
The ethernet header management only needs to handle a fixed size address (6 bytes). If the memcpy/memset are changed to be passed a constant length, then compiler can optimize for this case (and if it is smart eliminate string instructions). Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fd21150 commit 23f1f4e

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎net/ethernet/eth.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ int eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
9191

9292
if (!saddr)
9393
saddr = dev->dev_addr;
94-
memcpy(eth->h_source, saddr, dev->addr_len);
94+
memcpy(eth->h_source, saddr, ETH_ALEN);
9595

9696
if (daddr) {
97-
memcpy(eth->h_dest, daddr, dev->addr_len);
97+
memcpy(eth->h_dest, daddr, ETH_ALEN);
9898
return ETH_HLEN;
9999
}
100100

@@ -103,7 +103,7 @@ int eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
103103
*/
104104

105105
if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
106-
memset(eth->h_dest, 0, dev->addr_len);
106+
memset(eth->h_dest, 0, ETH_ALEN);
107107
return ETH_HLEN;
108108
}
109109

@@ -135,7 +135,7 @@ int eth_rebuild_header(struct sk_buff *skb)
135135
"%s: unable to resolve type %X addresses.\n",
136136
dev->name, (int)eth->h_proto);
137137

138-
memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
138+
memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
139139
break;
140140
}
141141

@@ -233,8 +233,8 @@ int eth_header_cache(struct neighbour *neigh, struct hh_cache *hh)
233233
return -1;
234234

235235
eth->h_proto = type;
236-
memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
237-
memcpy(eth->h_dest, neigh->ha, dev->addr_len);
236+
memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
237+
memcpy(eth->h_dest, neigh->ha, ETH_ALEN);
238238
hh->hh_len = ETH_HLEN;
239239
return 0;
240240
}
@@ -251,7 +251,7 @@ void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev,
251251
unsigned char *haddr)
252252
{
253253
memcpy(((u8 *) hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)),
254-
haddr, dev->addr_len);
254+
haddr, ETH_ALEN);
255255
}
256256

257257
/**
@@ -271,7 +271,7 @@ static int eth_mac_addr(struct net_device *dev, void *p)
271271
return -EBUSY;
272272
if (!is_valid_ether_addr(addr->sa_data))
273273
return -EADDRNOTAVAIL;
274-
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
274+
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
275275
return 0;
276276
}
277277

0 commit comments

Comments
 (0)