Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: centralise maybe-unused definition in kselftest.h

Several selftests subdirectories duplicated the define __maybe_unused,
leading to redundant code. Move to kselftest.h header and remove other
definitions.

This addresses the duplication noted in the proc-pid-vm warning fix

Link: https://lkml.kernel.org/r/20250821101159.2238-1-reddybalavignesh9979@gmail.com
Signed-off-by: Bala-Vignesh-Reddy <reddybalavignesh9979@gmail.com>
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Link:https://lore.kernel.org/lkml/20250820143954.33d95635e504e94df01930d0@linux-foundation.org/
Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
Acked-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Acked-by: Mickal Salan <mic@digikod.net> [landlock]
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Bala-Vignesh-Reddy and committed by
Andrew Morton
a7498388 940b1be2

+6 -19
+4
tools/testing/selftests/kselftest.h
··· 92 92 #endif 93 93 #define __printf(a, b) __attribute__((format(printf, a, b))) 94 94 95 + #ifndef __maybe_unused 96 + #define __maybe_unused __attribute__((__unused__)) 97 + #endif 98 + 95 99 /* counters */ 96 100 struct ksft_count { 97 101 unsigned int ksft_pass;
+2 -4
tools/testing/selftests/landlock/audit.h
··· 20 20 #include <sys/time.h> 21 21 #include <unistd.h> 22 22 23 + #include "../kselftest.h" 24 + 23 25 #ifndef ARRAY_SIZE 24 26 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 25 - #endif 26 - 27 - #ifndef __maybe_unused 28 - #define __maybe_unused __attribute__((__unused__)) 29 27 #endif 30 28 31 29 #define REGEX_LANDLOCK_PREFIX "^audit([0-9.:]\\+): domain=\\([0-9a-f]\\+\\)"
-4
tools/testing/selftests/landlock/common.h
··· 22 22 23 23 #define TMP_DIR "tmp" 24 24 25 - #ifndef __maybe_unused 26 - #define __maybe_unused __attribute__((__unused__)) 27 - #endif 28 - 29 25 /* TEST_F_FORK() should not be used for new tests. */ 30 26 #define TEST_F_FORK(fixture_name, test_name) TEST_F(fixture_name, test_name) 31 27
-3
tools/testing/selftests/mm/pkey-helpers.h
··· 84 84 #ifndef noinline 85 85 # define noinline __attribute__((noinline)) 86 86 #endif 87 - #ifndef __maybe_unused 88 - # define __maybe_unused __attribute__((__unused__)) 89 - #endif 90 87 91 88 int sys_pkey_alloc(unsigned long flags, unsigned long init_val); 92 89 int sys_pkey_free(unsigned long pkey);
-4
tools/testing/selftests/net/psock_lib.h
··· 22 22 23 23 #define PORT_BASE 8000 24 24 25 - #ifndef __maybe_unused 26 - # define __maybe_unused __attribute__ ((__unused__)) 27 - #endif 28 - 29 25 static __maybe_unused void pair_udp_setfilter(int fd) 30 26 { 31 27 /* the filter below checks for all of the following conditions that
-2
tools/testing/selftests/perf_events/watermark_signal.c
··· 17 17 18 18 #include "../kselftest_harness.h" 19 19 20 - #define __maybe_unused __attribute__((__unused__)) 21 - 22 20 static int sigio_count; 23 21 24 22 static void handle_sigio(int signum __maybe_unused,
-2
tools/testing/selftests/ublk/utils.h
··· 2 2 #ifndef KUBLK_UTILS_H 3 3 #define KUBLK_UTILS_H 4 4 5 - #define __maybe_unused __attribute__((unused)) 6 - 7 5 #ifndef min 8 6 #define min(a, b) ((a) < (b) ? (a) : (b)) 9 7 #endif