* [PATCH] selftests: posix_timers: Use common error handling code in two functions
@ 2017-11-21 10:00 SF Markus Elfring
2017-11-21 15:43 ` Shuah Khan
0 siblings, 1 reply; 3+ messages in thread
From: SF Markus Elfring @ 2017-11-21 10:00 UTC (permalink / raw)
To: linux-kselftest, Frederic Weisbecker, John Stultz, Shuah Khan,
Stephen Boyd, Thomas Gleixner
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 21 Nov 2017 10:50:32 +0100
Add jump targets so that a bit of exception handling can be better reused
at the end of these functions.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
tools/testing/selftests/timers/posix_timers.c | 32 +++++++++++++--------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index 15cf56d32155..5c9fbb06194f 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -104,10 +104,8 @@ static int check_itimer(int which)
signal(SIGALRM, sig_handler);
err = gettimeofday(&start, NULL);
- if (err < 0) {
- perror("Can't call gettimeofday()\n");
- return -1;
- }
+ if (err < 0)
+ goto report_failure;
err = setitimer(which, &val, NULL);
if (err < 0) {
@@ -123,10 +121,8 @@ static int check_itimer(int which)
idle_loop();
err = gettimeofday(&end, NULL);
- if (err < 0) {
- perror("Can't call gettimeofday()\n");
- return -1;
- }
+ if (err < 0)
+ goto report_failure;
if (!check_diff(start, end))
printf("[OK]\n");
@@ -134,6 +130,10 @@ static int check_itimer(int which)
printf("[FAIL]\n");
return 0;
+
+report_failure:
+ perror("Can't call gettimeofday()\n");
+ return -1;
}
static int check_timer_create(int which)
@@ -162,10 +162,8 @@ static int check_timer_create(int which)
signal(SIGALRM, sig_handler);
err = gettimeofday(&start, NULL);
- if (err < 0) {
- perror("Can't call gettimeofday()\n");
- return -1;
- }
+ if (err < 0)
+ goto report_failure;
err = timer_settime(id, 0, &val, NULL);
if (err < 0) {
@@ -176,10 +174,8 @@ static int check_timer_create(int which)
user_loop();
err = gettimeofday(&end, NULL);
- if (err < 0) {
- perror("Can't call gettimeofday()\n");
- return -1;
- }
+ if (err < 0)
+ goto report_failure;
if (!check_diff(start, end))
printf("[OK]\n");
@@ -187,6 +183,10 @@ static int check_timer_create(int which)
printf("[FAIL]\n");
return 0;
+
+report_failure:
+ perror("Can't call gettimeofday()\n");
+ return -1;
}
int main(int argc, char **argv)
--
2.15.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests: posix_timers: Use common error handling code in two functions
2017-11-21 10:00 [PATCH] selftests: posix_timers: Use common error handling code in two functions SF Markus Elfring
@ 2017-11-21 15:43 ` Shuah Khan
2017-11-21 18:46 ` SF Markus Elfring
0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2017-11-21 15:43 UTC (permalink / raw)
To: SF Markus Elfring, linux-kselftest, Frederic Weisbecker,
John Stultz, Stephen Boyd, Thomas Gleixner
Cc: LKML, kernel-janitors, Shuah Khan, Shuah Khan
On 11/21/2017 03:00 AM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 21 Nov 2017 10:50:32 +0100
>
> Add jump targets so that a bit of exception handling can be better reused
> at the end of these functions.
>
> This issue was detected by using the Coccinelle software.
Please include Coccinelle report in the change log.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> tools/testing/selftests/timers/posix_timers.c | 32 +++++++++++++--------------
> 1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
> index 15cf56d32155..5c9fbb06194f 100644
> --- a/tools/testing/selftests/timers/posix_timers.c
> +++ b/tools/testing/selftests/timers/posix_timers.c
> @@ -104,10 +104,8 @@ static int check_itimer(int which)
> signal(SIGALRM, sig_handler);
>
> err = gettimeofday(&start, NULL);
> - if (err < 0) {
> - perror("Can't call gettimeofday()\n");
> - return -1;
> - }
> + if (err < 0)
> + goto report_failure;
Instead of report_failure, makes this specific to the failure.
Something like, gettimeofday_error
>
> err = setitimer(which, &val, NULL);
> if (err < 0) {
> @@ -123,10 +121,8 @@ static int check_itimer(int which)
> idle_loop();
>
> err = gettimeofday(&end, NULL);
> - if (err < 0) {
> - perror("Can't call gettimeofday()\n");
> - return -1;
> - }
> + if (err < 0)
> + goto report_failure;
>
> if (!check_diff(start, end))
> printf("[OK]\n");
> @@ -134,6 +130,10 @@ static int check_itimer(int which)
> printf("[FAIL]\n");
>
> return 0;
> +
> +report_failure:
> + perror("Can't call gettimeofday()\n");
> + return -1;
> }
>
> static int check_timer_create(int which)
> @@ -162,10 +162,8 @@ static int check_timer_create(int which)
> signal(SIGALRM, sig_handler);
>
> err = gettimeofday(&start, NULL);
> - if (err < 0) {
> - perror("Can't call gettimeofday()\n");
> - return -1;
> - }
> + if (err < 0)
> + goto report_failure;
>
> err = timer_settime(id, 0, &val, NULL);
> if (err < 0) {
> @@ -176,10 +174,8 @@ static int check_timer_create(int which)
> user_loop();
>
> err = gettimeofday(&end, NULL);
> - if (err < 0) {
> - perror("Can't call gettimeofday()\n");
> - return -1;
> - }
> + if (err < 0)
> + goto report_failure;
>
> if (!check_diff(start, end))
> printf("[OK]\n");
> @@ -187,6 +183,10 @@ static int check_timer_create(int which)
> printf("[FAIL]\n");
>
> return 0;
> +
> +report_failure:
> + perror("Can't call gettimeofday()\n");
> + return -1;
> }
>
> int main(int argc, char **argv)
>
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests: posix_timers: Use common error handling code in two functions
2017-11-21 15:43 ` Shuah Khan
@ 2017-11-21 18:46 ` SF Markus Elfring
0 siblings, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-11-21 18:46 UTC (permalink / raw)
To: shuah, linux-kselftest, Frederic Weisbecker, John Stultz,
Stephen Boyd, Thomas Gleixner
Cc: LKML, kernel-janitors, Shuah Khan
>> Add jump targets so that a bit of exception handling can be better reused
>> at the end of these functions.
>>
>> This issue was detected by using the Coccinelle software.
>
> Please include Coccinelle report in the change log.
I guess that I can not append the kind of report you might be looking for
so far. This small update suggestion is just another result from one
of my evolving scripts for the semantic patch language.
It was discussed under the topic “Comparing statement lists with SmPL”
to some degree.
https://systeme.lip6.fr/pipermail/cocci/2017-August/004388.html
>> @@ -104,10 +104,8 @@ static int check_itimer(int which)
>> signal(SIGALRM, sig_handler);
>>
>> err = gettimeofday(&start, NULL);
>> - if (err < 0) {
>> - perror("Can't call gettimeofday()\n");
>> - return -1;
>> - }
>> + if (err < 0)
>> + goto report_failure;
>
> Instead of report_failure, makes this specific to the failure.
> Something like, gettimeofday_error
Would you like to achieve unique error messages in this use case?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-21 18:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-21 10:00 [PATCH] selftests: posix_timers: Use common error handling code in two functions SF Markus Elfring
2017-11-21 15:43 ` Shuah Khan
2017-11-21 18:46 ` SF Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).