-----Original Message-----
From: kernel test robot <lkp(a)intel.com>
Sent: Wednesday, February 17, 2021 6:21 PM
To: Lars-Peter Clausen <lars(a)metafoo.de>
Cc: kbuild-all(a)lists.01.org; Jonathan Cameron
<Jonathan.Cameron(a)huawei.com>; Ardelean, Alexandru
<alexandru.Ardelean(a)analog.com>
Subject: [iio:testing 47/53] drivers/iio/buffer/industrialio-buffer-dma.c:669
iio_dma_buffer_alloc_blocks() warn: always true condition '(i >= 0) => (0-
u32max >= 0)'
[External]
tree:
https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/g...
23/iio.git__;!!A3Ni8CS0y2Y!r0vJx0FTiLi3bS6LugAUkUV4m4kSgQvuRql4XvRJBxLk
EhqwktjO1ekJmXEVppxQ7ZPMsA$ testing
head: 0fd146b288591a8139220fec417dfc5652820480
commit: b9ad66ba4db6f349aa795ed59c3e42d4208844fa [47/53] iio: buffer-
dma: Add mmap support
config: x86_64-randconfig-m001-20210215 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp(a)intel.com>
smatch warnings:
drivers/iio/buffer/industrialio-buffer-dma.c:669 iio_dma_buffer_alloc_blocks()
warn: always true condition '(i >= 0) => (0-u32max >= 0)'
drivers/iio/buffer/industrialio-buffer-dma.c:669 iio_dma_buffer_alloc_blocks()
warn: always true condition '(i >= 0) => (0-u32max >= 0)'
vim +669 drivers/iio/buffer/industrialio-buffer-dma.c
603
604 int iio_dma_buffer_alloc_blocks(struct iio_buffer *buffer,
605 struct iio_buffer_block_alloc_req *req)
606 {
607 struct iio_dma_buffer_queue *queue =
iio_buffer_to_queue(buffer);
608 struct iio_dma_buffer_block **blocks;
609 unsigned int num_blocks;
610 unsigned int i;
611 int ret = 0;
612
613 mutex_lock(&queue->lock);
614
615 /*
616 * If the buffer is enabled and in fileio mode new blocks can't be
617 * allocated.
618 */
619 if (queue->fileio.enabled) {
620 ret = -EBUSY;
621 goto err_unlock;
622 }
623
624 /* Free memory that might be in use for fileio mode */
625 iio_dma_buffer_fileio_free(queue);
626
627 /* 64 blocks ought to be enough for anybody ;) */
628 if (req->count > 64 - queue->num_blocks)
629 req->count = 64 - queue->num_blocks;
630 if (req->size > iio_dma_buffer_max_block_size)
631 req->size = iio_dma_buffer_max_block_size;
632
633 req->id = queue->num_blocks;
634
635 if (req->count == 0 || req->size == 0) {
636 ret = 0;
637 goto err_unlock;
638 }
639
640 num_blocks = req->count + queue->num_blocks;
641
642 blocks = krealloc(queue->blocks, sizeof(*blocks) * num_blocks,
643 GFP_KERNEL);
644 if (!blocks) {
645 ret = -ENOMEM;
646 goto err_unlock;
647 }
648
649 for (i = queue->num_blocks; i < num_blocks; i++) {
650 blocks[i] = iio_dma_buffer_alloc_block(queue, req-
>size);
651 if (!blocks[i]) {
652 ret = -ENOMEM;
653 goto err_unwind;
654 }
655 blocks[i]->block.id = i;
656 blocks[i]->block.data.offset = queue->max_offset;
657 queue->max_offset += PAGE_ALIGN(req->size);
658 }
659
660 req->count = i - queue->num_blocks;
661 queue->num_blocks = i;
662 queue->blocks = blocks;
663
664 mutex_unlock(&queue->lock);
665
666 return 0;
667
668 err_unwind:
> 669 for (; i >= 0; i--)
Oh crap.
This is actually serious.
Will fix this
> 670 iio_buffer_block_put(blocks[i]);
> 671 kfree(blocks);
> 672 err_unlock:
> 673 mutex_unlock(&queue->lock);
> 674
> 675 return ret;
> 676 }
> 677 EXPORT_SYMBOL_GPL(iio_dma_buffer_alloc_blocks);
> 678
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
>
> all(a)lists.01.org__;!!A3Ni8CS0y2Y!r0vJx0FTiLi3bS6LugAUkUV4m4kSgQvuRql4Xv
> RJBxLkEhqwktjO1ekJmXEVppzqskxNkQ$