Skip to content

Commit 6e37326

Browse files
Ram Paitorvalds
authored andcommitted
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: Ram Pai <[email protected]> Signed-off-by: Sandipan Das <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Dave Hansen <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Florian Weimer <[email protected]> Cc: "Desnes A. Nunes do Rosario" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thiago Jung Bauermann <[email protected]> Cc: "Aneesh Kumar K.V" <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Michal Suchanek <[email protected]> Cc: Shuah Khan <[email protected]> Link: http://lkml.kernel.org/r/0162f55816d4e783a0d6e49e554d0ab9a3c9a23b.1585646528.git.sandipan@linux.ibm.com Signed-off-by: Linus Torvalds <[email protected]>
1 parent ea5f95c commit 6e37326

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tools/testing/selftests/vm/protection_keys.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define __SANE_USERSPACE_TYPES__
2626
#include <errno.h>
2727
#include <linux/futex.h>
28+
#include <time.h>
2829
#include <sys/time.h>
2930
#include <sys/syscall.h>
3031
#include <string.h>
@@ -546,10 +547,10 @@ int alloc_random_pkey(void)
546547
int nr_alloced = 0;
547548
int random_index;
548549
memset(alloced_pkeys, 0, sizeof(alloced_pkeys));
550+
srand((unsigned int)time(NULL));
549551

550552
/* allocate every possible key and make a note of which ones we got */
551553
max_nr_pkey_allocs = NR_PKEYS;
552-
max_nr_pkey_allocs = 1;
553554
for (i = 0; i < max_nr_pkey_allocs; i++) {
554555
int new_pkey = alloc_pkey();
555556
if (new_pkey < 0)

0 commit comments

Comments
 (0)