diff mbox

[ovs-dev,05/23] compat: Backport prandom_u32_max().

Message ID 1446926401-55723-6-git-send-email-joestringer@nicira.com
State Superseded
Headers show

Commit Message

Joe Stringer Nov. 7, 2015, 7:59 p.m. UTC
Signed-off-by: Joe Stringer <joestringer@nicira.com>
---
 acinclude.m4                                 | 1 +
 datapath/linux/compat/include/linux/random.h | 7 +++++++
 2 files changed, 8 insertions(+)
diff mbox

Patch

diff --git a/acinclude.m4 b/acinclude.m4
index 9465adb1daab..cb3326227f82 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -375,6 +375,7 @@  AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
                   [OVS_DEFINE([HAVE_NF_HOOKFN_ARG_OPS])])
 
   OVS_GREP_IFELSE([$KSRC/include/linux/random.h], [prandom_u32])
+  OVS_GREP_IFELSE([$KSRC/include/linux/random.h], [prandom_u32_max])
 
   OVS_GREP_IFELSE([$KSRC/include/net/rtnetlink.h], [get_link_net])
   OVS_GREP_IFELSE([$KSRC/include/net/rtnetlink.h], [name_assign_type])
diff --git a/datapath/linux/compat/include/linux/random.h b/datapath/linux/compat/include/linux/random.h
index f2a6d6aa1468..5c088a2d860b 100644
--- a/datapath/linux/compat/include/linux/random.h
+++ b/datapath/linux/compat/include/linux/random.h
@@ -7,4 +7,11 @@ 
 #define prandom_u32()		random32()
 #endif
 
+#ifndef HAVE_PRANDOM_U32_MAX
+static inline u32 prandom_u32_max(u32 ep_ro)
+{
+	return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
+}
+#endif
+
 #endif