diff options
author | Martin Kelly <mkelly@xevo.com> | 2018-03-26 17:27:51 -0400 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2018-03-30 06:14:32 -0400 |
commit | c043ec1ca5baae63726aae32abbe003192bc6eec (patch) | |
tree | 51574cd7d82dec8175c75f9f4498fd38fa8bb68d | |
parent | d58109dcf37fc9baec354385ec9fdcd8878d174d (diff) |
iio:buffer: make length types match kfifo types
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: Martin Kelly <mkelly@xevo.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r-- | drivers/iio/buffer/industrialio-buffer-dma.c | 2 | ||||
-rw-r--r-- | drivers/iio/buffer/kfifo_buf.c | 4 | ||||
-rw-r--r-- | include/linux/iio/buffer_impl.h | 6 |
3 files changed, 6 insertions, 6 deletions
diff --git a/drivers/iio/buffer/industrialio-buffer-dma.c b/drivers/iio/buffer/industrialio-buffer-dma.c index 05e0c353e089..b32bf57910ca 100644 --- a/drivers/iio/buffer/industrialio-buffer-dma.c +++ b/drivers/iio/buffer/industrialio-buffer-dma.c | |||
@@ -587,7 +587,7 @@ EXPORT_SYMBOL_GPL(iio_dma_buffer_set_bytes_per_datum); | |||
587 | * Should be used as the set_length callback for iio_buffer_access_ops | 587 | * Should be used as the set_length callback for iio_buffer_access_ops |
588 | * struct for DMA buffers. | 588 | * struct for DMA buffers. |
589 | */ | 589 | */ |
590 | int iio_dma_buffer_set_length(struct iio_buffer *buffer, int length) | 590 | int iio_dma_buffer_set_length(struct iio_buffer *buffer, unsigned int length) |
591 | { | 591 | { |
592 | /* Avoid an invalid state */ | 592 | /* Avoid an invalid state */ |
593 | if (length < 2) | 593 | if (length < 2) |
diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c index 047fe757ab97..ac622edf2486 100644 --- a/drivers/iio/buffer/kfifo_buf.c +++ b/drivers/iio/buffer/kfifo_buf.c | |||
@@ -22,7 +22,7 @@ struct iio_kfifo { | |||
22 | #define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer) | 22 | #define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer) |
23 | 23 | ||
24 | static inline int __iio_allocate_kfifo(struct iio_kfifo *buf, | 24 | static inline int __iio_allocate_kfifo(struct iio_kfifo *buf, |
25 | int bytes_per_datum, int length) | 25 | size_t bytes_per_datum, unsigned int length) |
26 | { | 26 | { |
27 | if ((length == 0) || (bytes_per_datum == 0)) | 27 | if ((length == 0) || (bytes_per_datum == 0)) |
28 | return -EINVAL; | 28 | return -EINVAL; |
@@ -67,7 +67,7 @@ static int iio_set_bytes_per_datum_kfifo(struct iio_buffer *r, size_t bpd) | |||
67 | return 0; | 67 | return 0; |
68 | } | 68 | } |
69 | 69 | ||
70 | static int iio_set_length_kfifo(struct iio_buffer *r, int length) | 70 | static int iio_set_length_kfifo(struct iio_buffer *r, unsigned int length) |
71 | { | 71 | { |
72 | /* Avoid an invalid state */ | 72 | /* Avoid an invalid state */ |
73 | if (length < 2) | 73 | if (length < 2) |
diff --git a/include/linux/iio/buffer_impl.h b/include/linux/iio/buffer_impl.h index b9e22b7e2f28..d1171db23742 100644 --- a/include/linux/iio/buffer_impl.h +++ b/include/linux/iio/buffer_impl.h | |||
@@ -53,7 +53,7 @@ struct iio_buffer_access_funcs { | |||
53 | int (*request_update)(struct iio_buffer *buffer); | 53 | int (*request_update)(struct iio_buffer *buffer); |
54 | 54 | ||
55 | int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); | 55 | int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); |
56 | int (*set_length)(struct iio_buffer *buffer, int length); | 56 | int (*set_length)(struct iio_buffer *buffer, unsigned int length); |
57 | 57 | ||
58 | int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); | 58 | int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); |
59 | int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); | 59 | int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); |
@@ -72,10 +72,10 @@ struct iio_buffer_access_funcs { | |||
72 | */ | 72 | */ |
73 | struct iio_buffer { | 73 | struct iio_buffer { |
74 | /** @length: Number of datums in buffer. */ | 74 | /** @length: Number of datums in buffer. */ |
75 | int length; | 75 | unsigned int length; |
76 | 76 | ||
77 | /** @bytes_per_datum: Size of individual datum including timestamp. */ | 77 | /** @bytes_per_datum: Size of individual datum including timestamp. */ |
78 | int bytes_per_datum; | 78 | size_t bytes_per_datum; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * @access: Buffer access functions associated with the | 81 | * @access: Buffer access functions associated with the |