Skip to contentSkip to conversation

selftests: centralise maybe-unused definition in kselftest.h

PATCH In review Bala-Vignesh-Reddy 5 participants 5 messages Aug 21, 2025 – Aug 22, 2025

Subsystems (11)
lore
Share & tools
lore
#0 lore raw

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
index c3b6d2604b1e..661d31c4b558 100644
@@ -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
index b16986aa6442..02fd1393947a 100644
@@ -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
index 88a3c78f5d98..9acecae36f51 100644
@@ -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
index ea404f80e6cb..fa15f006fa68 100644
@@ -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
index 6e4fef560873..067265b0a554 100644
@@ -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
index e03fe1b9bba2..b3a72f0ac522 100644
@@ -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
index 978cbcb3eb11..2a72d37ad008 100644
@@ -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
index 36545d1567f1..a852e0b7153e 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Bala-Vignesh-Reddy

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

Looks reasonable.

Signature · 2 lines
Wei Yang
Help you, Help me
Acked-by on v1 1/1
#2 lore raw
In reply to Bala-Vignesh-Reddy
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 to kselftest.h header and removed other definition.

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

Thanks,
SJ

[...]

Reviewed-by on v1 1/1
#3 lore raw
In reply to Bala-Vignesh-Reddy
Quoted 10 lines · Bala-Vignesh-Reddy

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

Thanks,
Ming

maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Bala-Vignesh-Reddy
Quoted 10 lines · Bala-Vignesh-Reddy

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

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
index c3b6d2604b1e..661d31c4b558 100644
@@ -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
index b16986aa6442..02fd1393947a 100644
@@ -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
index 88a3c78f5d98..9acecae36f51 100644

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
index ea404f80e6cb..fa15f006fa68 100644
@@ -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
index 6e4fef560873..067265b0a554 100644
@@ -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
index e03fe1b9bba2..b3a72f0ac522 100644
@@ -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
index 978cbcb3eb11..2a72d37ad008 100644
@@ -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
index 36545d1567f1..a852e0b7153e 100644
@@ -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