batman-adv: Avoid rounding issues for local hna timeout

Message ID 1276961074-3223-1-git-send-email-linus.luessing@web.de
State Accepted, archived
Commit 5f3dc043deb23802cf88d7facfc346097347c890
Headers

Commit Message

Linus Lüssing June 19, 2010, 3:24 p.m. UTC
  With the current default values, this patch is not critical, as
LOCAL_HNA_TIMEOUT is a multiple of 1000 anyway. However, if someone
would like to change this #define, the person could have some
unexpected rounding issues. Therefore doing the multiplication before
the division now.

Signed-off-by: Linus Lüssing <linus.luessing@web.de>
---
 translation-table.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
  

Comments

Simon Wunderlich June 19, 2010, 10:23 p.m. UTC | #1
Hey Linus,

thanks, applied in r1710.

Cheers,
	Simon

On Sat, Jun 19, 2010 at 05:24:34PM +0200, Linus Lüssing wrote:
> With the current default values, this patch is not critical, as
> LOCAL_HNA_TIMEOUT is a multiple of 1000 anyway. However, if someone
> would like to change this #define, the person could have some
> unexpected rounding issues. Therefore doing the multiplication before
> the division now.
> 
> Signed-off-by: Linus Lüssing <linus.luessing@web.de>
> ---
>  translation-table.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/translation-table.c b/translation-table.c
> index 619a9a8..cf37cc4 100644
> --- a/translation-table.c
> +++ b/translation-table.c
> @@ -259,7 +259,7 @@ static void hna_local_purge(struct work_struct *work)
>  		hna_local_entry = hashit.bucket->data;
>  
>  		timeout = hna_local_entry->last_seen +
> -			((LOCAL_HNA_TIMEOUT / 1000) * HZ);
> +			((LOCAL_HNA_TIMEOUT * HZ) / 1000);
>  		if ((!hna_local_entry->never_purge) &&
>  		    time_after(jiffies, timeout))
>  			hna_local_del(hna_local_entry, "address timed out");
> -- 
> 1.7.1
> 
>
  

Patch

diff --git a/translation-table.c b/translation-table.c
index 619a9a8..cf37cc4 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -259,7 +259,7 @@  static void hna_local_purge(struct work_struct *work)
 		hna_local_entry = hashit.bucket->data;
 
 		timeout = hna_local_entry->last_seen +
-			((LOCAL_HNA_TIMEOUT / 1000) * HZ);
+			((LOCAL_HNA_TIMEOUT * HZ) / 1000);
 		if ((!hna_local_entry->never_purge) &&
 		    time_after(jiffies, timeout))
 			hna_local_del(hna_local_entry, "address timed out");