diff options
-rw-r--r-- | drivers/iio/kfifo_buf.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c index 95c6fc81c2c7..7134e8ada09a 100644 --- a/drivers/iio/kfifo_buf.c +++ b/drivers/iio/kfifo_buf.c | |||
@@ -42,7 +42,6 @@ static int iio_request_update_kfifo(struct iio_buffer *r) | |||
42 | } else { | 42 | } else { |
43 | kfifo_reset_out(&buf->kf); | 43 | kfifo_reset_out(&buf->kf); |
44 | } | 44 | } |
45 | r->stufftoread = false; | ||
46 | mutex_unlock(&buf->user_lock); | 45 | mutex_unlock(&buf->user_lock); |
47 | 46 | ||
48 | return ret; | 47 | return ret; |
@@ -108,7 +107,7 @@ static int iio_store_to_kfifo(struct iio_buffer *r, | |||
108 | ret = kfifo_in(&kf->kf, data, 1); | 107 | ret = kfifo_in(&kf->kf, data, 1); |
109 | if (ret != 1) | 108 | if (ret != 1) |
110 | return -EBUSY; | 109 | return -EBUSY; |
111 | r->stufftoread = true; | 110 | |
112 | wake_up_interruptible_poll(&r->pollq, POLLIN | POLLRDNORM); | 111 | wake_up_interruptible_poll(&r->pollq, POLLIN | POLLRDNORM); |
113 | 112 | ||
114 | return 0; | 113 | return 0; |
@@ -127,13 +126,6 @@ static int iio_read_first_n_kfifo(struct iio_buffer *r, | |||
127 | ret = -EINVAL; | 126 | ret = -EINVAL; |
128 | else | 127 | else |
129 | ret = kfifo_to_user(&kf->kf, buf, n, &copied); | 128 | ret = kfifo_to_user(&kf->kf, buf, n, &copied); |
130 | |||
131 | if (kfifo_is_empty(&kf->kf)) | ||
132 | r->stufftoread = false; | ||
133 | /* verify it is still empty to avoid race */ | ||
134 | if (!kfifo_is_empty(&kf->kf)) | ||
135 | r->stufftoread = true; | ||
136 | |||
137 | mutex_unlock(&kf->user_lock); | 129 | mutex_unlock(&kf->user_lock); |
138 | if (ret < 0) | 130 | if (ret < 0) |
139 | return ret; | 131 | return ret; |
@@ -141,6 +133,18 @@ static int iio_read_first_n_kfifo(struct iio_buffer *r, | |||
141 | return copied; | 133 | return copied; |
142 | } | 134 | } |
143 | 135 | ||
136 | static bool iio_kfifo_buf_data_available(struct iio_buffer *r) | ||
137 | { | ||
138 | struct iio_kfifo *kf = iio_to_kfifo(r); | ||
139 | bool empty; | ||
140 | |||
141 | mutex_lock(&kf->user_lock); | ||
142 | empty = kfifo_is_empty(&kf->kf); | ||
143 | mutex_unlock(&kf->user_lock); | ||
144 | |||
145 | return !empty; | ||
146 | } | ||
147 | |||
144 | static void iio_kfifo_buffer_release(struct iio_buffer *buffer) | 148 | static void iio_kfifo_buffer_release(struct iio_buffer *buffer) |
145 | { | 149 | { |
146 | struct iio_kfifo *kf = iio_to_kfifo(buffer); | 150 | struct iio_kfifo *kf = iio_to_kfifo(buffer); |
@@ -153,6 +157,7 @@ static void iio_kfifo_buffer_release(struct iio_buffer *buffer) | |||
153 | static const struct iio_buffer_access_funcs kfifo_access_funcs = { | 157 | static const struct iio_buffer_access_funcs kfifo_access_funcs = { |
154 | .store_to = &iio_store_to_kfifo, | 158 | .store_to = &iio_store_to_kfifo, |
155 | .read_first_n = &iio_read_first_n_kfifo, | 159 | .read_first_n = &iio_read_first_n_kfifo, |
160 | .data_available = iio_kfifo_buf_data_available, | ||
156 | .request_update = &iio_request_update_kfifo, | 161 | .request_update = &iio_request_update_kfifo, |
157 | .get_bytes_per_datum = &iio_get_bytes_per_datum_kfifo, | 162 | .get_bytes_per_datum = &iio_get_bytes_per_datum_kfifo, |
158 | .set_bytes_per_datum = &iio_set_bytes_per_datum_kfifo, | 163 | .set_bytes_per_datum = &iio_set_bytes_per_datum_kfifo, |