]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
selftests: vm: remove dependecy from internal kernel macros
authorMuhammad Usama Anjum <usama.anjum@collabora.com>
Wed, 19 Jan 2022 10:15:31 +0000 (15:15 +0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 11:57:49 +0000 (13:57 +0200)
[ Upstream commit 681696862bc1823595c05960a83766d1aa965c17 ]

The defination of swap() is used from kernel's internal header when this
test is built in source tree. The build fails when this test is built
out of source tree as defination of swap() isn't found. Selftests
shouldn't depend on kernel's internal header files. They can only depend
on uapi header files. Add the defination of swap() to fix the build
error:

gcc -Wall  -I/linux_mainline2/build/usr/include -no-pie    userfaultfd.c -lrt -lpthread -o /linux_mainline2/build/kselftest/vm/userfaultfd
userfaultfd.c: In function ‘userfaultfd_stress’:
userfaultfd.c:1530:3: warning: implicit declaration of function ‘swap’; did you mean ‘swab’? [-Wimplicit-function-declaration]
 1530 |   swap(area_src, area_dst);
      |   ^~~~
      |   swab
/usr/bin/ld: /tmp/cclUUH7V.o: in function `userfaultfd_stress':
userfaultfd.c:(.text+0x4d64): undefined reference to `swap'
/usr/bin/ld: userfaultfd.c:(.text+0x4d82): undefined reference to `swap'
collect2: error: ld returned 1 exit status

Fixes: 2c769ed7137a ("tools/testing/selftests/vm/userfaultfd.c: use swap() to make code cleaner")
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/vm/userfaultfd.c

index 3fc1d2ee294859fcc3b6c587b4a22182725686f4..c964bfe9fbcda8360a9a19b1200f1a48b5ac3994 100644 (file)
@@ -120,6 +120,9 @@ struct uffd_stats {
                                 ~(unsigned long)(sizeof(unsigned long long) \
                                                  -  1)))
 
+#define swap(a, b) \
+       do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
+
 const char *examples =
     "# Run anonymous memory test on 100MiB region with 99999 bounces:\n"
     "./userfaultfd anon 100 99999\n\n"