From a108c38271f13a2d2252042ba2a732e1735fd1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20L=C3=BCssing?= Date: Mon, 22 Mar 2010 22:46:15 +0100 Subject: [PATCH] --- yaml --- r: 197167 b: refs/heads/master c: ea4ceb18b525fd7016c10995c0f1313a729c7e2b h: refs/heads/master i: 197165: 7bb263ba484b846c075f83d65f5627d4a2a049dc 197163: edcc2f0702780c6497a858e3fa71e774949d46b2 197159: 9ac5451abf29866ff411f1aceb6327918edc8a03 197151: c12216232bb47bc593ad94791fbde6e4677425b9 v: v3 --- [refs] | 2 +- trunk/drivers/staging/batman-adv/vis.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index cd6efb4990f1..068b110b9e63 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: f6497e38fda6970819daacb67725d67474079381 +refs/heads/master: ea4ceb18b525fd7016c10995c0f1313a729c7e2b diff --git a/trunk/drivers/staging/batman-adv/vis.c b/trunk/drivers/staging/batman-adv/vis.c index 222db0189a6d..28eac7e05235 100644 --- a/trunk/drivers/staging/batman-adv/vis.c +++ b/trunk/drivers/staging/batman-adv/vis.c @@ -27,6 +27,22 @@ #include "hard-interface.h" #include "hash.h" +/* 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) + struct hashtable_t *vis_hash; DEFINE_SPINLOCK(vis_hash_lock); static DEFINE_SPINLOCK(recv_list_lock); @@ -212,7 +228,7 @@ static struct vis_info *add_packet(struct vis_packet *vis_packet, old_info = hash_find(vis_hash, &search_elem); if (old_info != NULL) { - if (vis_packet->seqno - old_info->packet.seqno <= 0) { + if (!seq_after(vis_packet->seqno, old_info->packet.seqno)) { if (old_info->packet.seqno == vis_packet->seqno) { recv_list_add(&old_info->recv_list, vis_packet->sender_orig);