Commit 1858d0f3 authored by Martin Kelly's avatar Martin Kelly Committed by Stefan Bader

iio:buffer: make length types match kfifo types

BugLink: https://bugs.launchpad.net/bugs/1784382

commit c043ec1c upstream.

Currently, we use int for buffer length and bytes_per_datum. However,
kfifo uses unsigned int for length and size_t for element size. We need
to make sure these matches or we will have bugs related to overflow (in
the range between INT_MAX and UINT_MAX for length, for example).

In addition, set_bytes_per_datum uses size_t while bytes_per_datum is an
int, which would cause bugs for large values of bytes_per_datum.

Change buffer length to use unsigned int and bytes_per_datum to use
size_t.
Signed-off-by: default avatarMartin Kelly <mkelly@xevo.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
[bwh: Backported to 4.4:
 - Drop change to iio_dma_buffer_set_length()
 - Adjust filename, context]
Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent d04e33b7
...@@ -19,7 +19,7 @@ struct iio_kfifo { ...@@ -19,7 +19,7 @@ struct iio_kfifo {
#define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer) #define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer)
static inline int __iio_allocate_kfifo(struct iio_kfifo *buf, static inline int __iio_allocate_kfifo(struct iio_kfifo *buf,
int bytes_per_datum, int length) size_t bytes_per_datum, unsigned int length)
{ {
if ((length == 0) || (bytes_per_datum == 0)) if ((length == 0) || (bytes_per_datum == 0))
return -EINVAL; return -EINVAL;
...@@ -71,7 +71,7 @@ static int iio_set_bytes_per_datum_kfifo(struct iio_buffer *r, size_t bpd) ...@@ -71,7 +71,7 @@ static int iio_set_bytes_per_datum_kfifo(struct iio_buffer *r, size_t bpd)
return 0; return 0;
} }
static int iio_set_length_kfifo(struct iio_buffer *r, int length) static int iio_set_length_kfifo(struct iio_buffer *r, unsigned int length)
{ {
/* Avoid an invalid state */ /* Avoid an invalid state */
if (length < 2) if (length < 2)
......
...@@ -49,7 +49,7 @@ struct iio_buffer_access_funcs { ...@@ -49,7 +49,7 @@ struct iio_buffer_access_funcs {
int (*request_update)(struct iio_buffer *buffer); int (*request_update)(struct iio_buffer *buffer);
int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd);
int (*set_length)(struct iio_buffer *buffer, int length); int (*set_length)(struct iio_buffer *buffer, unsigned int length);
void (*release)(struct iio_buffer *buffer); void (*release)(struct iio_buffer *buffer);
...@@ -78,8 +78,8 @@ struct iio_buffer_access_funcs { ...@@ -78,8 +78,8 @@ struct iio_buffer_access_funcs {
* @watermark: [INTERN] number of datums to wait for poll/read. * @watermark: [INTERN] number of datums to wait for poll/read.
*/ */
struct iio_buffer { struct iio_buffer {
int length; unsigned int length;
int bytes_per_datum; size_t bytes_per_datum;
struct attribute_group *scan_el_attrs; struct attribute_group *scan_el_attrs;
long *scan_mask; long *scan_mask;
bool scan_timestamp; bool scan_timestamp;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment