diff mbox

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

Message ID 1449129236-5038-6-git-send-email-joe@ovn.org
State Accepted
Headers show

Commit Message

Joe Stringer Dec. 3, 2015, 7:53 a.m. UTC
From: Joe Stringer <joestringer@nicira.com>

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 da1d39704c7b..090712e356df 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -381,6 +381,7 @@  AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
                   [OVS_DEFINE([HAVE_NF_CT_TMPL_ALLOC_TAKES_STRUCT_ZONE])])
 
   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