From: Shuah Khan <skhan@linuxfoundation.org>
To: jstultz@google.com
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
tglx@linutronix.de, shuah@kernel.org, sboyd@kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH 1/2] selftests:timers: posix_timers: Fix warn_unused_result in __fatal_error()
Date: Wed, 25 Sep 2024 09:13:12 -0600 [thread overview]
Message-ID: <07999b46-ec31-4284-8869-1ecbdc0c7104@linuxfoundation.org> (raw)
In-Reply-To: <4f3a0acd903aeee52fb71acaec1106d513a2e88b.1727191485.git.skhan@linuxfoundation.org>
On 9/24/24 09:56, Shuah Khan wrote:
> __fatal_error routine doesn't check strerror_r() return value,
> which results in the following compile time warning:
>
> posix_timers.c: In function ‘__fatal_error’:
> posix_timers.c:31:9: warning: ignoring return value of ‘strerror_r’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
> 31 | strerror_r(errno, buf, sizeof(buf));
>
> Fix this by adding a check for return value and error handling appropriate
> for the GNU-specific strerror_r() in use in __fatal_error(). Check if
> return string is null and handle accordingly.
>
> From Linux strerror_r() manual page:
>
> "The GNU-specific strerror_r() returns a pointer to a string containing
> the error message. This may be either a pointer to a string that the
> function stores in buf, or a pointer to some (immutable) static string
> (in which case buf is unused). If the function stores a string in buf,
> then at most buflen bytes are stored (the string may be truncated if
> buflen is too small and errnum is unknown). The string always includes
> a terminating null byte."
>
> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
> ---
> tools/testing/selftests/timers/posix_timers.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
> index 16bd49492efa..ddb1cebc844e 100644
> --- a/tools/testing/selftests/timers/posix_timers.c
> +++ b/tools/testing/selftests/timers/posix_timers.c
> @@ -26,13 +26,17 @@
> static void __fatal_error(const char *test, const char *name, const char *what)
> {
> char buf[64];
> + char *ret_str = NULL;
>
> - strerror_r(errno, buf, sizeof(buf));
> + ret_str = strerror_r(errno, buf, sizeof(buf));
>
> - if (name && strlen(name))
> - ksft_exit_fail_msg("%s %s %s %s\n", test, name, what, buf);
> + if (name && strlen(name) && ret_str)
> + ksft_exit_fail_msg("%s %s %s %s\n", test, name, what, ret_str);
> + else if (ret_str)
> + ksft_exit_fail_msg("%s %s %s\n", test, what, ret_str);
> else
> - ksft_exit_fail_msg("%s %s %s\n", test, what, buf);
> + ksft_exit_fail_msg("%s %s\n", test, what);
> +
> }
>
> #define fatal_error(name, what) __fatal_error(__func__, name, what)
Any comments on this patch John?
thanks,
-- Shuah
next prev parent reply other threads:[~2024-09-25 15:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-24 15:56 [PATCH 0/2] timers test fix and duplicate defines cleanup Shuah Khan
2024-09-24 15:56 ` [PATCH 1/2] selftests:timers: posix_timers: Fix warn_unused_result in __fatal_error() Shuah Khan
2024-09-25 15:13 ` Shuah Khan [this message]
2024-09-25 17:19 ` John Stultz
2024-09-24 15:56 ` [PATCH 2/2] selftests: timers: Remove local NSEC_PER_SEC and USEC_PER_SEC defines Shuah Khan
2024-09-24 23:59 ` John Stultz
2024-09-25 15:20 ` Shuah Khan
2024-09-25 17:33 ` John Stultz
2024-09-26 17:15 ` [PATCH 0/2] timers test fix and duplicate defines cleanup Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=07999b46-ec31-4284-8869-1ecbdc0c7104@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox