summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/iio/buffer.h2
-rw-r--r--drivers/staging/iio/kfifo_buf.c6
2 files changed, 6 insertions, 2 deletions
diff --git a/drivers/staging/iio/buffer.h b/drivers/staging/iio/buffer.h
index c69709925ba2..44593b28b36f 100644
--- a/drivers/staging/iio/buffer.h
+++ b/drivers/staging/iio/buffer.h
@@ -21,7 +21,7 @@ struct iio_buffer;
* @mark_in_use: reference counting, typically to prevent module removal
* @unmark_in_use: reduce reference count when no longer using buffer
* @store_to: actually store stuff to the buffer
- * @read_first_n: try to get a specified number of elements (must exist)
+ * @read_first_n: try to get a specified number of bytes (must exist)
* @mark_param_change: notify buffer that some relevant parameter has changed
* Often this means the underlying storage may need to
* change.
diff --git a/drivers/staging/iio/kfifo_buf.c b/drivers/staging/iio/kfifo_buf.c
index d8867abd0a84..b69cca5e43ca 100644
--- a/drivers/staging/iio/kfifo_buf.c
+++ b/drivers/staging/iio/kfifo_buf.c
@@ -160,7 +160,11 @@ static int iio_read_first_n_kfifo(struct iio_buffer *r,
int ret, copied;
struct iio_kfifo *kf = iio_to_kfifo(r);
- ret = kfifo_to_user(&kf->kf, buf, r->bytes_per_datum*n, &copied);
+ if (n < r->bytes_per_datum)
+ return -EINVAL;
+
+ n = rounddown(n, r->bytes_per_datum);
+ ret = kfifo_to_user(&kf->kf, buf, n, &copied);
return copied;
}