selftests: centralise maybe-unused definition in kselftest.h
Subsystems (11)
PATCH 1/1 selftests: centralise maybe-unused definition in kselftest.h
Several selftests subdirectories duplicated the define __maybe_unused, leading to redundant code. Moved to kselftest.h header and removed other definition.
This addresses the duplication noted in the proc-pid-vm warning fix
--- tools/testing/selftests/kselftest.h | 4 ++++ tools/testing/selftests/landlock/audit.h | 6 ++---- tools/testing/selftests/landlock/common.h | 4 ---- tools/testing/selftests/mm/pkey-helpers.h | 3 --- tools/testing/selftests/net/psock_lib.h | 4 ---- tools/testing/selftests/perf_events/watermark_signal.c | 2 -- tools/testing/selftests/proc/proc-pid-vm.c | 4 ---- tools/testing/selftests/ublk/utils.h | 2 -- 8 files changed, 6 insertions(+), 23 deletions(-)
tools/testing/selftests/kselftest.h +4 -0
@@ -92,6 +92,10 @@#endif #define __printf (a, b) __attribute__((format(printf, a, b))) +#ifndef __maybe_unused +#define __maybe_unused __attribute__((__unused__)) +#endif +/* counters */ struct ksft_count {unsigned int ksft_pass;
tools/testing/selftests/landlock/audit.h +2 -4
@@ -20,14 +20,12 @@#include <sys/time.h> #include <unistd.h> +#include "../kselftest.h" +#ifndef ARRAY_SIZE #define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0]))#endif -#ifndef __maybe_unused -#define __maybe_unused __attribute__((__unused__)) -#endif -#define REGEX_LANDLOCK_PREFIX "^audit([0-9.:]\\+): domain=\\([0-9a-f]\\+\\)"struct audit_filter {
tools/testing/selftests/landlock/common.h +0 -4
@@ -22,10 +22,6 @@#define TMP_DIR "tmp" -#ifndef __maybe_unused -#define __maybe_unused __attribute__((__unused__)) -#endif -/* TEST_F_FORK() should not be used for new tests. */ #define TEST_F_FORK (fixture_name, test_name) TEST_F(fixture_name, test_name)
tools/testing/selftests/mm/pkey-helpers.h +0 -3
@@ -84,9 +84,6 @@ extern void abort_hooks(void);#ifndef noinline# define noinline __attribute__((noinline))#endif -#ifndef __maybe_unused -# define __maybe_unused __attribute__((__unused__)) -#endif int sys_pkey_alloc (unsigned long flags,unsigned long init_val);int sys_pkey_free (unsigned long pkey);
tools/testing/selftests/net/psock_lib.h +0 -4
@@ -22,10 +22,6 @@#define PORT_BASE 8000 -#ifndef __maybe_unused -# define __maybe_unused __attribute__ ((__unused__)) -#endif -static __maybe_unused void pair_udp_setfilter (int fd) {/* the filter below checks for all of the following conditions that
tools/testing/selftests/perf_events/watermark_signal.c +0 -2
@@ -17,8 +17,6 @@#include "../kselftest_harness.h" -#define __maybe_unused __attribute__((__unused__)) -static int sigio_count; static void handle_sigio(int signum __maybe_unused,
tools/testing/selftests/proc/proc-pid-vm.c +0 -4
@@ -47,10 +47,6 @@#include <sys/resource.h> #include <linux/fs.h> -#ifndef __maybe_unused -#define __maybe_unused __attribute__((__unused__)) -#endif -#include "../kselftest.h" static inline long sys_execveat (int dirfd,const char *pathname,char **argv,char **envp,int flags)
tools/testing/selftests/ublk/utils.h +0 -2
@@ -2,8 +2,6 @@#ifndef KUBLK_UTILS_H #define KUBLK_UTILS_H -#define __maybe_unused __attribute__((unused)) -#ifndef min#define min (a, b) ((a) < (b) ? (a) : (b))#endif
Signature · 1 line
2.43.0
Quoted 10 lines · Bala-Vignesh-Reddy
Several selftests subdirectories duplicated the define
__maybe_unused, leading to redundant code. Moved tokselftest.hheader and removed other definition.This addresses the duplication noted in the proc-pid-vm warning fix
Suggested-by Andrew Morton <[email protected]>Signed-off-by Bala-Vignesh-Reddy <[email protected]>
Looks reasonable.
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 10 lines · On Thu, 21 Aug 2025 15:41:59 +0530 Bala-Vignesh-Reddy…
Several selftests subdirectories duplicated the define
__maybe_unused, leading to redundant code. Moved tokselftest.hheader and removed other definition.This addresses the duplication noted in the proc-pid-vm warning fix
Suggested-by Andrew Morton <[email protected]>Signed-off-by Bala-Vignesh-Reddy <[email protected]>
Thanks,
SJ
[...]
Quoted 10 lines · Bala-Vignesh-Reddy
Several selftests subdirectories duplicated the define
__maybe_unused, leading to redundant code. Moved tokselftest.hheader and removed other definition.This addresses the duplication noted in the proc-pid-vm warning fix
Suggested-by Andrew Morton <[email protected]>Signed-off-by Bala-Vignesh-Reddy <[email protected]>
Thanks,
Ming
Quoted 10 lines · Bala-Vignesh-Reddy
Several selftests subdirectories duplicated the define
__maybe_unused, leading to redundant code. Moved tokselftest.hheader and removed other definition.This addresses the duplication noted in the proc-pid-vm warning fix
Suggested-by Andrew Morton <[email protected]>Signed-off-by Bala-Vignesh-Reddy <[email protected]>
Looks good for Landlock:
Quoted 52 lines
--- tools/testing/selftests/kselftest.h | 4 ++++ tools/testing/selftests/landlock/audit.h | 6 ++---- tools/testing/selftests/landlock/common.h | 4 ---- tools/testing/selftests/mm/pkey-helpers.h | 3 --- tools/testing/selftests/net/psock_lib.h | 4 ---- tools/testing/selftests/perf_events/watermark_signal.c | 2 -- tools/testing/selftests/proc/proc-pid-vm.c | 4 ---- tools/testing/selftests/ublk/utils.h | 2 -- 8 files changed, 6 insertions(+), 23 deletions(-)tools/testing/selftests/kselftest.h +4
-0@@ -92,6 +92,10 @@#endif #define __printf (a, b) __attribute__((format(printf, a, b))) +#ifndef __maybe_unused +#define __maybe_unused __attribute__((__unused__)) +#endif +/* counters */ struct ksft_count {unsigned int ksft_pass;tools/testing/selftests/landlock/audit.h +2
-4@@ -20,14 +20,12 @@#include <sys/time.h> #include <unistd.h> +#include "../kselftest.h" +#ifndef ARRAY_SIZE #define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0]))#endif -#ifndef __maybe_unused -#define __maybe_unused __attribute__((__unused__)) -#endif -#define REGEX_LANDLOCK_PREFIX "^audit([0-9.:]\\+): domain=\\([0-9a-f]\\+\\)"struct audit_filter {tools/testing/selftests/landlock/common.h +0
-0
tools/testing/selftests/landlock/common.h line 28
Quoted 7 lines
tools/testing/selftests/landlock/common.h +0
-4@@ -22,10 +22,6 @@#define TMP_DIR "tmp" -#ifndef __maybe_unused -#define __maybe_unused __attribute__((__unused__)) -#endif -
We could explicitly include kselftest.h in this file, but it's already included by kselftest_harness.h, so that's OK.
Quoted 77 lines
tools/testing/selftests/landlock/common.h +0
-0/* TEST_F_FORK() should not be used for new tests. */ #define TEST_F_FORK (fixture_name, test_name) TEST_F(fixture_name, test_name)tools/testing/selftests/mm/pkey-helpers.h +0
-3@@ -84,9 +84,6 @@ extern void abort_hooks(void);#ifndef noinline# define noinline __attribute__((noinline))#endif -#ifndef __maybe_unused -# define __maybe_unused __attribute__((__unused__)) -#endif int sys_pkey_alloc (unsigned long flags,unsigned long init_val);int sys_pkey_free (unsigned long pkey);tools/testing/selftests/net/psock_lib.h +0
-4@@ -22,10 +22,6 @@#define PORT_BASE 8000 -#ifndef __maybe_unused -# define __maybe_unused __attribute__ ((__unused__)) -#endif -static __maybe_unused void pair_udp_setfilter (int fd) {/* the filter below checks for all of the following conditions that tools/testing/selftests/perf_events/watermark_signal.c +0
-2@@ -17,8 +17,6 @@#include "../kselftest_harness.h" -#define __maybe_unused __attribute__((__unused__)) -static int sigio_count; static void handle_sigio(int signum __maybe_unused,tools/testing/selftests/proc/proc-pid-vm.c +0
-4@@ -47,10 +47,6 @@#include <sys/resource.h> #include <linux/fs.h> -#ifndef __maybe_unused -#define __maybe_unused __attribute__((__unused__)) -#endif -#include "../kselftest.h" static inline long sys_execveat (int dirfd,const char *pathname,char **argv,char **envp,int flags)tools/testing/selftests/ublk/utils.h +0
-2@@ -2,8 +2,6 @@#ifndef KUBLK_UTILS_H #define KUBLK_UTILS_H -#define __maybe_unused __attribute__((unused)) -#ifndef min#define min (a, b) ((a) < (b) ? (a) : (b))#endif Signature · 1 line
2.43.0