]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/iio/industrialio-event.c
Merge branch 'for-4.8/core' of git://git.kernel.dk/linux-block
[karo-tx-linux.git] / drivers / iio / industrialio-event.c
index cae332b1d7ea595959c53ecb3c8f51eef9ba095b..0ebfc923a9975a39326b38049f93cd3dfd1c0601 100644 (file)
@@ -44,6 +44,11 @@ struct iio_event_interface {
        struct mutex            read_lock;
 };
 
+bool iio_event_enabled(const struct iio_event_interface *ev_int)
+{
+       return !!test_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
+}
+
 /**
  * iio_push_event() - try to add event to the list for userspace reading
  * @indio_dev:         IIO device structure
@@ -60,7 +65,7 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
        int copied;
 
        /* Does anyone care? */
-       if (test_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) {
+       if (iio_event_enabled(ev_int)) {
 
                ev.id = ev_code;
                ev.timestamp = timestamp;
@@ -180,8 +185,14 @@ int iio_event_getfd(struct iio_dev *indio_dev)
        if (ev_int == NULL)
                return -ENODEV;
 
-       if (test_and_set_bit(IIO_BUSY_BIT_POS, &ev_int->flags))
-               return -EBUSY;
+       fd = mutex_lock_interruptible(&indio_dev->mlock);
+       if (fd)
+               return fd;
+
+       if (test_and_set_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) {
+               fd = -EBUSY;
+               goto unlock;
+       }
 
        iio_device_get(indio_dev);
 
@@ -194,6 +205,8 @@ int iio_event_getfd(struct iio_dev *indio_dev)
                kfifo_reset_out(&ev_int->det_events);
        }
 
+unlock:
+       mutex_unlock(&indio_dev->mlock);
        return fd;
 }