Skip to content

Commit ea191d0

Browse files
GONG, Ruiqijic23
authored andcommitted
iio: irsd200: fix -Warray-bounds bug in irsd200_trigger_handler
When compiling with gcc 13 with -Warray-bounds enabled: In file included from drivers/iio/proximity/irsd200.c:15: In function ‘iio_push_to_buffers_with_timestamp’, inlined from ‘irsd200_trigger_handler’ at drivers/iio/proximity/irsd200.c:770:2: ./include/linux/iio/buffer.h:42:46: error: array subscript ‘int64_t {aka long long int}[0]’ is partly outside array bounds of ‘s16[1]’ {aka ‘short int[1]’} [-Werror=array-bounds=] 42 | ((int64_t *)data)[ts_offset] = timestamp; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~ drivers/iio/proximity/irsd200.c: In function ‘irsd200_trigger_handler’: drivers/iio/proximity/irsd200.c:763:13: note: object ‘buf’ of size 2 763 | s16 buf = 0; | ^~~ The problem seems to be that irsd200_trigger_handler() is taking a s16 variable as an int64_t buffer. As Jonathan suggested [1], fix it by extending the buffer to a two-element array of s64. Link: KSPP#331 Link: https://lore.kernel.org/lkml/20230809181329.46c00a5d@jic23-huawei/ [1] Fixes: 3db3562 ("iio: Add driver for Murata IRS-D200") Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com> Acked-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Waqar Hameed <waqar.hameed@axis.com> Tested-by: Waqar Hameed <waqar.hameed@axis.com> Reviewed-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230810035910.1334706-1-gongruiqi@huaweicloud.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent c6fd912 commit ea191d0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/iio/proximity/irsd200.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -759,14 +759,14 @@ static irqreturn_t irsd200_trigger_handler(int irq, void *pollf)
759759
{
760760
struct iio_dev *indio_dev = ((struct iio_poll_func *)pollf)->indio_dev;
761761
struct irsd200_data *data = iio_priv(indio_dev);
762-
s16 buf = 0;
762+
s64 buf[2] = {};
763763
int ret;
764764

765-
ret = irsd200_read_data(data, &buf);
765+
ret = irsd200_read_data(data, (s16 *)buf);
766766
if (ret)
767767
goto end;
768768

769-
iio_push_to_buffers_with_timestamp(indio_dev, &buf,
769+
iio_push_to_buffers_with_timestamp(indio_dev, buf,
770770
iio_get_time_ns(indio_dev));
771771

772772
end:

0 commit comments

Comments
 (0)