diff options
-rw-r--r-- | net/dccp/ccids/ccid3.c | 27 |
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 | */ | ||
48 | static 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 |
66 | static int ccid3_debug; | 45 | static 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; |