From patchwork Sat Nov 26 14:26:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 127807 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 960DD1007D7 for ; Sun, 27 Nov 2011 01:30:10 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752478Ab1KZOaF (ORCPT ); Sat, 26 Nov 2011 09:30:05 -0500 Received: from nm2.bullet.mail.ukl.yahoo.com ([217.146.183.219]:32259 "HELO nm2.bullet.mail.ukl.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751858Ab1KZOaD (ORCPT ); Sat, 26 Nov 2011 09:30:03 -0500 Received: from [217.146.183.183] by nm2.bullet.mail.ukl.yahoo.com with NNFMP; 26 Nov 2011 14:30:01 -0000 Received: from [77.238.184.77] by tm14.bullet.mail.ukl.yahoo.com with NNFMP; 26 Nov 2011 14:30:01 -0000 Received: from [127.0.0.1] by smtp146.mail.ukl.yahoo.com with NNFMP; 26 Nov 2011 14:30:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1322317801; bh=XEcBIeeK+rhOY2zlJ/bLcKfR0JeP/STjHijpVPCjEc8=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=6ihGmAHjlUAVz/CS/qYX1yyJifPZAUQI67SM83xAXF3ogxLYL9INpAcDxU+azl0Q871stbA4lS3a/7MyvNClh1mn0mPxgV30+ues4zIOMa4CazbOal/qkBXF/ToKcceHKtghSwB0nLrSPDBJoTTnDV4LP3KE/Sif6rkYrvqZSNU= X-Yahoo-Newman-Id: 513870.94664.bm@smtp146.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: Vs.7sl0VM1nMd7gC4PU_Azo7P_rltb0IipMrq1L7.PyQdGA _QK614TSG_JNdoaQkRPlCS7Qv9767fncAFXyspR1KPxWUJlL7xQ.Lfw6I0jh lH_8S7bUsKcF8V5Vdaj.gnHsiFNz.kCjKuO4uu2GZaM.hHUEyE09ht9VDnys MNCVIWPzBkfJLF8yGvTXKwB0uGZdMn7H1TOknbUDBb4pFsXPSV1oSsH6xXPL nMdHSnWLBCsbbPUy5_opoGe0hohcFs1ZuQEtv9ttZPhS3HJWyqnKP7jfFmn3 lNsZZKA6gpqhIwW8EIDhnny3.OcG_gmkUuFh74LQOvDvkG_1Vi_Mhu0WnRAq 69oRWdg6j2n5t4MYCUYf4RIohGV91pHJifzFsgTD_MHfhSRfKb6ii.hQ- X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@210.177.7.38 with plain) by smtp146.mail.ukl.yahoo.com with SMTP; 26 Nov 2011 14:29:58 +0000 GMT From: Marek Lindner To: davem@davemloft.net Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Simon Wunderlich , Simon Wunderlich , Sven Eckelmann Subject: [PATCH 07/10] batman-adv: directly write tt entries without buffering Date: Sat, 26 Nov 2011 22:26:49 +0800 Message-Id: <1322317612-7770-8-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1322317612-7770-1-git-send-email-lindner_marek@yahoo.de> References: <1322317612-7770-1-git-send-email-lindner_marek@yahoo.de> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Simon Wunderlich 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 Signed-off-by: Sven Eckelmann --- 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);