netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antonio Quartulli <antonio@meshcoding.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	Antonio Quartulli <antonio@open-mesh.com>,
	Marek Lindner <lindner_marek@yahoo.de>
Subject: [PATCH 14/16] batman-adv: implement batadv_tt_entries
Date: Sun, 13 Oct 2013 13:22:59 +0200	[thread overview]
Message-ID: <1381663381-626-15-git-send-email-antonio@meshcoding.com> (raw)
In-Reply-To: <1381663381-626-1-git-send-email-antonio@meshcoding.com>

From: Antonio Quartulli <antonio@open-mesh.com>

Implement batadv_tt_entries() to get the number of entries
fitting in a given amount of bytes. This computation is done
several times in the code and therefore it is useful to have
an helper function.

Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 net/batman-adv/translation-table.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 34fa6cc..58636a7 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -232,6 +232,17 @@ static int batadv_tt_len(int changes_num)
 	return changes_num * sizeof(struct batadv_tvlv_tt_change);
 }
 
+/**
+ * batadv_tt_entries - compute the number of entries fitting in tt_len bytes
+ * @tt_len: available space
+ *
+ * Returns the number of entries.
+ */
+static uint16_t batadv_tt_entries(uint16_t tt_len)
+{
+	return tt_len / batadv_tt_len(1);
+}
+
 static int batadv_tt_local_init(struct batadv_priv *bat_priv)
 {
 	if (bat_priv->tt.local_hash)
@@ -406,7 +417,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
 	if (tt_diff_len == 0)
 		goto container_register;
 
-	tt_diff_entries_num = tt_diff_len / batadv_tt_len(1);
+	tt_diff_entries_num = batadv_tt_entries(tt_diff_len);
 
 	spin_lock_bh(&bat_priv->tt.changes_list_lock);
 	atomic_set(&bat_priv->tt.local_changes, 0);
@@ -1616,7 +1627,7 @@ batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
 		tt_len -= tt_len % sizeof(struct batadv_tvlv_tt_change);
 	}
 
-	tt_tot = tt_len / sizeof(struct batadv_tvlv_tt_change);
+	tt_tot = batadv_tt_entries(tt_len);
 
 	tvlv_tt_data = kzalloc(sizeof(*tvlv_tt_data) + tt_len,
 			       GFP_ATOMIC);
@@ -2567,7 +2578,7 @@ static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
 	tt_data = (struct batadv_tvlv_tt_data *)tvlv_value;
 	tvlv_value_len -= sizeof(*tt_data);
 
-	num_entries = tvlv_value_len / batadv_tt_len(1);
+	num_entries = batadv_tt_entries(tvlv_value_len);
 
 	batadv_tt_update_orig(bat_priv, orig,
 			      (unsigned char *)(tt_data + 1),
@@ -2602,7 +2613,7 @@ static int batadv_tt_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv,
 	tt_data = (struct batadv_tvlv_tt_data *)tvlv_value;
 	tvlv_value_len -= sizeof(*tt_data);
 
-	num_entries = tvlv_value_len / batadv_tt_len(1);
+	num_entries = batadv_tt_entries(tvlv_value_len);
 
 	switch (tt_data->flags & BATADV_TT_DATA_TYPE_MASK) {
 	case BATADV_TT_REQUEST:
-- 
1.8.3.2

  parent reply	other threads:[~2013-10-13 11:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-13 11:22 pull request: batman-adv 2013-10-13 Antonio Quartulli
     [not found] ` <1381663381-626-1-git-send-email-antonio-x4xJYDvStAgysxA8WJXlww@public.gmane.org>
2013-10-13 11:22   ` [PATCH 01/16] batman-adv: only add recordroute information to icmp request/reply Antonio Quartulli
2013-10-13 11:22 ` [PATCH 02/16] batman-adv: make tt_global_add static and return bool Antonio Quartulli
2013-10-13 11:22 ` [PATCH 03/16] batman-adv: remove batadv_tt_global_add_orig declaration Antonio Quartulli
2013-10-13 11:22 ` [PATCH 04/16] batman-adv: don't use call_rcu if not needed Antonio Quartulli
2013-10-13 11:22 ` [PATCH 05/16] batman-adv: h_vlan_encapsulated_proto access refactoring Antonio Quartulli
2013-10-13 11:22 ` [PATCH 06/16] batman-adv: use VLAN_ETH_HLEN instead of sizeof(struct vlan_eth_hdr) Antonio Quartulli
2013-10-13 11:22 ` [PATCH 07/16] batman-adv: Remove old fragmentation code Antonio Quartulli
2013-10-13 11:22 ` [PATCH 08/16] batman-adv: Receive fragmented packets and merge Antonio Quartulli
2013-10-13 11:22 ` [PATCH 09/16] batman-adv: Fragment and send skbs larger than mtu Antonio Quartulli
2013-10-13 11:22 ` [PATCH 10/16] batman-adv: use htons when possible Antonio Quartulli
2013-10-13 11:22 ` [PATCH 11/16] batman-adv: create common header for ICMP packets Antonio Quartulli
2013-10-13 11:22 ` [PATCH 12/16] batman-adv: consider network coding overhead when calculating required mtu Antonio Quartulli
2013-10-13 11:22 ` [PATCH 13/16] batman-adv: remove useless find_router look up Antonio Quartulli
2013-10-13 11:22 ` Antonio Quartulli [this message]
2013-10-13 11:23 ` [PATCH 15/16] batman-adv: make batadv_tt_save_orig_buffer() generic Antonio Quartulli
2013-10-13 11:23 ` [PATCH 16/16] batman-adv: Add dummy soft-interface rx mode handler Antonio Quartulli
2013-10-17 18:27 ` pull request: batman-adv 2013-10-13 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=1381663381-626-15-git-send-email-antonio@meshcoding.com \
    --to=antonio@meshcoding.com \
    --cc=antonio@open-mesh.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=lindner_marek@yahoo.de \
    --cc=netdev@vger.kernel.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).