Message ID | 1614570058-38194-1-git-send-email-tanghui20@huawei.com |
---|---|
State | Accepted |
Commit | 7cc05071f930a631040fea16a41f9d78771edc49 |
Headers | show |
Series | crypto: qat - fix use of 'dma_map_single' | expand |
Hi Hui, url: https://github.com/0day-ci/linux/commits/Hui-Tang/crypto-qat-fix-use-of-dma_map_single/20210301-114717 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master config: i386-randconfig-m021-20210304 (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> smatch warnings: drivers/crypto/qat/qat_common/qat_algs.c:809 qat_alg_sgl_to_bufl() error: uninitialized symbol 'blp'. vim +/blp +809 drivers/crypto/qat/qat_common/qat_algs.c d370cec3219490 Tadeusz Struk 2014-06-05 711 static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, d370cec3219490 Tadeusz Struk 2014-06-05 712 struct scatterlist *sgl, e19ab1211d2848 Herbert Xu 2015-07-30 713 struct scatterlist *sglout, d370cec3219490 Tadeusz Struk 2014-06-05 714 struct qat_crypto_request *qat_req) d370cec3219490 Tadeusz Struk 2014-06-05 715 { d370cec3219490 Tadeusz Struk 2014-06-05 716 struct device *dev = &GET_DEV(inst->accel_dev); e19ab1211d2848 Herbert Xu 2015-07-30 717 int i, sg_nctr = 0; e19ab1211d2848 Herbert Xu 2015-07-30 718 int n = sg_nents(sgl); d370cec3219490 Tadeusz Struk 2014-06-05 719 struct qat_alg_buf_list *bufl; d370cec3219490 Tadeusz Struk 2014-06-05 720 struct qat_alg_buf_list *buflout = NULL; d370cec3219490 Tadeusz Struk 2014-06-05 721 dma_addr_t blp; ^^^^^^^^^^^^^^ d370cec3219490 Tadeusz Struk 2014-06-05 722 dma_addr_t bloutp = 0; d370cec3219490 Tadeusz Struk 2014-06-05 723 struct scatterlist *sg; 1793d1aba19415 Gustavo A. R. Silva 2019-06-06 724 size_t sz_out, sz = struct_size(bufl, bufers, n + 1); d370cec3219490 Tadeusz Struk 2014-06-05 725 d370cec3219490 Tadeusz Struk 2014-06-05 726 if (unlikely(!n)) d370cec3219490 Tadeusz Struk 2014-06-05 727 return -EINVAL; d370cec3219490 Tadeusz Struk 2014-06-05 728 82f82504b8f5f1 Tadeusz Struk 2014-12-08 729 bufl = kzalloc_node(sz, GFP_ATOMIC, 09adc8789c4e89 Tadeusz Struk 2014-10-13 730 dev_to_node(&GET_DEV(inst->accel_dev))); d370cec3219490 Tadeusz Struk 2014-06-05 731 if (unlikely(!bufl)) d370cec3219490 Tadeusz Struk 2014-06-05 732 return -ENOMEM; d370cec3219490 Tadeusz Struk 2014-06-05 733 d370cec3219490 Tadeusz Struk 2014-06-05 734 for_each_sg(sgl, sg, n, i) { e19ab1211d2848 Herbert Xu 2015-07-30 735 int y = sg_nctr; 82f82504b8f5f1 Tadeusz Struk 2014-12-08 736 82f82504b8f5f1 Tadeusz Struk 2014-12-08 737 if (!sg->length) 82f82504b8f5f1 Tadeusz Struk 2014-12-08 738 continue; d65071ecde1ed1 Tadeusz Struk 2014-06-24 739 d370cec3219490 Tadeusz Struk 2014-06-05 740 bufl->bufers[y].addr = dma_map_single(dev, sg_virt(sg), d370cec3219490 Tadeusz Struk 2014-06-05 741 sg->length, d370cec3219490 Tadeusz Struk 2014-06-05 742 DMA_BIDIRECTIONAL); d370cec3219490 Tadeusz Struk 2014-06-05 743 bufl->bufers[y].len = sg->length; d370cec3219490 Tadeusz Struk 2014-06-05 744 if (unlikely(dma_mapping_error(dev, bufl->bufers[y].addr))) 72eed063767e13 Arnd Bergmann 2017-06-22 745 goto err_in; "blp" uninitialized at this goto. 82f82504b8f5f1 Tadeusz Struk 2014-12-08 746 sg_nctr++; d370cec3219490 Tadeusz Struk 2014-06-05 747 } e19ab1211d2848 Herbert Xu 2015-07-30 748 bufl->num_bufs = sg_nctr; 54bc41cf4d0517 Hui Tang 2021-03-01 749 blp = dma_map_single(dev, bufl, sz, DMA_TO_DEVICE); ^^^^^^ Initialized here. 54bc41cf4d0517 Hui Tang 2021-03-01 750 if (unlikely(dma_mapping_error(dev, blp))) 54bc41cf4d0517 Hui Tang 2021-03-01 751 goto err_in; d370cec3219490 Tadeusz Struk 2014-06-05 752 qat_req->buf.bl = bufl; d370cec3219490 Tadeusz Struk 2014-06-05 753 qat_req->buf.blp = blp; d370cec3219490 Tadeusz Struk 2014-06-05 754 qat_req->buf.sz = sz; d370cec3219490 Tadeusz Struk 2014-06-05 755 /* Handle out of place operation */ d370cec3219490 Tadeusz Struk 2014-06-05 756 if (sgl != sglout) { d370cec3219490 Tadeusz Struk 2014-06-05 757 struct qat_alg_buf *bufers; d370cec3219490 Tadeusz Struk 2014-06-05 758 82f82504b8f5f1 Tadeusz Struk 2014-12-08 759 n = sg_nents(sglout); 1793d1aba19415 Gustavo A. R. Silva 2019-06-06 760 sz_out = struct_size(buflout, bufers, n + 1); 82f82504b8f5f1 Tadeusz Struk 2014-12-08 761 sg_nctr = 0; 82f82504b8f5f1 Tadeusz Struk 2014-12-08 762 buflout = kzalloc_node(sz_out, GFP_ATOMIC, 09adc8789c4e89 Tadeusz Struk 2014-10-13 763 dev_to_node(&GET_DEV(inst->accel_dev))); d370cec3219490 Tadeusz Struk 2014-06-05 764 if (unlikely(!buflout)) 72eed063767e13 Arnd Bergmann 2017-06-22 765 goto err_in; d370cec3219490 Tadeusz Struk 2014-06-05 766 bufers = buflout->bufers; d370cec3219490 Tadeusz Struk 2014-06-05 767 for_each_sg(sglout, sg, n, i) { e19ab1211d2848 Herbert Xu 2015-07-30 768 int y = sg_nctr; 82f82504b8f5f1 Tadeusz Struk 2014-12-08 769 82f82504b8f5f1 Tadeusz Struk 2014-12-08 770 if (!sg->length) 82f82504b8f5f1 Tadeusz Struk 2014-12-08 771 continue; d65071ecde1ed1 Tadeusz Struk 2014-06-24 772 d370cec3219490 Tadeusz Struk 2014-06-05 773 bufers[y].addr = dma_map_single(dev, sg_virt(sg), d370cec3219490 Tadeusz Struk 2014-06-05 774 sg->length, d370cec3219490 Tadeusz Struk 2014-06-05 775 DMA_BIDIRECTIONAL); d370cec3219490 Tadeusz Struk 2014-06-05 776 if (unlikely(dma_mapping_error(dev, bufers[y].addr))) 72eed063767e13 Arnd Bergmann 2017-06-22 777 goto err_out; 82f82504b8f5f1 Tadeusz Struk 2014-12-08 778 bufers[y].len = sg->length; 82f82504b8f5f1 Tadeusz Struk 2014-12-08 779 sg_nctr++; d370cec3219490 Tadeusz Struk 2014-06-05 780 } e19ab1211d2848 Herbert Xu 2015-07-30 781 buflout->num_bufs = sg_nctr; 82f82504b8f5f1 Tadeusz Struk 2014-12-08 782 buflout->num_mapped_bufs = sg_nctr; 54bc41cf4d0517 Hui Tang 2021-03-01 783 bloutp = dma_map_single(dev, buflout, sz_out, DMA_TO_DEVICE); 54bc41cf4d0517 Hui Tang 2021-03-01 784 if (unlikely(dma_mapping_error(dev, bloutp))) 54bc41cf4d0517 Hui Tang 2021-03-01 785 goto err_out; d370cec3219490 Tadeusz Struk 2014-06-05 786 qat_req->buf.blout = buflout; d370cec3219490 Tadeusz Struk 2014-06-05 787 qat_req->buf.bloutp = bloutp; 82f82504b8f5f1 Tadeusz Struk 2014-12-08 788 qat_req->buf.sz_out = sz_out; d370cec3219490 Tadeusz Struk 2014-06-05 789 } else { d370cec3219490 Tadeusz Struk 2014-06-05 790 /* Otherwise set the src and dst to the same address */ d370cec3219490 Tadeusz Struk 2014-06-05 791 qat_req->buf.bloutp = qat_req->buf.blp; 82f82504b8f5f1 Tadeusz Struk 2014-12-08 792 qat_req->buf.sz_out = 0; d370cec3219490 Tadeusz Struk 2014-06-05 793 } d370cec3219490 Tadeusz Struk 2014-06-05 794 return 0; 82f82504b8f5f1 Tadeusz Struk 2014-12-08 795 72eed063767e13 Arnd Bergmann 2017-06-22 796 err_out: 54bc41cf4d0517 Hui Tang 2021-03-01 797 if (!dma_mapping_error(dev, bloutp)) 54bc41cf4d0517 Hui Tang 2021-03-01 798 dma_unmap_single(dev, bloutp, sz_out, DMA_TO_DEVICE); 54bc41cf4d0517 Hui Tang 2021-03-01 799 82f82504b8f5f1 Tadeusz Struk 2014-12-08 800 n = sg_nents(sglout); e19ab1211d2848 Herbert Xu 2015-07-30 801 for (i = 0; i < n; i++) 82f82504b8f5f1 Tadeusz Struk 2014-12-08 802 if (!dma_mapping_error(dev, buflout->bufers[i].addr)) 82f82504b8f5f1 Tadeusz Struk 2014-12-08 803 dma_unmap_single(dev, buflout->bufers[i].addr, 82f82504b8f5f1 Tadeusz Struk 2014-12-08 804 buflout->bufers[i].len, d370cec3219490 Tadeusz Struk 2014-06-05 805 DMA_BIDIRECTIONAL); d370cec3219490 Tadeusz Struk 2014-06-05 806 kfree(buflout); 72eed063767e13 Arnd Bergmann 2017-06-22 807 72eed063767e13 Arnd Bergmann 2017-06-22 808 err_in: 54bc41cf4d0517 Hui Tang 2021-03-01 @809 if (!dma_mapping_error(dev, blp)) ^^^ Uninitialized. 54bc41cf4d0517 Hui Tang 2021-03-01 810 dma_unmap_single(dev, blp, sz, DMA_TO_DEVICE); 54bc41cf4d0517 Hui Tang 2021-03-01 811 72eed063767e13 Arnd Bergmann 2017-06-22 812 n = sg_nents(sgl); 72eed063767e13 Arnd Bergmann 2017-06-22 813 for (i = 0; i < n; i++) 72eed063767e13 Arnd Bergmann 2017-06-22 814 if (!dma_mapping_error(dev, bufl->bufers[i].addr)) 72eed063767e13 Arnd Bergmann 2017-06-22 815 dma_unmap_single(dev, bufl->bufers[i].addr, 72eed063767e13 Arnd Bergmann 2017-06-22 816 bufl->bufers[i].len, 72eed063767e13 Arnd Bergmann 2017-06-22 817 DMA_BIDIRECTIONAL); 72eed063767e13 Arnd Bergmann 2017-06-22 818 72eed063767e13 Arnd Bergmann 2017-06-22 819 kfree(bufl); 72eed063767e13 Arnd Bergmann 2017-06-22 820 72eed063767e13 Arnd Bergmann 2017-06-22 821 dev_err(dev, "Failed to map buf for dma\n"); d370cec3219490 Tadeusz Struk 2014-06-05 822 return -ENOMEM; d370cec3219490 Tadeusz Struk 2014-06-05 823 } --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff --git a/drivers/crypto/qat/qat_common/qat_algs.c b/drivers/crypto/qat/qat_common/qat_algs.c index ff78c73..e88c534 100644 --- a/drivers/crypto/qat/qat_common/qat_algs.c +++ b/drivers/crypto/qat/qat_common/qat_algs.c @@ -731,10 +731,6 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, if (unlikely(!bufl)) return -ENOMEM; - blp = dma_map_single(dev, bufl, sz, DMA_TO_DEVICE); - if (unlikely(dma_mapping_error(dev, blp))) - goto err_in; - for_each_sg(sgl, sg, n, i) { int y = sg_nctr; @@ -750,6 +746,9 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, sg_nctr++; } bufl->num_bufs = sg_nctr; + blp = dma_map_single(dev, bufl, sz, DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(dev, blp))) + goto err_in; qat_req->buf.bl = bufl; qat_req->buf.blp = blp; qat_req->buf.sz = sz; @@ -764,9 +763,6 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, dev_to_node(&GET_DEV(inst->accel_dev))); if (unlikely(!buflout)) goto err_in; - bloutp = dma_map_single(dev, buflout, sz_out, DMA_TO_DEVICE); - if (unlikely(dma_mapping_error(dev, bloutp))) - goto err_out; bufers = buflout->bufers; for_each_sg(sglout, sg, n, i) { int y = sg_nctr; @@ -784,6 +780,9 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, } buflout->num_bufs = sg_nctr; buflout->num_mapped_bufs = sg_nctr; + bloutp = dma_map_single(dev, buflout, sz_out, DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(dev, bloutp))) + goto err_out; qat_req->buf.blout = buflout; qat_req->buf.bloutp = bloutp; qat_req->buf.sz_out = sz_out; @@ -795,17 +794,21 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, return 0; err_out: + if (!dma_mapping_error(dev, bloutp)) + dma_unmap_single(dev, bloutp, sz_out, DMA_TO_DEVICE); + n = sg_nents(sglout); for (i = 0; i < n; i++) if (!dma_mapping_error(dev, buflout->bufers[i].addr)) dma_unmap_single(dev, buflout->bufers[i].addr, buflout->bufers[i].len, DMA_BIDIRECTIONAL); - if (!dma_mapping_error(dev, bloutp)) - dma_unmap_single(dev, bloutp, sz_out, DMA_TO_DEVICE); kfree(buflout); err_in: + if (!dma_mapping_error(dev, blp)) + dma_unmap_single(dev, blp, sz, DMA_TO_DEVICE); + n = sg_nents(sgl); for (i = 0; i < n; i++) if (!dma_mapping_error(dev, bufl->bufers[i].addr)) @@ -813,8 +816,6 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, bufl->bufers[i].len, DMA_BIDIRECTIONAL); - if (!dma_mapping_error(dev, blp)) - dma_unmap_single(dev, blp, sz, DMA_TO_DEVICE); kfree(bufl); dev_err(dev, "Failed to map buf for dma\n");
DMA_TO_DEVICE synchronisation must be done after the last modification of the memory region by the software and before it is handed off to the device. Signed-off-by: Hui Tang <tanghui20@huawei.com> --- drivers/crypto/qat/qat_common/qat_algs.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)