aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp
diff options
context:
space:
mode:
authorGerrit Renker <gerrit@erg.abdn.ac.uk>2006-12-09 21:02:51 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-12-11 17:34:43 -0500
commitb9039a2a8df974d7702564318722434bb276a995 (patch)
treeee67d87ec5b6e0a7f3100f63c31050270593146d /net/dccp
parent1a21e49a8d60f588c1276f765198b14d5688a778 (diff)
[DCCP] ccid3: Replace scaled division operations
This replaces the remaining uses of usecs_div with scaled_div32, which internally uses 64bit division and produces a warning on overflow. Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk> Acked-by: Ian McDonald <ian.mcdonald@jandi.co.nz> Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Diffstat (limited to 'net/dccp')
-rw-r--r--net/dccp/ccids/ccid3.c27
1 files changed, 3 insertions, 24 deletions
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index aa355d4cfc8a..bdd13de4f422 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -41,27 +41,6 @@
41#include "lib/tfrc.h" 41#include "lib/tfrc.h"
42#include "ccid3.h" 42#include "ccid3.h"
43 43
44/*
45 * Reason for maths here is to avoid 32 bit overflow when a is big.
46 * With this we get close to the limit.
47 */
48static u32 usecs_div(const u32 a, const u32 b)
49{
50 const u32 div = a < (UINT_MAX / (USEC_PER_SEC / 10)) ? 10 :
51 a < (UINT_MAX / (USEC_PER_SEC / 50)) ? 50 :
52 a < (UINT_MAX / (USEC_PER_SEC / 100)) ? 100 :
53 a < (UINT_MAX / (USEC_PER_SEC / 500)) ? 500 :
54 a < (UINT_MAX / (USEC_PER_SEC / 1000)) ? 1000 :
55 a < (UINT_MAX / (USEC_PER_SEC / 5000)) ? 5000 :
56 a < (UINT_MAX / (USEC_PER_SEC / 10000)) ? 10000 :
57 a < (UINT_MAX / (USEC_PER_SEC / 50000)) ? 50000 :
58 100000;
59 const u32 tmp = a * (USEC_PER_SEC / div);
60 return (b >= 2 * div) ? tmp / (b / div) : tmp;
61}
62
63
64
65#ifdef CONFIG_IP_DCCP_CCID3_DEBUG 44#ifdef CONFIG_IP_DCCP_CCID3_DEBUG
66static int ccid3_debug; 45static int ccid3_debug;
67#define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a) 46#define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
@@ -731,8 +710,8 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
731 case TFRC_RSTATE_DATA: { 710 case TFRC_RSTATE_DATA: {
732 const u32 delta = timeval_delta(&now, 711 const u32 delta = timeval_delta(&now,
733 &hcrx->ccid3hcrx_tstamp_last_feedback); 712 &hcrx->ccid3hcrx_tstamp_last_feedback);
734 hcrx->ccid3hcrx_x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, 713 hcrx->ccid3hcrx_x_recv =
735 delta); 714 scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta);
736 } 715 }
737 break; 716 break;
738 case TFRC_RSTATE_TERM: 717 case TFRC_RSTATE_TERM:
@@ -862,7 +841,7 @@ found:
862 841
863 dccp_timestamp(sk, &tstamp); 842 dccp_timestamp(sk, &tstamp);
864 delta = timeval_delta(&tstamp, &hcrx->ccid3hcrx_tstamp_last_feedback); 843 delta = timeval_delta(&tstamp, &hcrx->ccid3hcrx_tstamp_last_feedback);
865 x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, delta); 844 x_recv = scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta);
866 845
867 if (x_recv == 0) 846 if (x_recv == 0)
868 x_recv = hcrx->ccid3hcrx_x_recv; 847 x_recv = hcrx->ccid3hcrx_x_recv;