mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tobias Klauser <tklauser@distanz.ch>
To: Greg Kroah-Hartman <gregkh@suse.de>, devel@driverdev.osuosl.org
Cc: linux-kernel@vger.kernel.org,
	Tobias Klauser <tklauser@distanz.ch>,
	Jiri Slaby <jirislaby@gmail.com>
Subject: [PATCH] staging: iio: Fix locking in __iio_push_event
Date: Fri, 15 Jan 2010 10:30:01 +0100	[thread overview]
Message-ID: <1263547801-8640-1-git-send-email-tklauser@distanz.ch> (raw)

Correctly unlock the mutex when leaving the function. This was
discovered by the stanse tool at
http://decibel.fi.muni.cz/~xslaby/stanse/error.cgi?db=33-rc&id=138

Cc: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
 drivers/staging/iio/industrialio-core.c |   49 +++++++++++++++++--------------
 1 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c
index 768f448..fa0f025 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/staging/iio/industrialio-core.c
@@ -78,28 +78,33 @@ EXPORT_SYMBOL(__iio_change_event);
 
 	/* Does anyone care? */
 	mutex_lock(&ev_int->event_list_lock);
-	if (test_bit(IIO_BUSY_BIT_POS, &ev_int->handler.flags)) {
-		if (ev_int->current_events == ev_int->max_events)
-			return 0;
-		ev = kmalloc(sizeof(*ev), GFP_KERNEL);
-		if (ev == NULL) {
-			ret = -ENOMEM;
-			goto error_ret;
-		}
-		ev->ev.id = ev_code;
-		ev->ev.timestamp = timestamp;
-		ev->shared_pointer = shared_pointer_p;
-		if (ev->shared_pointer)
-			shared_pointer_p->ev_p = ev;
-
-		list_add_tail(&ev->list, &ev_int->det_events.list);
-		ev_int->current_events++;
-		mutex_unlock(&ev_int->event_list_lock);
-		wake_up_interruptible(&ev_int->wait);
-	} else
-		mutex_unlock(&ev_int->event_list_lock);
+	if (!test_bit(IIO_BUSY_BIT_POS, &ev_int->handler.flags))
+		goto out_unlock;
 
-error_ret:
+	if (ev_int->current_events == ev_int->max_events)
+		goto out_unlock;
+
+	ev = kmalloc(sizeof(*ev), GFP_KERNEL);
+	if (ev == NULL) {
+		ret = -ENOMEM;
+		goto out_unlock;
+	}
+
+	ev->ev.id = ev_code;
+	ev->ev.timestamp = timestamp;
+	ev->shared_pointer = shared_pointer_p;
+	if (ev->shared_pointer)
+		shared_pointer_p->ev_p = ev;
+
+	list_add_tail(&ev->list, &ev_int->det_events.list);
+	ev_int->current_events++;
+	mutex_unlock(&ev_int->event_list_lock);
+	wake_up_interruptible(&ev_int->wait);
+
+	return 0;
+
+out_unlock:
+	mutex_unlock(&ev_int->event_list_lock);
 	return ret;
 }
 EXPORT_SYMBOL(__iio_push_event);
-- 
1.6.3.3


             reply	other threads:[~2010-01-15  9:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-15  9:30 Tobias Klauser [this message]
2010-01-15 17:59 ` Greg KH
2010-01-17 17:53   ` Tobias Klauser

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=1263547801-8640-1-git-send-email-tklauser@distanz.ch \
    --to=tklauser@distanz.ch \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@suse.de \
    --cc=jirislaby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®