aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/batman-adv/main.h16
-rw-r--r--net/batman-adv/vis.c16
2 files changed, 16 insertions, 16 deletions
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 0150897acf63..80be5ad4fc9c 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)
182 182
183#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) 183#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
184 184
185/* Returns the smallest signed integer in two's complement with the sizeof x */
186#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
187
188/* Checks if a sequence number x is a predecessor/successor of y.
189 * they handle overflows/underflows and can correctly check for a
190 * predecessor/successor unless the variable sequence number has grown by
191 * more then 2**(bitwidth(x)-1)-1.
192 * This means that for a uint8_t with the maximum value 255, it would think:
193 * - when adding nothing - it is neither a predecessor nor a successor
194 * - before adding more than 127 to the starting value - it is a predecessor,
195 * - when adding 128 - it is neither a predecessor nor a successor,
196 * - after adding more than 127 to the starting value - it is a successor */
197#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \
198 _dummy > smallest_signed_int(_dummy); })
199#define seq_after(x, y) seq_before(y, x)
200
185#endif /* _NET_BATMAN_ADV_MAIN_H_ */ 201#endif /* _NET_BATMAN_ADV_MAIN_H_ */
diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c
index ea8d7e91fcac..355c6e590b0c 100644
--- a/net/batman-adv/vis.c
+++ b/net/batman-adv/vis.c
@@ -30,22 +30,6 @@
30 30
31#define MAX_VIS_PACKET_SIZE 1000 31#define MAX_VIS_PACKET_SIZE 1000
32 32
33/* Returns the smallest signed integer in two's complement with the sizeof x */
34#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
35
36/* Checks if a sequence number x is a predecessor/successor of y.
37 * they handle overflows/underflows and can correctly check for a
38 * predecessor/successor unless the variable sequence number has grown by
39 * more then 2**(bitwidth(x)-1)-1.
40 * This means that for a uint8_t with the maximum value 255, it would think:
41 * - when adding nothing - it is neither a predecessor nor a successor
42 * - before adding more than 127 to the starting value - it is a predecessor,
43 * - when adding 128 - it is neither a predecessor nor a successor,
44 * - after adding more than 127 to the starting value - it is a successor */
45#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \
46 _dummy > smallest_signed_int(_dummy); })
47#define seq_after(x, y) seq_before(y, x)
48
49static void start_vis_timer(struct bat_priv *bat_priv); 33static void start_vis_timer(struct bat_priv *bat_priv);
50 34
51/* free the info */ 35/* free the info */