Re: [PATCH 1/3] crypto: stm32/cryp - use dma when possible.
From: kernel test robot
Date: Mon Apr 22 2024 - 08:22:06 EST
Hi Maxime,
kernel test robot noticed the following build warnings:
[auto build test WARNING on atorgue-stm32/stm32-next]
[also build test WARNING on herbert-crypto-2.6/master herbert-cryptodev-2.6/master linus/master v6.9-rc5 next-20240422]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Maxime-MERE/crypto-stm32-cryp-use-dma-when-possible/20240418-224748
base: https://git.kernel.org/pub/scm/linux/kernel/git/atorgue/stm32.git stm32-next
patch link: https://lore.kernel.org/r/20240418144256.3736800-2-maxime.mere%40foss.st.com
patch subject: [PATCH 1/3] crypto: stm32/cryp - use dma when possible.
config: arm-randconfig-r081-20240422 (https://download.01.org/0day-ci/archive/20240422/202404222021.S9hjJBpb-lkp@xxxxxxxxx/config)
compiler: arm-linux-gnueabi-gcc (GCC) 13.2.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202404222021.S9hjJBpb-lkp@xxxxxxxxx/
smatch warnings:
drivers/crypto/stm32/stm32-cryp.c:1496 stm32_cryp_truncate_sg() warn: unsigned 'alloc_sg_len' is never less than zero.
drivers/crypto/stm32/stm32-cryp.c:1580 stm32_cryp_cipher_prepare() warn: unsigned 'cryp->in_sg_len' is never less than zero.
drivers/crypto/stm32/stm32-cryp.c:1584 stm32_cryp_cipher_prepare() warn: unsigned 'cryp->out_sg_len' is never less than zero.
vim +/alloc_sg_len +1496 drivers/crypto/stm32/stm32-cryp.c
1481
1482 static int stm32_cryp_truncate_sg(struct scatterlist **new_sg, size_t *new_sg_len,
1483 struct scatterlist *sg, off_t skip, size_t size)
1484 {
1485 struct scatterlist *cur;
1486 size_t alloc_sg_len;
1487
1488 *new_sg_len = 0;
1489
1490 if (!sg || !size) {
1491 *new_sg = NULL;
1492 return 0;
1493 }
1494
1495 alloc_sg_len = sg_nents_for_len(sg, skip + size);
> 1496 if (alloc_sg_len < 0)
1497 return alloc_sg_len;
1498
1499 /* We allocate to much sg entry, but it is easier */
1500 *new_sg = kmalloc_array(alloc_sg_len, sizeof(struct scatterlist), GFP_KERNEL);
1501 if (!*new_sg)
1502 return -ENOMEM;
1503
1504 sg_init_table(*new_sg, alloc_sg_len);
1505
1506 cur = *new_sg;
1507 while (sg && size) {
1508 unsigned int len = sg->length;
1509 unsigned int offset = sg->offset;
1510
1511 if (skip > len) {
1512 skip -= len;
1513 sg = sg_next(sg);
1514 continue;
1515 }
1516
1517 if (skip) {
1518 len -= skip;
1519 offset += skip;
1520 skip = 0;
1521 }
1522
1523 if (size < len)
1524 len = size;
1525
1526 if (len > 0) {
1527 (*new_sg_len)++;
1528 size -= len;
1529 sg_set_page(cur, sg_page(sg), len, offset);
1530 if (size == 0)
1531 sg_mark_end(cur);
1532 cur = sg_next(cur);
1533 }
1534
1535 sg = sg_next(sg);
1536 }
1537
1538 return 0;
1539 }
1540
1541 static int stm32_cryp_cipher_prepare(struct stm32_cryp *cryp, struct scatterlist *in_sg,
1542 struct scatterlist *out_sg)
1543 {
1544 size_t align_size;
1545
1546 cryp->dma_mode = stm32_cryp_dma_check(cryp, in_sg, out_sg);
1547
1548 scatterwalk_start(&cryp->in_walk, in_sg);
1549 scatterwalk_start(&cryp->out_walk, out_sg);
1550
1551 if (cryp->dma_mode == NO_DMA) {
1552 cryp->flags &= ~FLG_IN_OUT_DMA;
1553
1554 if (is_ctr(cryp))
1555 memset(cryp->last_ctr, 0, sizeof(cryp->last_ctr));
1556
1557 } else if (cryp->dma_mode == DMA_NEED_SG_TRUNC) {
1558 int ret;
1559
1560 cryp->flags |= FLG_IN_OUT_DMA;
1561
1562 align_size = ALIGN_DOWN(cryp->payload_in, cryp->hw_blocksize);
1563 ret = stm32_cryp_truncate_sg(&cryp->in_sg, &cryp->in_sg_len, in_sg, 0, align_size);
1564 if (ret)
1565 return ret;
1566
1567 ret = stm32_cryp_truncate_sg(&cryp->out_sg, &cryp->out_sg_len, out_sg, 0,
1568 align_size);
1569 if (ret) {
1570 kfree(cryp->in_sg);
1571 return ret;
1572 }
1573 } else {
1574 cryp->flags |= FLG_IN_OUT_DMA;
1575
1576 cryp->in_sg = in_sg;
1577 cryp->out_sg = out_sg;
1578
1579 cryp->in_sg_len = sg_nents_for_len(cryp->in_sg, cryp->payload_in);
> 1580 if (cryp->in_sg_len < 0)
1581 return cryp->in_sg_len;
1582
1583 cryp->out_sg_len = sg_nents_for_len(out_sg, cryp->payload_out);
> 1584 if (cryp->out_sg_len < 0)
1585 return cryp->out_sg_len;
1586 }
1587
1588 return 0;
1589 }
1590
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki