2024-04-14 06:26:53

by Muhammad Usama Anjum

[permalink] [raw]
Subject: [PATCH] selftests: Mark ksft_exit_fail_perror() as __noreturn

Let the compilers (clang) know that this function would just call
exit() and would never return. It is needed to avoid false positive
static analysis errors. All similar functions calling exit()
unconditionally have been marked as __noreturn.

Signed-off-by: Muhammad Usama Anjum <[email protected]>
---
This patch has been suggested [1] and tested on top of the following
patches:
- f07041728422 ("selftests: add ksft_exit_fail_perror()") which is
in kselftest tree already
- ("kselftest: Mark functions that unconditionally call exit() as
__noreturn") would appear in tip/timers/urgent

[1] https://lore.kernel.org/all/[email protected]
---
tools/testing/selftests/kselftest.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index 050c5fd018400..b43a7a7ca4b40 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -372,7 +372,7 @@ static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...)
exit(KSFT_FAIL);
}

-static inline void ksft_exit_fail_perror(const char *msg)
+static inline __noreturn void ksft_exit_fail_perror(const char *msg)
{
#ifndef NOLIBC
ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
--
2.39.2



2024-04-15 15:41:16

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] selftests: Mark ksft_exit_fail_perror() as __noreturn

On Sun, Apr 14, 2024 at 11:26:53AM +0500, Muhammad Usama Anjum wrote:
> Let the compilers (clang) know that this function would just call
> exit() and would never return. It is needed to avoid false positive
> static analysis errors. All similar functions calling exit()
> unconditionally have been marked as __noreturn.
>
> Signed-off-by: Muhammad Usama Anjum <[email protected]>

Reviewed-by: Nathan Chancellor <[email protected]>

> ---
> This patch has been suggested [1] and tested on top of the following
> patches:
> - f07041728422 ("selftests: add ksft_exit_fail_perror()") which is
> in kselftest tree already
> - ("kselftest: Mark functions that unconditionally call exit() as
> __noreturn") would appear in tip/timers/urgent
>
> [1] https://lore.kernel.org/all/[email protected]
> ---
> tools/testing/selftests/kselftest.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
> index 050c5fd018400..b43a7a7ca4b40 100644
> --- a/tools/testing/selftests/kselftest.h
> +++ b/tools/testing/selftests/kselftest.h
> @@ -372,7 +372,7 @@ static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...)
> exit(KSFT_FAIL);
> }
>
> -static inline void ksft_exit_fail_perror(const char *msg)
> +static inline __noreturn void ksft_exit_fail_perror(const char *msg)
> {
> #ifndef NOLIBC
> ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
> --
> 2.39.2
>
>

2024-04-17 00:04:57

by Shuah Khan

[permalink] [raw]
Subject: Re: [PATCH] selftests: Mark ksft_exit_fail_perror() as __noreturn

On 4/15/24 09:41, Nathan Chancellor wrote:
> On Sun, Apr 14, 2024 at 11:26:53AM +0500, Muhammad Usama Anjum wrote:
>> Let the compilers (clang) know that this function would just call
>> exit() and would never return. It is needed to avoid false positive
>> static analysis errors. All similar functions calling exit()
>> unconditionally have been marked as __noreturn.
>>
>> Signed-off-by: Muhammad Usama Anjum <[email protected]>
>
> Reviewed-by: Nathan Chancellor <[email protected]>
>

Thank you both. Applied to linux-kselftest next for Linux 6.10-rc1.

thanks,
-- Shuah