netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	Antonio Quartulli <ordex@autistici.org>,
	Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 13/17] batman-adv: move smallest_signed_int(), seq_before() and seq_after() into main.h
Date: Mon, 30 May 2011 09:22:58 +0200	[thread overview]
Message-ID: <1306740182-2665-14-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1306740182-2665-1-git-send-email-sven@narfation.org>

From: Antonio Quartulli <ordex@autistici.org>

smallest_signed_int(), seq_before() and seq_after() are very useful
functions that help to handle comparisons between sequence numbers.
However they were only defined in vis.c. With this patch every
batman-adv function will be able to use them.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 net/batman-adv/main.h |   16 ++++++++++++++++
 net/batman-adv/vis.c  |   16 ----------------
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 0150897a..80be5ad 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -182,4 +182,20 @@ static inline int compare_eth(const void *data1, const void *data2)
 
 #define atomic_dec_not_zero(v)	atomic_add_unless((v), -1, 0)
 
+/* Returns the smallest signed integer in two's complement with the sizeof x */
+#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
+
+/* Checks if a sequence number x is a predecessor/successor of y.
+ * they handle overflows/underflows and can correctly check for a
+ * predecessor/successor unless the variable sequence number has grown by
+ * more then 2**(bitwidth(x)-1)-1.
+ * This means that for a uint8_t with the maximum value 255, it would think:
+ *  - when adding nothing - it is neither a predecessor nor a successor
+ *  - before adding more than 127 to the starting value - it is a predecessor,
+ *  - when adding 128 - it is neither a predecessor nor a successor,
+ *  - after adding more than 127 to the starting value - it is a successor */
+#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \
+			_dummy > smallest_signed_int(_dummy); })
+#define seq_after(x, y) seq_before(y, x)
+
 #endif /* _NET_BATMAN_ADV_MAIN_H_ */
diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c
index ea8d7e9..355c6e5 100644
--- a/net/batman-adv/vis.c
+++ b/net/batman-adv/vis.c
@@ -30,22 +30,6 @@
 
 #define MAX_VIS_PACKET_SIZE 1000
 
-/* Returns the smallest signed integer in two's complement with the sizeof x */
-#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
-
-/* Checks if a sequence number x is a predecessor/successor of y.
- * they handle overflows/underflows and can correctly check for a
- * predecessor/successor unless the variable sequence number has grown by
- * more then 2**(bitwidth(x)-1)-1.
- * This means that for a uint8_t with the maximum value 255, it would think:
- *  - when adding nothing - it is neither a predecessor nor a successor
- *  - before adding more than 127 to the starting value - it is a predecessor,
- *  - when adding 128 - it is neither a predecessor nor a successor,
- *  - after adding more than 127 to the starting value - it is a successor */
-#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \
-			_dummy > smallest_signed_int(_dummy); })
-#define seq_after(x, y) seq_before(y, x)
-
 static void start_vis_timer(struct bat_priv *bat_priv);
 
 /* free the info */
-- 
1.7.5.3


  parent reply	other threads:[~2011-05-30  7:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-30  7:22 batman-adv 2011-05-30 Sven Eckelmann
     [not found] ` <1306740182-2665-1-git-send-email-sven-KaDOiPu9UxWEi8DpZVb4nw@public.gmane.org>
2011-05-30  7:22   ` [PATCH 01/17] batman-adv: move neigh_node->if_incoming->if_status check in find_router() Sven Eckelmann
2011-05-30  7:22   ` [PATCH 02/17] batman-adv: Use kzalloc rather than kmalloc followed by memset with 0 Sven Eckelmann
2011-05-30  7:22   ` [PATCH 03/17] batman-adv: Annotate functions with format strings Sven Eckelmann
2011-05-30  7:22   ` [PATCH 04/17] batman-adv: Print jiffies as unsigned long Sven Eckelmann
2011-05-30  7:22   ` [PATCH 05/17] batman-adv: Remove comparising < 0 for unsigned type Sven Eckelmann
2011-05-30  7:22   ` [PATCH 06/17] batman-adv: Don't do pointer arithmetic with void* Sven Eckelmann
2011-05-30  7:22   ` [PATCH 07/17] batman-adv: Add const type qualifier for pointers Sven Eckelmann
2011-05-30  7:22   ` [PATCH 08/17] batman-adv: Only use int up and down gw representation Sven Eckelmann
2011-05-30  7:22   ` [PATCH 09/17] batman-adv: Remove explicit casts cast from void* for store Sven Eckelmann
2011-05-30  7:22   ` [PATCH 10/17] batman-adv: Remove casts from type x to type x Sven Eckelmann
2011-06-01  3:52   ` batman-adv 2011-05-30 David Miller
2011-05-30  7:22 ` [PATCH 11/17] batman-adv: Calculate sizeof using variable insead of types Sven Eckelmann
2011-05-30  7:22 ` [PATCH 12/17] batman-adv: Use rcu_dereference_protected by update-side Sven Eckelmann
2011-05-30  7:22 ` Sven Eckelmann [this message]
2011-05-30  7:22 ` [PATCH 14/17] batman-adv: Check type of x and y in seq_(before|after) Sven Eckelmann
2011-05-30  7:23 ` [PATCH 15/17] batman-adv: use is_broadcast_ether_addr() instead of compare_eth(.., brd_addr) Sven Eckelmann
2011-05-30  7:23 ` [PATCH 16/17] batman-adv: a multiline comment should precede the variable it is describing Sven Eckelmann
2011-05-30  7:23 ` [PATCH 17/17] batman-adv: Ensure that we really have route changes in update_route Sven Eckelmann

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=1306740182-2665-14-git-send-email-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=ordex@autistici.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).