aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/vis.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/vis.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/vis.c')
-rw-r--r--net/batman-adv/vis.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c
index b48954cd1e12..ea8d7e91fcac 100644
--- a/net/batman-adv/vis.c
+++ b/net/batman-adv/vis.c
@@ -241,7 +241,7 @@ int vis_seq_print_text(struct seq_file *seq, void *offset)
241 hlist_for_each_entry_rcu(info, node, head, hash_entry) { 241 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
242 packet = (struct vis_packet *)info->skb_packet->data; 242 packet = (struct vis_packet *)info->skb_packet->data;
243 entries = (struct vis_info_entry *) 243 entries = (struct vis_info_entry *)
244 ((char *)packet + sizeof(struct vis_packet)); 244 ((char *)packet + sizeof(*packet));
245 245
246 for (j = 0; j < packet->entries; j++) { 246 for (j = 0; j < packet->entries; j++) {
247 if (entries[j].quality == 0) 247 if (entries[j].quality == 0)
@@ -289,7 +289,7 @@ int vis_seq_print_text(struct seq_file *seq, void *offset)
289 hlist_for_each_entry_rcu(info, node, head, hash_entry) { 289 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
290 packet = (struct vis_packet *)info->skb_packet->data; 290 packet = (struct vis_packet *)info->skb_packet->data;
291 entries = (struct vis_info_entry *) 291 entries = (struct vis_info_entry *)
292 ((char *)packet + sizeof(struct vis_packet)); 292 ((char *)packet + sizeof(*packet));
293 293
294 for (j = 0; j < packet->entries; j++) { 294 for (j = 0; j < packet->entries; j++) {
295 if (entries[j].quality == 0) 295 if (entries[j].quality == 0)
@@ -367,7 +367,7 @@ static void recv_list_add(struct bat_priv *bat_priv,
367{ 367{
368 struct recvlist_node *entry; 368 struct recvlist_node *entry;
369 369
370 entry = kmalloc(sizeof(struct recvlist_node), GFP_ATOMIC); 370 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
371 if (!entry) 371 if (!entry)
372 return; 372 return;
373 373
@@ -414,11 +414,11 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
414 return NULL; 414 return NULL;
415 415
416 /* see if the packet is already in vis_hash */ 416 /* see if the packet is already in vis_hash */
417 search_elem.skb_packet = dev_alloc_skb(sizeof(struct vis_packet)); 417 search_elem.skb_packet = dev_alloc_skb(sizeof(*search_packet));
418 if (!search_elem.skb_packet) 418 if (!search_elem.skb_packet)
419 return NULL; 419 return NULL;
420 search_packet = (struct vis_packet *)skb_put(search_elem.skb_packet, 420 search_packet = (struct vis_packet *)skb_put(search_elem.skb_packet,
421 sizeof(struct vis_packet)); 421 sizeof(*search_packet));
422 422
423 memcpy(search_packet->vis_orig, vis_packet->vis_orig, ETH_ALEN); 423 memcpy(search_packet->vis_orig, vis_packet->vis_orig, ETH_ALEN);
424 old_info = vis_hash_find(bat_priv, &search_elem); 424 old_info = vis_hash_find(bat_priv, &search_elem);
@@ -444,27 +444,26 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
444 kref_put(&old_info->refcount, free_info); 444 kref_put(&old_info->refcount, free_info);
445 } 445 }
446 446
447 info = kmalloc(sizeof(struct vis_info), GFP_ATOMIC); 447 info = kmalloc(sizeof(*info), GFP_ATOMIC);
448 if (!info) 448 if (!info)
449 return NULL; 449 return NULL;
450 450
451 info->skb_packet = dev_alloc_skb(sizeof(struct vis_packet) + 451 info->skb_packet = dev_alloc_skb(sizeof(*packet) + vis_info_len +
452 vis_info_len + sizeof(struct ethhdr)); 452 sizeof(struct ethhdr));
453 if (!info->skb_packet) { 453 if (!info->skb_packet) {
454 kfree(info); 454 kfree(info);
455 return NULL; 455 return NULL;
456 } 456 }
457 skb_reserve(info->skb_packet, sizeof(struct ethhdr)); 457 skb_reserve(info->skb_packet, sizeof(struct ethhdr));
458 packet = (struct vis_packet *)skb_put(info->skb_packet, 458 packet = (struct vis_packet *)skb_put(info->skb_packet, sizeof(*packet)
459 sizeof(struct vis_packet) + 459 + vis_info_len);
460 vis_info_len);
461 460
462 kref_init(&info->refcount); 461 kref_init(&info->refcount);
463 INIT_LIST_HEAD(&info->send_list); 462 INIT_LIST_HEAD(&info->send_list);
464 INIT_LIST_HEAD(&info->recv_list); 463 INIT_LIST_HEAD(&info->recv_list);
465 info->first_seen = jiffies; 464 info->first_seen = jiffies;
466 info->bat_priv = bat_priv; 465 info->bat_priv = bat_priv;
467 memcpy(packet, vis_packet, sizeof(struct vis_packet) + vis_info_len); 466 memcpy(packet, vis_packet, sizeof(*packet) + vis_info_len);
468 467
469 /* initialize and add new packet. */ 468 /* initialize and add new packet. */
470 *is_new = 1; 469 *is_new = 1;
@@ -634,7 +633,7 @@ static int generate_vis_packet(struct bat_priv *bat_priv)
634 packet->ttl = TTL; 633 packet->ttl = TTL;
635 packet->seqno = htonl(ntohl(packet->seqno) + 1); 634 packet->seqno = htonl(ntohl(packet->seqno) + 1);
636 packet->entries = 0; 635 packet->entries = 0;
637 skb_trim(info->skb_packet, sizeof(struct vis_packet)); 636 skb_trim(info->skb_packet, sizeof(*packet));
638 637
639 if (packet->vis_type == VIS_TYPE_CLIENT_UPDATE) { 638 if (packet->vis_type == VIS_TYPE_CLIENT_UPDATE) {
640 best_tq = find_best_vis_server(bat_priv, info); 639 best_tq = find_best_vis_server(bat_priv, info);
@@ -910,17 +909,15 @@ int vis_init(struct bat_priv *bat_priv)
910 goto err; 909 goto err;
911 } 910 }
912 911
913 bat_priv->my_vis_info->skb_packet = dev_alloc_skb( 912 bat_priv->my_vis_info->skb_packet = dev_alloc_skb(sizeof(*packet) +
914 sizeof(struct vis_packet) + 913 MAX_VIS_PACKET_SIZE +
915 MAX_VIS_PACKET_SIZE + 914 sizeof(struct ethhdr));
916 sizeof(struct ethhdr));
917 if (!bat_priv->my_vis_info->skb_packet) 915 if (!bat_priv->my_vis_info->skb_packet)
918 goto free_info; 916 goto free_info;
919 917
920 skb_reserve(bat_priv->my_vis_info->skb_packet, sizeof(struct ethhdr)); 918 skb_reserve(bat_priv->my_vis_info->skb_packet, sizeof(struct ethhdr));
921 packet = (struct vis_packet *)skb_put( 919 packet = (struct vis_packet *)skb_put(bat_priv->my_vis_info->skb_packet,
922 bat_priv->my_vis_info->skb_packet, 920 sizeof(*packet));
923 sizeof(struct vis_packet));
924 921
925 /* prefill the vis info */ 922 /* prefill the vis info */
926 bat_priv->my_vis_info->first_seen = jiffies - 923 bat_priv->my_vis_info->first_seen = jiffies -