linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: rt-users <linux-rt-users@vger.kernel.org>
Cc: Clark Williams <williams@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Carsten Emde <C.Emde@osadl.org>,
	Sebastian Siewior <bigeasy@linutronix.de>,
	John Kacur <jkacur@redhat.com>
Subject: [PATCH 2/6] Fix possible exit on error without releasing mutex
Date: Fri, 10 Jul 2015 14:25:27 +0200	[thread overview]
Message-ID: <1436531131-9186-3-git-send-email-jkacur@redhat.com> (raw)
In-Reply-To: <1436531131-9186-1-git-send-email-jkacur@redhat.com>

Coverage tools indicate that there are two spots where the function
low_priority() could exit without releasing the mutex.

Since the only error that pthread_barrier_wait is supposed to give is
EINVAL when the barrier is not an initialized barrier object, the
chances of this happinning seem remote. However, if we are going to
test for the error and potentially exit, then we should release the
mutex too.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/pi_tests/pi_stress.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c
index aaa36c362445..1d1cc58fae54 100644
--- a/src/pi_tests/pi_stress.c
+++ b/src/pi_tests/pi_stress.c
@@ -727,17 +727,24 @@ void *low_priority(void *arg)
 		status = pthread_barrier_wait(&p->locked_barrier);
 		if (status && status != PTHREAD_BARRIER_SERIAL_THREAD) {
 			pi_error
-			    ("low_priority[%d]: pthread_barrier_wait(locked): %x\n",
-			     p->id, status);
+				("low_priority[%d]: pthread_barrier_wait(locked): %x\n",
+				 p->id, status);
+			/* release the mutex */
+			pi_debug("low_priority[%d]: unlocking mutex\n", p->id);
+			pthread_mutex_unlock(&p->mutex);
 			return NULL;
 		}
+
 		/* wait for priority boost */
 		pi_debug("low_priority[%d]: entering elevated wait\n", p->id);
 		status = pthread_barrier_wait(&p->elevate_barrier);
 		if (status && status != PTHREAD_BARRIER_SERIAL_THREAD) {
 			pi_error
-			    ("low_priority[%d]: pthread_barrier_wait(elevate): %x\n",
-			     p->id, status);
+				("low_priority[%d]: pthread_barrier_wait(elevate): %x\n",
+				 p->id, status);
+			/* release the mutex */
+			pi_debug("low_priority[%d]: unlocking mutex\n", p->id);
+			pthread_mutex_unlock(&p->mutex);
 			return NULL;
 		}
 
-- 
1.8.3.1


  parent reply	other threads:[~2015-07-10 12:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-10 12:25 [PATCH 0/6] Various rt-test patches John Kacur
2015-07-10 12:25 ` [PATCH 1/6] Fix warning: unused variable ‘c’ John Kacur
2015-07-10 12:25 ` John Kacur [this message]
2015-07-14 15:59   ` [PATCH 2/6] Fix possible exit on error without releasing mutex Sebastian Andrzej Siewior
2015-07-14 21:03     ` John Kacur
2015-07-10 12:25 ` [PATCH 3/6] Create a .gitattribute file to specify what files git-archive should ignore John Kacur
2015-07-10 12:25 ` [PATCH 4/6] Add .tar files to .gitignore John Kacur
2015-07-14 15:58   ` Sebastian Andrzej Siewior
2015-07-14 20:33     ` John Kacur
2015-07-10 12:25 ` [PATCH 5/6] Change VERSION_STRING to VERSION John Kacur
2015-07-10 13:42   ` Pavel Vasilyev
2015-07-14 16:09   ` Sebastian Andrzej Siewior
2015-07-14 21:45     ` John Kacur
2015-07-10 12:25 ` [PATCH 6/6] Create an rt-tests.tar file using git-archive John Kacur
2015-07-14 16:13   ` Sebastian Andrzej Siewior
2015-07-14 20:28     ` John Kacur

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=1436531131-9186-3-git-send-email-jkacur@redhat.com \
    --to=jkacur@redhat.com \
    --cc=C.Emde@osadl.org \
    --cc=bigeasy@linutronix.de \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.com \
    /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).