linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-kselftest@vger.kernel.org,
	Frederic Weisbecker <fweisbec@gmail.com>,
	John Stultz <john.stultz@linaro.org>,
	Shuah Khan <shuah@kernel.org>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] selftests: posix_timers: Use common error handling code in two functions
Date: Tue, 21 Nov 2017 11:00:52 +0100	[thread overview]
Message-ID: <3ce187fa-a6df-a419-6924-ea12bf837972@users.sourceforge.net> (raw)

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

             reply	other threads:[~2017-11-21 10:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-21 10:00 SF Markus Elfring [this message]
2017-11-21 15:43 ` [PATCH] selftests: posix_timers: Use common error handling code in two functions Shuah Khan
2017-11-21 18:46   ` SF Markus Elfring

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=3ce187fa-a6df-a419-6924-ea12bf837972@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=fweisbec@gmail.com \
    --cc=john.stultz@linaro.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=sboyd@codeaurora.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;
as well as URLs for NNTP newsgroup(s).