diff options
author | Simon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de> | 2011-10-22 12:15:26 -0400 |
---|---|---|
committer | Sven Eckelmann <sven@narfation.org> | 2011-11-20 07:08:33 -0500 |
commit | d099c2c541f003bfde9a9eda5519913b313c4c27 (patch) | |
tree | 1cee26067baf32ccebf12b5ff6b93698d3e1e363 /net/batman-adv/translation-table.c | |
parent | c90681b8505946761b55d4981c9c3b56b3c4171b (diff) |
batman-adv: directly write tt entries without buffering
When the translation tables (global and local) are written for debugfs,
it is not neccesary to allocate a buffer, we can directly use
seq_printf() to print them out.
This might actually be safer if the table changes between size
calculation and traversal, and we can't estimate the required size
wrong.
Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Diffstat (limited to 'net/batman-adv/translation-table.c')
-rw-r--r-- | net/batman-adv/translation-table.c | 57 |
1 files changed, 2 insertions, 55 deletions
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 5f28a7f0b03e..78b9528bfc2a 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c | |||
@@ -314,8 +314,6 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset) | |||
314 | struct hard_iface *primary_if; | 314 | struct hard_iface *primary_if; |
315 | struct hlist_node *node; | 315 | struct hlist_node *node; |
316 | struct hlist_head *head; | 316 | struct hlist_head *head; |
317 | size_t buf_size, pos; | ||
318 | char *buff; | ||
319 | uint32_t i; | 317 | uint32_t i; |
320 | int ret = 0; | 318 | int ret = 0; |
321 | 319 | ||
@@ -338,34 +336,13 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset) | |||
338 | "announced via TT (TTVN: %u):\n", | 336 | "announced via TT (TTVN: %u):\n", |
339 | net_dev->name, (uint8_t)atomic_read(&bat_priv->ttvn)); | 337 | net_dev->name, (uint8_t)atomic_read(&bat_priv->ttvn)); |
340 | 338 | ||
341 | buf_size = 1; | ||
342 | /* Estimate length for: " * xx:xx:xx:xx:xx:xx\n" */ | ||
343 | for (i = 0; i < hash->size; i++) { | ||
344 | head = &hash->table[i]; | ||
345 | |||
346 | rcu_read_lock(); | ||
347 | __hlist_for_each_rcu(node, head) | ||
348 | buf_size += 29; | ||
349 | rcu_read_unlock(); | ||
350 | } | ||
351 | |||
352 | buff = kmalloc(buf_size, GFP_ATOMIC); | ||
353 | if (!buff) { | ||
354 | ret = -ENOMEM; | ||
355 | goto out; | ||
356 | } | ||
357 | |||
358 | buff[0] = '\0'; | ||
359 | pos = 0; | ||
360 | |||
361 | for (i = 0; i < hash->size; i++) { | 339 | for (i = 0; i < hash->size; i++) { |
362 | head = &hash->table[i]; | 340 | head = &hash->table[i]; |
363 | 341 | ||
364 | rcu_read_lock(); | 342 | rcu_read_lock(); |
365 | hlist_for_each_entry_rcu(tt_local_entry, node, | 343 | hlist_for_each_entry_rcu(tt_local_entry, node, |
366 | head, hash_entry) { | 344 | head, hash_entry) { |
367 | pos += snprintf(buff + pos, 30, " * %pM " | 345 | seq_printf(seq, " * %pM [%c%c%c%c%c]\n", |
368 | "[%c%c%c%c%c]\n", | ||
369 | tt_local_entry->addr, | 346 | tt_local_entry->addr, |
370 | (tt_local_entry->flags & | 347 | (tt_local_entry->flags & |
371 | TT_CLIENT_ROAM ? 'R' : '.'), | 348 | TT_CLIENT_ROAM ? 'R' : '.'), |
@@ -380,9 +357,6 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset) | |||
380 | } | 357 | } |
381 | rcu_read_unlock(); | 358 | rcu_read_unlock(); |
382 | } | 359 | } |
383 | |||
384 | seq_printf(seq, "%s", buff); | ||
385 | kfree(buff); | ||
386 | out: | 360 | out: |
387 | if (primary_if) | 361 | if (primary_if) |
388 | hardif_free_ref(primary_if); | 362 | hardif_free_ref(primary_if); |
@@ -591,8 +565,6 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset) | |||
591 | struct hard_iface *primary_if; | 565 | struct hard_iface *primary_if; |
592 | struct hlist_node *node; | 566 | struct hlist_node *node; |
593 | struct hlist_head *head; | 567 | struct hlist_head *head; |
594 | size_t buf_size, pos; | ||
595 | char *buff; | ||
596 | uint32_t i; | 568 | uint32_t i; |
597 | int ret = 0; | 569 | int ret = 0; |
598 | 570 | ||
@@ -617,35 +589,13 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset) | |||
617 | seq_printf(seq, " %-13s %s %-15s %s %s\n", | 589 | seq_printf(seq, " %-13s %s %-15s %s %s\n", |
618 | "Client", "(TTVN)", "Originator", "(Curr TTVN)", "Flags"); | 590 | "Client", "(TTVN)", "Originator", "(Curr TTVN)", "Flags"); |
619 | 591 | ||
620 | buf_size = 1; | ||
621 | /* Estimate length for: " * xx:xx:xx:xx:xx:xx (ttvn) via | ||
622 | * xx:xx:xx:xx:xx:xx (cur_ttvn)\n"*/ | ||
623 | for (i = 0; i < hash->size; i++) { | ||
624 | head = &hash->table[i]; | ||
625 | |||
626 | rcu_read_lock(); | ||
627 | __hlist_for_each_rcu(node, head) | ||
628 | buf_size += 67; | ||
629 | rcu_read_unlock(); | ||
630 | } | ||
631 | |||
632 | buff = kmalloc(buf_size, GFP_ATOMIC); | ||
633 | if (!buff) { | ||
634 | ret = -ENOMEM; | ||
635 | goto out; | ||
636 | } | ||
637 | |||
638 | buff[0] = '\0'; | ||
639 | pos = 0; | ||
640 | |||
641 | for (i = 0; i < hash->size; i++) { | 592 | for (i = 0; i < hash->size; i++) { |
642 | head = &hash->table[i]; | 593 | head = &hash->table[i]; |
643 | 594 | ||
644 | rcu_read_lock(); | 595 | rcu_read_lock(); |
645 | hlist_for_each_entry_rcu(tt_global_entry, node, | 596 | hlist_for_each_entry_rcu(tt_global_entry, node, |
646 | head, hash_entry) { | 597 | head, hash_entry) { |
647 | pos += snprintf(buff + pos, 69, | 598 | seq_printf(seq, " * %pM (%3u) via %pM (%3u) " |
648 | " * %pM (%3u) via %pM (%3u) " | ||
649 | "[%c%c%c]\n", tt_global_entry->addr, | 599 | "[%c%c%c]\n", tt_global_entry->addr, |
650 | tt_global_entry->ttvn, | 600 | tt_global_entry->ttvn, |
651 | tt_global_entry->orig_node->orig, | 601 | tt_global_entry->orig_node->orig, |
@@ -661,9 +611,6 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset) | |||
661 | } | 611 | } |
662 | rcu_read_unlock(); | 612 | rcu_read_unlock(); |
663 | } | 613 | } |
664 | |||
665 | seq_printf(seq, "%s", buff); | ||
666 | kfree(buff); | ||
667 | out: | 614 | out: |
668 | if (primary_if) | 615 | if (primary_if) |
669 | hardif_free_ref(primary_if); | 616 | hardif_free_ref(primary_if); |