1 From b119d3bc328e7a9574861ebe0c2110e2776c2de1 Mon Sep 17 00:00:00 2001
2 From: Martin Kelly <mkelly@xevo.com>
3 Date: Fri, 11 Jan 2019 23:13:09 +0000
4 Subject: tools: iio: iio_generic_buffer: make num_loops signed
6 From: Martin Kelly <mkelly@xevo.com>
8 commit b119d3bc328e7a9574861ebe0c2110e2776c2de1 upstream.
10 Currently, num_loops is unsigned, but it's set by strtoll, which returns a
11 (signed) long long int. This could lead to overflow, and it also makes the
12 check "num_loops < 0" always be false, since num_loops is unsigned.
13 Setting num_loops to -1 to loop forever is almost working because num_loops
14 is getting set to a very high number, but it's technically still incorrect.
16 Fix this issue by making num_loops signed. This also fixes an error found
19 Signed-off-by: Martin Kelly <mkelly@xevo.com>
20 Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
21 Fixes: 55dda0abcf9d ("tools: iio: iio_generic_buffer: allow continuous looping")
22 Cc: <Stable@vger.kernel.org>
23 Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
27 tools/iio/iio_generic_buffer.c | 2 +-
28 1 file changed, 1 insertion(+), 1 deletion(-)
30 --- a/tools/iio/iio_generic_buffer.c
31 +++ b/tools/iio/iio_generic_buffer.c
32 @@ -330,7 +330,7 @@ static const struct option longopts[] =
34 int main(int argc, char **argv)
36 - unsigned long long num_loops = 2;
37 + long long num_loops = 2;
38 unsigned long timedelay = 1000000;
39 unsigned long buf_len = 128;