Commit 5b78e5138e6a636d00fea08514bfc5a2ff5dfb15
Committed by
Jonathan Cameron
1 parent
0894d80dfd
Exists in
master
and in
16 other branches
iio:kfifo: Empty buffer on update
The kfifo's request_update callback will free the current buffer and allocate a new one if the size has changed. This will remove any samples that might still be left in the buffer. If the size has not changed the buffer content is left untouched though. This is a bit inconsistent and might cause an application to see data from a previous capture. This patch inserts a call to kfifo_reset_out() when the size did not change. This makes sure that any pending samples are removed from the buffer. Note, due to a different bug the buffer is currently always re-allocated, even if the size did not change. So this patch will not change the behavior. In the next patch the bug will be fixed and this patch makes sure that the current behavior is kept. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Showing 1 changed file with 7 additions and 5 deletions Side-by-side Diff
drivers/iio/kfifo_buf.c
... | ... | @@ -33,15 +33,17 @@ |
33 | 33 | int ret = 0; |
34 | 34 | struct iio_kfifo *buf = iio_to_kfifo(r); |
35 | 35 | |
36 | - if (!buf->update_needed) | |
37 | - goto error_ret; | |
38 | 36 | mutex_lock(&buf->user_lock); |
39 | - kfifo_free(&buf->kf); | |
40 | - ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum, | |
37 | + if (buf->update_needed) { | |
38 | + kfifo_free(&buf->kf); | |
39 | + ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum, | |
41 | 40 | buf->buffer.length); |
41 | + } else { | |
42 | + kfifo_reset_out(&buf->kf); | |
43 | + } | |
42 | 44 | r->stufftoread = false; |
43 | 45 | mutex_unlock(&buf->user_lock); |
44 | -error_ret: | |
46 | + | |
45 | 47 | return ret; |
46 | 48 | } |
47 | 49 |