linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: iio: Fix locking in __iio_push_event
@ 2010-01-15  9:30 Tobias Klauser
  2010-01-15 17:59 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Tobias Klauser @ 2010-01-15  9:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman, devel; +Cc: linux-kernel, Tobias Klauser, Jiri Slaby

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: iio: Fix locking in __iio_push_event
  2010-01-15  9:30 [PATCH] staging: iio: Fix locking in __iio_push_event Tobias Klauser
@ 2010-01-15 17:59 ` Greg KH
  2010-01-17 17:53   ` Tobias Klauser
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2010-01-15 17:59 UTC (permalink / raw)
  To: Tobias Klauser; +Cc: Greg Kroah-Hartman, devel, linux-kernel, Jiri Slaby

On Fri, Jan 15, 2010 at 10:30:01AM +0100, Tobias Klauser wrote:
> 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>

Sorry, but this is already fixed in my tree, someone beat you to it :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: iio: Fix locking in __iio_push_event
  2010-01-15 17:59 ` Greg KH
@ 2010-01-17 17:53   ` Tobias Klauser
  0 siblings, 0 replies; 3+ messages in thread
From: Tobias Klauser @ 2010-01-17 17:53 UTC (permalink / raw)
  To: Greg KH; +Cc: Greg Kroah-Hartman, devel, linux-kernel, Jiri Slaby

On 2010-01-15 at 18:59:41 +0100, Greg KH <greg@kroah.com> wrote:
> On Fri, Jan 15, 2010 at 10:30:01AM +0100, Tobias Klauser wrote:
> > 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>
> 
> Sorry, but this is already fixed in my tree, someone beat you to it :)

Oh, I seem to have missed that one in linux-next (or I should have a
closer look at your staging repository the next time :-). Never mind...

Cheers, Tobias

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-01-17 17:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-15  9:30 [PATCH] staging: iio: Fix locking in __iio_push_event Tobias Klauser
2010-01-15 17:59 ` Greg KH
2010-01-17 17:53   ` Tobias Klauser

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).