Commit 6e373263 authored by Ram Pai's avatar Ram Pai Committed by Linus Torvalds

selftests/vm/pkeys: fix alloc_random_pkey() to make it really random

alloc_random_pkey() was allocating the same pkey every time.  Not all
pkeys were geting tested.  This fixes it.
Signed-off-by: default avatarRam Pai <linuxram@us.ibm.com>
Signed-off-by: default avatarSandipan Das <sandipan@linux.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarDave Hansen <dave.hansen@intel.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: "Desnes A. Nunes do Rosario" <desnesn@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Suchanek <msuchanek@suse.de>
Cc: Shuah Khan <shuah@kernel.org>
Link: http://lkml.kernel.org/r/0162f55816d4e783a0d6e49e554d0ab9a3c9a23b.1585646528.git.sandipan@linux.ibm.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ea5f95c3
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define __SANE_USERSPACE_TYPES__ #define __SANE_USERSPACE_TYPES__
#include <errno.h> #include <errno.h>
#include <linux/futex.h> #include <linux/futex.h>
#include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <string.h> #include <string.h>
...@@ -546,10 +547,10 @@ int alloc_random_pkey(void) ...@@ -546,10 +547,10 @@ int alloc_random_pkey(void)
int nr_alloced = 0; int nr_alloced = 0;
int random_index; int random_index;
memset(alloced_pkeys, 0, sizeof(alloced_pkeys)); memset(alloced_pkeys, 0, sizeof(alloced_pkeys));
srand((unsigned int)time(NULL));
/* allocate every possible key and make a note of which ones we got */ /* allocate every possible key and make a note of which ones we got */
max_nr_pkey_allocs = NR_PKEYS; max_nr_pkey_allocs = NR_PKEYS;
max_nr_pkey_allocs = 1;
for (i = 0; i < max_nr_pkey_allocs; i++) { for (i = 0; i < max_nr_pkey_allocs; i++) {
int new_pkey = alloc_pkey(); int new_pkey = alloc_pkey();
if (new_pkey < 0) if (new_pkey < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment