aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/unicast.c
diff options
context:
space:
mode:
authorSven Eckelmann <sven@narfation.org>2011-05-14 17:14:54 -0400
committerSven Eckelmann <sven@narfation.org>2011-05-30 01:39:33 -0400
commit704509b8d44886cebfbaff1a9813c35dfa986954 (patch)
tree7b353f1d4a33b31d55d2a85f8d70882ade1868ce /net/batman-adv/unicast.c
parent958ca5985604a6f13387d32de489365df816558b (diff)
batman-adv: Calculate sizeof using variable insead of types
Documentation/CodingStyle recommends to use the form p = kmalloc(sizeof(*p), ...); to calculate the size of a struct and not the version where the struct name is spelled out to prevent bugs when the type of p changes. This also seems appropriate for manipulation of buffers when they are directly associated with p. Signed-off-by: Sven Eckelmann <sven@narfation.org>
Diffstat (limited to 'net/batman-adv/unicast.c')
-rw-r--r--net/batman-adv/unicast.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
index 82717fd9661d..6eabf42f8822 100644
--- a/net/batman-adv/unicast.c
+++ b/net/batman-adv/unicast.c
@@ -39,8 +39,8 @@ static struct sk_buff *frag_merge_packet(struct list_head *head,
39 (struct unicast_frag_packet *)skb->data; 39 (struct unicast_frag_packet *)skb->data;
40 struct sk_buff *tmp_skb; 40 struct sk_buff *tmp_skb;
41 struct unicast_packet *unicast_packet; 41 struct unicast_packet *unicast_packet;
42 int hdr_len = sizeof(struct unicast_packet); 42 int hdr_len = sizeof(*unicast_packet);
43 int uni_diff = sizeof(struct unicast_frag_packet) - hdr_len; 43 int uni_diff = sizeof(*up) - hdr_len;
44 44
45 /* set skb to the first part and tmp_skb to the second part */ 45 /* set skb to the first part and tmp_skb to the second part */
46 if (up->flags & UNI_FRAG_HEAD) { 46 if (up->flags & UNI_FRAG_HEAD) {
@@ -53,7 +53,7 @@ static struct sk_buff *frag_merge_packet(struct list_head *head,
53 if (skb_linearize(skb) < 0 || skb_linearize(tmp_skb) < 0) 53 if (skb_linearize(skb) < 0 || skb_linearize(tmp_skb) < 0)
54 goto err; 54 goto err;
55 55
56 skb_pull(tmp_skb, sizeof(struct unicast_frag_packet)); 56 skb_pull(tmp_skb, sizeof(*up));
57 if (pskb_expand_head(skb, 0, tmp_skb->len, GFP_ATOMIC) < 0) 57 if (pskb_expand_head(skb, 0, tmp_skb->len, GFP_ATOMIC) < 0)
58 goto err; 58 goto err;
59 59
@@ -99,8 +99,7 @@ static int frag_create_buffer(struct list_head *head)
99 struct frag_packet_list_entry *tfp; 99 struct frag_packet_list_entry *tfp;
100 100
101 for (i = 0; i < FRAG_BUFFER_SIZE; i++) { 101 for (i = 0; i < FRAG_BUFFER_SIZE; i++) {
102 tfp = kmalloc(sizeof(struct frag_packet_list_entry), 102 tfp = kmalloc(sizeof(*tfp), GFP_ATOMIC);
103 GFP_ATOMIC);
104 if (!tfp) { 103 if (!tfp) {
105 frag_list_free(head); 104 frag_list_free(head);
106 return -ENOMEM; 105 return -ENOMEM;
@@ -224,8 +223,8 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
224 struct hard_iface *primary_if; 223 struct hard_iface *primary_if;
225 struct sk_buff *frag_skb; 224 struct sk_buff *frag_skb;
226 struct unicast_frag_packet *frag1, *frag2; 225 struct unicast_frag_packet *frag1, *frag2;
227 int uc_hdr_len = sizeof(struct unicast_packet); 226 int uc_hdr_len = sizeof(*unicast_packet);
228 int ucf_hdr_len = sizeof(struct unicast_frag_packet); 227 int ucf_hdr_len = sizeof(*frag1);
229 int data_len = skb->len - uc_hdr_len; 228 int data_len = skb->len - uc_hdr_len;
230 int large_tail = 0, ret = NET_RX_DROP; 229 int large_tail = 0, ret = NET_RX_DROP;
231 uint16_t seqno; 230 uint16_t seqno;
@@ -250,14 +249,14 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
250 frag1 = (struct unicast_frag_packet *)skb->data; 249 frag1 = (struct unicast_frag_packet *)skb->data;
251 frag2 = (struct unicast_frag_packet *)frag_skb->data; 250 frag2 = (struct unicast_frag_packet *)frag_skb->data;
252 251
253 memcpy(frag1, &tmp_uc, sizeof(struct unicast_packet)); 252 memcpy(frag1, &tmp_uc, sizeof(tmp_uc));
254 253
255 frag1->ttl--; 254 frag1->ttl--;
256 frag1->version = COMPAT_VERSION; 255 frag1->version = COMPAT_VERSION;
257 frag1->packet_type = BAT_UNICAST_FRAG; 256 frag1->packet_type = BAT_UNICAST_FRAG;
258 257
259 memcpy(frag1->orig, primary_if->net_dev->dev_addr, ETH_ALEN); 258 memcpy(frag1->orig, primary_if->net_dev->dev_addr, ETH_ALEN);
260 memcpy(frag2, frag1, sizeof(struct unicast_frag_packet)); 259 memcpy(frag2, frag1, sizeof(*frag2));
261 260
262 if (data_len & 1) 261 if (data_len & 1)
263 large_tail = UNI_FRAG_LARGETAIL; 262 large_tail = UNI_FRAG_LARGETAIL;
@@ -314,7 +313,7 @@ find_router:
314 if (!neigh_node) 313 if (!neigh_node)
315 goto out; 314 goto out;
316 315
317 if (my_skb_head_push(skb, sizeof(struct unicast_packet)) < 0) 316 if (my_skb_head_push(skb, sizeof(*unicast_packet)) < 0)
318 goto out; 317 goto out;
319 318
320 unicast_packet = (struct unicast_packet *)skb->data; 319 unicast_packet = (struct unicast_packet *)skb->data;
@@ -328,7 +327,7 @@ find_router:
328 memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN); 327 memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN);
329 328
330 if (atomic_read(&bat_priv->fragmentation) && 329 if (atomic_read(&bat_priv->fragmentation) &&
331 data_len + sizeof(struct unicast_packet) > 330 data_len + sizeof(*unicast_packet) >
332 neigh_node->if_incoming->net_dev->mtu) { 331 neigh_node->if_incoming->net_dev->mtu) {
333 /* send frag skb decreases ttl */ 332 /* send frag skb decreases ttl */
334 unicast_packet->ttl++; 333 unicast_packet->ttl++;