Don't hard-code x86 specific names, use vdso_config definitions
to find the correct function matching the architecture.

Add random VDSO function names in names[][]. Remove the #ifdef
CONFIG_VDSO32, having the name there all the time is harmless
and guaranties a steady index for following strings.

Signed-off-by: Christophe Leroy <christophe.le...@csgroup.eu>
---
 tools/testing/selftests/vDSO/vdso_config.h         | 8 +++-----
 tools/testing/selftests/vDSO/vdso_test_getrandom.c | 8 ++++++--
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/vDSO/vdso_config.h 
b/tools/testing/selftests/vDSO/vdso_config.h
index 00bfed6e4922..740ce8c98d2e 100644
--- a/tools/testing/selftests/vDSO/vdso_config.h
+++ b/tools/testing/selftests/vDSO/vdso_config.h
@@ -68,16 +68,15 @@ static const char *versions[7] = {
        "LINUX_5.10"
 };
 
-static const char *names[2][6] = {
+static const char *names[2][7] = {
        {
                "__kernel_gettimeofday",
                "__kernel_clock_gettime",
                "__kernel_time",
                "__kernel_clock_getres",
                "__kernel_getcpu",
-#if defined(VDSO_32BIT)
                "__kernel_clock_gettime64",
-#endif
+               "__kernel_getrandom",
        },
        {
                "__vdso_gettimeofday",
@@ -85,9 +84,8 @@ static const char *names[2][6] = {
                "__vdso_time",
                "__vdso_clock_getres",
                "__vdso_getcpu",
-#if defined(VDSO_32BIT)
                "__vdso_clock_gettime64",
-#endif
+               "__vdso_getrandom",
        },
 };
 
diff --git a/tools/testing/selftests/vDSO/vdso_test_getrandom.c 
b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
index 05122425a873..02bcffc23e0c 100644
--- a/tools/testing/selftests/vDSO/vdso_test_getrandom.c
+++ b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
@@ -21,6 +21,7 @@
 
 #include "../kselftest.h"
 #include "parse_vdso.h"
+#include "vdso_config.h"
 
 #ifndef timespecsub
 #define        timespecsub(tsp, usp, vsp)                                      
\
@@ -107,6 +108,9 @@ static void vgetrandom_put_state(void *state)
 
 static void vgetrandom_init(void)
 {
+       const char *version = versions[VDSO_VERSION];
+       const char **name = (const char **)&names[VDSO_NAMES];
+
        if (pthread_key_create(&grnd_ctx.key, vgetrandom_put_state) != 0)
                return;
        unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
@@ -115,9 +119,9 @@ static void vgetrandom_init(void)
                exit(KSFT_SKIP);
        }
        vdso_init_from_sysinfo_ehdr(sysinfo_ehdr);
-       grnd_ctx.fn = (__typeof__(grnd_ctx.fn))vdso_sym("LINUX_2.6", 
"__vdso_getrandom");
+       grnd_ctx.fn = (__typeof__(grnd_ctx.fn))vdso_sym(version, name[6]);
        if (!grnd_ctx.fn) {
-               printf("__vdso_getrandom is missing!\n");
+               printf("%s is missing!\n", name[6]);
                exit(KSFT_FAIL);
        }
        if (grnd_ctx.fn(NULL, 0, 0, &grnd_ctx.params, ~0UL) != 0) {
-- 
2.44.0


Reply via email to