Skip to content

Commit c043ec1

Browse files
Martin Kellyjic23
authored andcommitted
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 <[email protected]> Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent d58109d commit c043ec1

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

drivers/iio/buffer/industrialio-buffer-dma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ EXPORT_SYMBOL_GPL(iio_dma_buffer_set_bytes_per_datum);
587587
* Should be used as the set_length callback for iio_buffer_access_ops
588588
* struct for DMA buffers.
589589
*/
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)
591591
{
592592
/* Avoid an invalid state */
593593
if (length < 2)

drivers/iio/buffer/kfifo_buf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct iio_kfifo {
2222
#define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer)
2323

2424
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)
2626
{
2727
if ((length == 0) || (bytes_per_datum == 0))
2828
return -EINVAL;
@@ -67,7 +67,7 @@ static int iio_set_bytes_per_datum_kfifo(struct iio_buffer *r, size_t bpd)
6767
return 0;
6868
}
6969

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)
7171
{
7272
/* Avoid an invalid state */
7373
if (length < 2)

include/linux/iio/buffer_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct iio_buffer_access_funcs {
5353
int (*request_update)(struct iio_buffer *buffer);
5454

5555
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);
5757

5858
int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);
5959
int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);
@@ -72,10 +72,10 @@ struct iio_buffer_access_funcs {
7272
*/
7373
struct iio_buffer {
7474
/** @length: Number of datums in buffer. */
75-
int length;
75+
unsigned int length;
7676

7777
/** @bytes_per_datum: Size of individual datum including timestamp. */
78-
int bytes_per_datum;
78+
size_t bytes_per_datum;
7979

8080
/**
8181
* @access: Buffer access functions associated with the

0 commit comments

Comments
 (0)