Skip to content

Commit 7c388ec

Browse files
committed
iio: kfifo - add poll support.
This buffer implementation was missing poll support. Signed-off-by: Jonathan Cameron <jic23@kernel.org> Tested-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: srinivas pandruvada <srinivas.pandruvada@intel.com>
1 parent 08ce9b4 commit 7c388ec

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎drivers/iio/kfifo_buf.c‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/kfifo.h>
77
#include <linux/mutex.h>
88
#include <linux/iio/kfifo_buf.h>
9+
#include <linux/sched.h>
910

1011
struct iio_kfifo {
1112
struct iio_buffer buffer;
@@ -36,6 +37,7 @@ static int iio_request_update_kfifo(struct iio_buffer *r)
3637
kfifo_free(&buf->kf);
3738
ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum,
3839
buf->buffer.length);
40+
r->stufftoread = false;
3941
error_ret:
4042
return ret;
4143
}
@@ -82,6 +84,9 @@ static int iio_set_bytes_per_datum_kfifo(struct iio_buffer *r, size_t bpd)
8284

8385
static int iio_set_length_kfifo(struct iio_buffer *r, int length)
8486
{
87+
/* Avoid an invalid state */
88+
if (length < 2)
89+
length = 2;
8590
if (r->length != length) {
8691
r->length = length;
8792
iio_mark_update_needed_kfifo(r);
@@ -98,6 +103,8 @@ static int iio_store_to_kfifo(struct iio_buffer *r,
98103
ret = kfifo_in(&kf->kf, data, 1);
99104
if (ret != 1)
100105
return -EBUSY;
106+
r->stufftoread = true;
107+
wake_up_interruptible(&r->pollq);
101108

102109
return 0;
103110
}
@@ -115,6 +122,12 @@ static int iio_read_first_n_kfifo(struct iio_buffer *r,
115122
if (ret < 0)
116123
return ret;
117124

125+
if (kfifo_is_empty(&kf->kf))
126+
r->stufftoread = false;
127+
/* verify it is still empty to avoid race */
128+
if (!kfifo_is_empty(&kf->kf))
129+
r->stufftoread = true;
130+
118131
return copied;
119132
}
120133

@@ -139,7 +152,7 @@ struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev)
139152
iio_buffer_init(&kf->buffer);
140153
kf->buffer.attrs = &iio_kfifo_attribute_group;
141154
kf->buffer.access = &kfifo_access_funcs;
142-
155+
kf->buffer.length = 2;
143156
return &kf->buffer;
144157
}
145158
EXPORT_SYMBOL(iio_kfifo_allocate);

0 commit comments

Comments
 (0)