aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/send.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/send.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/send.c')
-rw-r--r--net/batman-adv/send.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 9a20ba9e056f..d0cfa95e3037 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -73,7 +73,7 @@ int send_skb_packet(struct sk_buff *skb, struct hard_iface *hard_iface,
73 } 73 }
74 74
75 /* push to the ethernet header. */ 75 /* push to the ethernet header. */
76 if (my_skb_head_push(skb, sizeof(struct ethhdr)) < 0) 76 if (my_skb_head_push(skb, sizeof(*ethhdr)) < 0)
77 goto send_skb_err; 77 goto send_skb_err;
78 78
79 skb_reset_mac_header(skb); 79 skb_reset_mac_header(skb);
@@ -144,7 +144,7 @@ static void send_packet_to_if(struct forw_packet *forw_packet,
144 hard_iface->net_dev->name, 144 hard_iface->net_dev->name,
145 hard_iface->net_dev->dev_addr); 145 hard_iface->net_dev->dev_addr);
146 146
147 buff_pos += sizeof(struct batman_packet) + 147 buff_pos += sizeof(*batman_packet) +
148 (batman_packet->num_tt * ETH_ALEN); 148 (batman_packet->num_tt * ETH_ALEN);
149 packet_num++; 149 packet_num++;
150 batman_packet = (struct batman_packet *) 150 batman_packet = (struct batman_packet *)
@@ -220,19 +220,18 @@ static void rebuild_batman_packet(struct bat_priv *bat_priv,
220 unsigned char *new_buff; 220 unsigned char *new_buff;
221 struct batman_packet *batman_packet; 221 struct batman_packet *batman_packet;
222 222
223 new_len = sizeof(struct batman_packet) + 223 new_len = sizeof(*batman_packet) + (bat_priv->num_local_tt * ETH_ALEN);
224 (bat_priv->num_local_tt * ETH_ALEN);
225 new_buff = kmalloc(new_len, GFP_ATOMIC); 224 new_buff = kmalloc(new_len, GFP_ATOMIC);
226 225
227 /* keep old buffer if kmalloc should fail */ 226 /* keep old buffer if kmalloc should fail */
228 if (new_buff) { 227 if (new_buff) {
229 memcpy(new_buff, hard_iface->packet_buff, 228 memcpy(new_buff, hard_iface->packet_buff,
230 sizeof(struct batman_packet)); 229 sizeof(*batman_packet));
231 batman_packet = (struct batman_packet *)new_buff; 230 batman_packet = (struct batman_packet *)new_buff;
232 231
233 batman_packet->num_tt = tt_local_fill_buffer(bat_priv, 232 batman_packet->num_tt = tt_local_fill_buffer(bat_priv,
234 new_buff + sizeof(struct batman_packet), 233 new_buff + sizeof(*batman_packet),
235 new_len - sizeof(struct batman_packet)); 234 new_len - sizeof(*batman_packet));
236 235
237 kfree(hard_iface->packet_buff); 236 kfree(hard_iface->packet_buff);
238 hard_iface->packet_buff = new_buff; 237 hard_iface->packet_buff = new_buff;
@@ -368,7 +367,7 @@ void schedule_forward_packet(struct orig_node *orig_node,
368 send_time = forward_send_time(); 367 send_time = forward_send_time();
369 add_bat_packet_to_list(bat_priv, 368 add_bat_packet_to_list(bat_priv,
370 (unsigned char *)batman_packet, 369 (unsigned char *)batman_packet,
371 sizeof(struct batman_packet) + tt_buff_len, 370 sizeof(*batman_packet) + tt_buff_len,
372 if_incoming, 0, send_time); 371 if_incoming, 0, send_time);
373} 372}
374 373
@@ -424,7 +423,7 @@ int add_bcast_packet_to_list(struct bat_priv *bat_priv,
424 if (!primary_if) 423 if (!primary_if)
425 goto out_and_inc; 424 goto out_and_inc;
426 425
427 forw_packet = kmalloc(sizeof(struct forw_packet), GFP_ATOMIC); 426 forw_packet = kmalloc(sizeof(*forw_packet), GFP_ATOMIC);
428 427
429 if (!forw_packet) 428 if (!forw_packet)
430 goto out_and_inc; 429 goto out_and_inc;