diff mbox series

[v8,2/9] selftests/landlock: Locally define __maybe_unused

Message ID 20221001154908.49665-3-gnoack3000@gmail.com (mailing list archive)
State Handled Elsewhere
Headers show
Series landlock: truncate support | expand

Commit Message

Günther Noack Oct. 1, 2022, 3:49 p.m. UTC
The checkpatch tool started to flag __attribute__(__unused__), which
we previously used. The header where this is normally defined is not
currently compatible with selftests.

This is the same approach as used in selftests/net/psock_lib.h.

Signed-off-by: Günther Noack <gnoack3000@gmail.com>
---
 tools/testing/selftests/landlock/common.h | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

Comments

Mickaël Salaün Oct. 5, 2022, 6:53 p.m. UTC | #1
Thanks for cleaning this. Can you please move this patch just before the 
test patches?


On 01/10/2022 17:49, Günther Noack wrote:
> The checkpatch tool started to flag __attribute__(__unused__), which
> we previously used. The header where this is normally defined is not
> currently compatible with selftests.
> 
> This is the same approach as used in selftests/net/psock_lib.h.
> 
> Signed-off-by: Günther Noack <gnoack3000@gmail.com>
> ---
>   tools/testing/selftests/landlock/common.h | 18 ++++++++++--------
>   1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/testing/selftests/landlock/common.h b/tools/testing/selftests/landlock/common.h
> index 7ba18eb23783..7d34592471db 100644
> --- a/tools/testing/selftests/landlock/common.h
> +++ b/tools/testing/selftests/landlock/common.h
> @@ -17,6 +17,10 @@
>   
>   #include "../kselftest_harness.h"
>   
> +#ifndef __maybe_unused
> +#define __maybe_unused __attribute__((__unused__))
> +#endif
> +
>   /*
>    * TEST_F_FORK() is useful when a test drop privileges but the corresponding
>    * FIXTURE_TEARDOWN() requires them (e.g. to remove files from a directory
> @@ -140,14 +144,12 @@ static void _init_caps(struct __test_metadata *const _metadata, bool drop_all)
>   }
>   
>   /* We cannot put such helpers in a library because of kselftest_harness.h . */
> -__attribute__((__unused__)) static void
> -disable_caps(struct __test_metadata *const _metadata)
> +static void __maybe_unused disable_caps(struct __test_metadata *const _metadata)
>   {
>   	_init_caps(_metadata, false);
>   }
>   
> -__attribute__((__unused__)) static void
> -drop_caps(struct __test_metadata *const _metadata)
> +static void __maybe_unused drop_caps(struct __test_metadata *const _metadata)
>   {
>   	_init_caps(_metadata, true);
>   }
> @@ -176,14 +178,14 @@ static void _effective_cap(struct __test_metadata *const _metadata,
>   	}
>   }
>   
> -__attribute__((__unused__)) static void
> -set_cap(struct __test_metadata *const _metadata, const cap_value_t caps)
> +static void __maybe_unused set_cap(struct __test_metadata *const _metadata,
> +				   const cap_value_t caps)
>   {
>   	_effective_cap(_metadata, caps, CAP_SET);
>   }
>   
> -__attribute__((__unused__)) static void
> -clear_cap(struct __test_metadata *const _metadata, const cap_value_t caps)
> +static void __maybe_unused clear_cap(struct __test_metadata *const _metadata,
> +				     const cap_value_t caps)
>   {
>   	_effective_cap(_metadata, caps, CAP_CLEAR);
>   }
Günther Noack Oct. 8, 2022, 7:47 a.m. UTC | #2
On Wed, Oct 05, 2022 at 08:53:56PM +0200, Mickaël Salaün wrote:
> Thanks for cleaning this. Can you please move this patch just before the
> test patches?

Done.

--
diff mbox series

Patch

diff --git a/tools/testing/selftests/landlock/common.h b/tools/testing/selftests/landlock/common.h
index 7ba18eb23783..7d34592471db 100644
--- a/tools/testing/selftests/landlock/common.h
+++ b/tools/testing/selftests/landlock/common.h
@@ -17,6 +17,10 @@ 
 
 #include "../kselftest_harness.h"
 
+#ifndef __maybe_unused
+#define __maybe_unused __attribute__((__unused__))
+#endif
+
 /*
  * TEST_F_FORK() is useful when a test drop privileges but the corresponding
  * FIXTURE_TEARDOWN() requires them (e.g. to remove files from a directory
@@ -140,14 +144,12 @@  static void _init_caps(struct __test_metadata *const _metadata, bool drop_all)
 }
 
 /* We cannot put such helpers in a library because of kselftest_harness.h . */
-__attribute__((__unused__)) static void
-disable_caps(struct __test_metadata *const _metadata)
+static void __maybe_unused disable_caps(struct __test_metadata *const _metadata)
 {
 	_init_caps(_metadata, false);
 }
 
-__attribute__((__unused__)) static void
-drop_caps(struct __test_metadata *const _metadata)
+static void __maybe_unused drop_caps(struct __test_metadata *const _metadata)
 {
 	_init_caps(_metadata, true);
 }
@@ -176,14 +178,14 @@  static void _effective_cap(struct __test_metadata *const _metadata,
 	}
 }
 
-__attribute__((__unused__)) static void
-set_cap(struct __test_metadata *const _metadata, const cap_value_t caps)
+static void __maybe_unused set_cap(struct __test_metadata *const _metadata,
+				   const cap_value_t caps)
 {
 	_effective_cap(_metadata, caps, CAP_SET);
 }
 
-__attribute__((__unused__)) static void
-clear_cap(struct __test_metadata *const _metadata, const cap_value_t caps)
+static void __maybe_unused clear_cap(struct __test_metadata *const _metadata,
+				     const cap_value_t caps)
 {
 	_effective_cap(_metadata, caps, CAP_CLEAR);
 }