[PATCH v2] netfilter: xt_hashlimit: Fix link error in 32bit arch because of 64bit division

Subsystems: netfilter, networking [general], the rest

STALE3676d

2 messages, 2 authors, 2016-09-28 · open the first message on its own page

[PATCH v2] netfilter: xt_hashlimit: Fix link error in 32bit arch because of 64bit division

From: Vishwanath Pai <hidden>
Date: 2016-09-27 13:57:18

v2:
Remove unnecessary div64_u64 around constants

--

Fix link error in 32bit arch because of 64bit division

Division of 64bit integers will cause linker error undefined reference
to `__udivdi3'. Fix this by replacing divisions with div64_64

Signed-off-by: Vishwanath Pai <redacted>

---
 net/netfilter/xt_hashlimit.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 44a095e..200a9d8 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -467,17 +467,18 @@ static u64 user2credits(u64 user, int revision)
 		/* If multiplying would overflow... */
 		if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY_v1))
 			/* Divide first. */
-			return (user / XT_HASHLIMIT_SCALE) *\
+			return div64_u64(user, XT_HASHLIMIT_SCALE) *\
 						HZ * CREDITS_PER_JIFFY_v1;
 
-		return (user * HZ * CREDITS_PER_JIFFY_v1) \
-						/ XT_HASHLIMIT_SCALE;
+		return div64_u64((user * HZ * CREDITS_PER_JIFFY_v1),
+				  XT_HASHLIMIT_SCALE);
 	} else {
 		if (user > 0xFFFFFFFFFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
-			return (user / XT_HASHLIMIT_SCALE_v2) *\
+			return div64_u64(user, XT_HASHLIMIT_SCALE_v2) *\
 						HZ * CREDITS_PER_JIFFY;
 
-		return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE_v2;
+		return div64_u64((user * HZ * CREDITS_PER_JIFFY),
+				 XT_HASHLIMIT_SCALE_v2);
 	}
 }
 
-- 
1.9.1

Re: [PATCH v2] netfilter: xt_hashlimit: Fix link error in 32bit arch because of 64bit division

From: Maciej Żenczykowski <hidden>
Date: 2016-09-28 02:32:02

I don't think you actually need the backslashes since this ain't in a
MACRO definition context.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help