From: Marek Lindner <lindner_marek@yahoo.de>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
Simon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de>,
Simon Wunderlich <siwu@hrz.tu-chemnitz.de>,
Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 07/10] batman-adv: directly write tt entries without buffering
Date: Sat, 26 Nov 2011 22:26:49 +0800 [thread overview]
Message-ID: <1322317612-7770-8-git-send-email-lindner_marek@yahoo.de> (raw)
In-Reply-To: <1322317612-7770-1-git-send-email-lindner_marek@yahoo.de>
From: Simon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de>
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>
---
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 5f28a7f0..78b9528 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)
struct hard_iface *primary_if;
struct hlist_node *node;
struct hlist_head *head;
- size_t buf_size, pos;
- char *buff;
uint32_t i;
int ret = 0;
@@ -338,34 +336,13 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset)
"announced via TT (TTVN: %u):\n",
net_dev->name, (uint8_t)atomic_read(&bat_priv->ttvn));
- buf_size = 1;
- /* Estimate length for: " * xx:xx:xx:xx:xx:xx\n" */
- for (i = 0; i < hash->size; i++) {
- head = &hash->table[i];
-
- rcu_read_lock();
- __hlist_for_each_rcu(node, head)
- buf_size += 29;
- rcu_read_unlock();
- }
-
- buff = kmalloc(buf_size, GFP_ATOMIC);
- if (!buff) {
- ret = -ENOMEM;
- goto out;
- }
-
- buff[0] = '\0';
- pos = 0;
-
for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
rcu_read_lock();
hlist_for_each_entry_rcu(tt_local_entry, node,
head, hash_entry) {
- pos += snprintf(buff + pos, 30, " * %pM "
- "[%c%c%c%c%c]\n",
+ seq_printf(seq, " * %pM [%c%c%c%c%c]\n",
tt_local_entry->addr,
(tt_local_entry->flags &
TT_CLIENT_ROAM ? 'R' : '.'),
@@ -380,9 +357,6 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset)
}
rcu_read_unlock();
}
-
- seq_printf(seq, "%s", buff);
- kfree(buff);
out:
if (primary_if)
hardif_free_ref(primary_if);
@@ -591,8 +565,6 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset)
struct hard_iface *primary_if;
struct hlist_node *node;
struct hlist_head *head;
- size_t buf_size, pos;
- char *buff;
uint32_t i;
int ret = 0;
@@ -617,35 +589,13 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset)
seq_printf(seq, " %-13s %s %-15s %s %s\n",
"Client", "(TTVN)", "Originator", "(Curr TTVN)", "Flags");
- buf_size = 1;
- /* Estimate length for: " * xx:xx:xx:xx:xx:xx (ttvn) via
- * xx:xx:xx:xx:xx:xx (cur_ttvn)\n"*/
- for (i = 0; i < hash->size; i++) {
- head = &hash->table[i];
-
- rcu_read_lock();
- __hlist_for_each_rcu(node, head)
- buf_size += 67;
- rcu_read_unlock();
- }
-
- buff = kmalloc(buf_size, GFP_ATOMIC);
- if (!buff) {
- ret = -ENOMEM;
- goto out;
- }
-
- buff[0] = '\0';
- pos = 0;
-
for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
rcu_read_lock();
hlist_for_each_entry_rcu(tt_global_entry, node,
head, hash_entry) {
- pos += snprintf(buff + pos, 69,
- " * %pM (%3u) via %pM (%3u) "
+ seq_printf(seq, " * %pM (%3u) via %pM (%3u) "
"[%c%c%c]\n", tt_global_entry->addr,
tt_global_entry->ttvn,
tt_global_entry->orig_node->orig,
@@ -661,9 +611,6 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset)
}
rcu_read_unlock();
}
-
- seq_printf(seq, "%s", buff);
- kfree(buff);
out:
if (primary_if)
hardif_free_ref(primary_if);
--
1.7.5.4
next prev parent reply other threads:[~2011-11-26 14:30 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-26 14:26 pull request: batman-adv 2011-11-26 Marek Lindner
2011-11-26 14:26 ` [PATCH 01/10] batman-adv: update internal version number Marek Lindner
2011-11-26 14:26 ` Marek Lindner [this message]
[not found] ` <1322317612-7770-1-git-send-email-lindner_marek-LWAfsSFWpa4@public.gmane.org>
2011-11-26 14:26 ` [PATCH 02/10] batman-adv: tt_global_del_orig() has to print the correct message Marek Lindner
2011-11-26 14:26 ` [PATCH 03/10] batman-adv: Replace obsolete strict_strto<foo> with kstrto<foo> Marek Lindner
2011-11-26 14:26 ` [PATCH 04/10] batman-adv: refactoring gateway handling code Marek Lindner
2011-11-26 14:26 ` [PATCH 05/10] batman-adv: use orig_hash_find() instead of get_orig_node() in TT code Marek Lindner
2011-11-26 14:26 ` [PATCH 06/10] batman-adv: fixed hash functions type to uint32_t instead of int Marek Lindner
2011-11-26 14:26 ` [PATCH 08/10] batman-adv: linearise the tt_response skb only if needed Marek Lindner
2011-11-26 14:26 ` [PATCH 09/10] batman-adv: check for tt_reponse packet real length Marek Lindner
2011-11-26 14:26 ` [PATCH 10/10] batman-adv: Fix range check for expected packets Marek Lindner
2011-11-26 19:41 ` pull request: batman-adv 2011-11-26 David Miller
[not found] ` <20111126.144122.775553783672941660.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-12-02 17:12 ` Antonio Quartulli
[not found] ` <20111202171216.GA4561-E/2OGukznS5g9hUCZPvPmw@public.gmane.org>
2011-12-02 17:57 ` David Miller
[not found] ` <20111202.125725.896787381527077500.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-12-03 1:55 ` Antonio Quartulli
[not found] ` <20111203015528.GB3148-E/2OGukznS5g9hUCZPvPmw@public.gmane.org>
2011-12-03 1:59 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1322317612-7770-8-git-send-email-lindner_marek@yahoo.de \
--to=lindner_marek@yahoo.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=simon.wunderlich@s2003.tu-chemnitz.de \
--cc=siwu@hrz.tu-chemnitz.de \
--cc=sven@narfation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).