aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2011-11-17 21:20:04 -0500
committerDavid S. Miller <davem@davemloft.net>2011-11-18 14:37:09 -0500
commitae641949df01b85117845bec45328eab6d6fada1 (patch)
treeed8d5aedd678f86e8554dc0b1c080a43ef4b331d
parenta7ae1992248e5cf9dc5bd35695ab846d27efe15f (diff)
net: Remove all uses of LL_ALLOCATED_SPACE
net: Remove all uses of LL_ALLOCATED_SPACE The macro LL_ALLOCATED_SPACE was ill-conceived. It applies the alignment to the sum of needed_headroom and needed_tailroom. As the amount that is then reserved for head room is needed_headroom with alignment, this means that the tail room left may be too small. This patch replaces all uses of LL_ALLOCATED_SPACE with the macro LL_RESERVED_SPACE and direct reference to needed_tailroom. This also fixes the problem with needed_headroom changing between allocating the skb and reserving the head room. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/netpoll.c6
-rw-r--r--net/econet/af_econet.c7
-rw-r--r--net/ieee802154/dgram.c7
-rw-r--r--net/ieee802154/raw.c7
-rw-r--r--net/packet/af_packet.c18
5 files changed, 30 insertions, 15 deletions
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index cf64c1ffa4cd..1a7d8e2c9768 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -422,6 +422,7 @@ static void arp_reply(struct sk_buff *skb)
422 struct sk_buff *send_skb; 422 struct sk_buff *send_skb;
423 struct netpoll *np, *tmp; 423 struct netpoll *np, *tmp;
424 unsigned long flags; 424 unsigned long flags;
425 int hlen, tlen;
425 int hits = 0; 426 int hits = 0;
426 427
427 if (list_empty(&npinfo->rx_np)) 428 if (list_empty(&npinfo->rx_np))
@@ -479,8 +480,9 @@ static void arp_reply(struct sk_buff *skb)
479 if (tip != np->local_ip) 480 if (tip != np->local_ip)
480 continue; 481 continue;
481 482
482 send_skb = find_skb(np, size + LL_ALLOCATED_SPACE(np->dev), 483 hlen = LL_RESERVED_SPACE(np->dev);
483 LL_RESERVED_SPACE(np->dev)); 484 tlen = np->dev->needed_tailroom;
485 send_skb = find_skb(np, size + hlen + tlen, hlen);
484 if (!send_skb) 486 if (!send_skb)
485 continue; 487 continue;
486 488
diff --git a/net/econet/af_econet.c b/net/econet/af_econet.c
index 1c1f26c5d672..7e717cb35ad1 100644
--- a/net/econet/af_econet.c
+++ b/net/econet/af_econet.c
@@ -322,6 +322,7 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
322 /* Real hardware Econet. We're not worthy etc. */ 322 /* Real hardware Econet. We're not worthy etc. */
323#ifdef CONFIG_ECONET_NATIVE 323#ifdef CONFIG_ECONET_NATIVE
324 unsigned short proto = 0; 324 unsigned short proto = 0;
325 int hlen, tlen;
325 int res; 326 int res;
326 327
327 if (len + 15 > dev->mtu) { 328 if (len + 15 > dev->mtu) {
@@ -331,12 +332,14 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
331 332
332 dev_hold(dev); 333 dev_hold(dev);
333 334
334 skb = sock_alloc_send_skb(sk, len + LL_ALLOCATED_SPACE(dev), 335 hlen = LL_RESERVED_SPACE(dev);
336 tlen = dev->needed_tailroom;
337 skb = sock_alloc_send_skb(sk, len + hlen + tlen,
335 msg->msg_flags & MSG_DONTWAIT, &err); 338 msg->msg_flags & MSG_DONTWAIT, &err);
336 if (skb == NULL) 339 if (skb == NULL)
337 goto out_unlock; 340 goto out_unlock;
338 341
339 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 342 skb_reserve(skb, hlen);
340 skb_reset_network_header(skb); 343 skb_reset_network_header(skb);
341 344
342 eb = (struct ec_cb *)&skb->cb; 345 eb = (struct ec_cb *)&skb->cb;
diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
index faecf648123f..1b09eaabaac1 100644
--- a/net/ieee802154/dgram.c
+++ b/net/ieee802154/dgram.c
@@ -209,6 +209,7 @@ static int dgram_sendmsg(struct kiocb *iocb, struct sock *sk,
209 unsigned mtu; 209 unsigned mtu;
210 struct sk_buff *skb; 210 struct sk_buff *skb;
211 struct dgram_sock *ro = dgram_sk(sk); 211 struct dgram_sock *ro = dgram_sk(sk);
212 int hlen, tlen;
212 int err; 213 int err;
213 214
214 if (msg->msg_flags & MSG_OOB) { 215 if (msg->msg_flags & MSG_OOB) {
@@ -229,13 +230,15 @@ static int dgram_sendmsg(struct kiocb *iocb, struct sock *sk,
229 mtu = dev->mtu; 230 mtu = dev->mtu;
230 pr_debug("name = %s, mtu = %u\n", dev->name, mtu); 231 pr_debug("name = %s, mtu = %u\n", dev->name, mtu);
231 232
232 skb = sock_alloc_send_skb(sk, LL_ALLOCATED_SPACE(dev) + size, 233 hlen = LL_RESERVED_SPACE(dev);
234 tlen = dev->needed_tailroom;
235 skb = sock_alloc_send_skb(sk, hlen + tlen + size,
233 msg->msg_flags & MSG_DONTWAIT, 236 msg->msg_flags & MSG_DONTWAIT,
234 &err); 237 &err);
235 if (!skb) 238 if (!skb)
236 goto out_dev; 239 goto out_dev;
237 240
238 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 241 skb_reserve(skb, hlen);
239 242
240 skb_reset_network_header(skb); 243 skb_reset_network_header(skb);
241 244
diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c
index 10970ca85748..f96bae8fd330 100644
--- a/net/ieee802154/raw.c
+++ b/net/ieee802154/raw.c
@@ -108,6 +108,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
108 struct net_device *dev; 108 struct net_device *dev;
109 unsigned mtu; 109 unsigned mtu;
110 struct sk_buff *skb; 110 struct sk_buff *skb;
111 int hlen, tlen;
111 int err; 112 int err;
112 113
113 if (msg->msg_flags & MSG_OOB) { 114 if (msg->msg_flags & MSG_OOB) {
@@ -137,12 +138,14 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
137 goto out_dev; 138 goto out_dev;
138 } 139 }
139 140
140 skb = sock_alloc_send_skb(sk, LL_ALLOCATED_SPACE(dev) + size, 141 hlen = LL_RESERVED_SPACE(dev);
142 tlen = dev->needed_tailroom;
143 skb = sock_alloc_send_skb(sk, hlen + tlen + size,
141 msg->msg_flags & MSG_DONTWAIT, &err); 144 msg->msg_flags & MSG_DONTWAIT, &err);
142 if (!skb) 145 if (!skb)
143 goto out_dev; 146 goto out_dev;
144 147
145 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 148 skb_reserve(skb, hlen);
146 149
147 skb_reset_mac_header(skb); 150 skb_reset_mac_header(skb);
148 skb_reset_network_header(skb); 151 skb_reset_network_header(skb);
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 82a6f34d39d0..71c1a7521d32 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1944,7 +1944,7 @@ static void tpacket_destruct_skb(struct sk_buff *skb)
1944 1944
1945static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, 1945static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
1946 void *frame, struct net_device *dev, int size_max, 1946 void *frame, struct net_device *dev, int size_max,
1947 __be16 proto, unsigned char *addr) 1947 __be16 proto, unsigned char *addr, int hlen)
1948{ 1948{
1949 union { 1949 union {
1950 struct tpacket_hdr *h1; 1950 struct tpacket_hdr *h1;
@@ -1978,7 +1978,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
1978 return -EMSGSIZE; 1978 return -EMSGSIZE;
1979 } 1979 }
1980 1980
1981 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 1981 skb_reserve(skb, hlen);
1982 skb_reset_network_header(skb); 1982 skb_reset_network_header(skb);
1983 1983
1984 data = ph.raw + po->tp_hdrlen - sizeof(struct sockaddr_ll); 1984 data = ph.raw + po->tp_hdrlen - sizeof(struct sockaddr_ll);
@@ -2053,6 +2053,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2053 unsigned char *addr; 2053 unsigned char *addr;
2054 int len_sum = 0; 2054 int len_sum = 0;
2055 int status = 0; 2055 int status = 0;
2056 int hlen, tlen;
2056 2057
2057 mutex_lock(&po->pg_vec_lock); 2058 mutex_lock(&po->pg_vec_lock);
2058 2059
@@ -2101,16 +2102,17 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2101 } 2102 }
2102 2103
2103 status = TP_STATUS_SEND_REQUEST; 2104 status = TP_STATUS_SEND_REQUEST;
2105 hlen = LL_RESERVED_SPACE(dev);
2106 tlen = dev->needed_tailroom;
2104 skb = sock_alloc_send_skb(&po->sk, 2107 skb = sock_alloc_send_skb(&po->sk,
2105 LL_ALLOCATED_SPACE(dev) 2108 hlen + tlen + sizeof(struct sockaddr_ll),
2106 + sizeof(struct sockaddr_ll),
2107 0, &err); 2109 0, &err);
2108 2110
2109 if (unlikely(skb == NULL)) 2111 if (unlikely(skb == NULL))
2110 goto out_status; 2112 goto out_status;
2111 2113
2112 tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto, 2114 tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto,
2113 addr); 2115 addr, hlen);
2114 2116
2115 if (unlikely(tp_len < 0)) { 2117 if (unlikely(tp_len < 0)) {
2116 if (po->tp_loss) { 2118 if (po->tp_loss) {
@@ -2207,6 +2209,7 @@ static int packet_snd(struct socket *sock,
2207 int vnet_hdr_len; 2209 int vnet_hdr_len;
2208 struct packet_sock *po = pkt_sk(sk); 2210 struct packet_sock *po = pkt_sk(sk);
2209 unsigned short gso_type = 0; 2211 unsigned short gso_type = 0;
2212 int hlen, tlen;
2210 2213
2211 /* 2214 /*
2212 * Get and verify the address. 2215 * Get and verify the address.
@@ -2291,8 +2294,9 @@ static int packet_snd(struct socket *sock,
2291 goto out_unlock; 2294 goto out_unlock;
2292 2295
2293 err = -ENOBUFS; 2296 err = -ENOBUFS;
2294 skb = packet_alloc_skb(sk, LL_ALLOCATED_SPACE(dev), 2297 hlen = LL_RESERVED_SPACE(dev);
2295 LL_RESERVED_SPACE(dev), len, vnet_hdr.hdr_len, 2298 tlen = dev->needed_tailroom;
2299 skb = packet_alloc_skb(sk, hlen + tlen, hlen, len, vnet_hdr.hdr_len,
2296 msg->msg_flags & MSG_DONTWAIT, &err); 2300 msg->msg_flags & MSG_DONTWAIT, &err);
2297 if (skb == NULL) 2301 if (skb == NULL)
2298 goto out_unlock; 2302 goto out_unlock;