Re: [PATCH] crypto: qat - fix use of 'dma_map_single'

2021-03-04 Thread Dan Carpenter
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 
Reported-by: Dan Carpenter 

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 = 
_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(_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 Tang2021-03-01  749  blp = 
dma_map_single(dev, bufl, sz, DMA_TO_DEVICE);
^^
Initialized here.

54bc41cf4d0517 Hui Tang2021-03-01  750  if 
(unlikely(dma_mapping_error(dev, blp)))
54bc41cf4d0517 Hui Tang2021-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 = 

Re: [PATCH] crypto: qat - fix use of 'dma_map_single'

2021-03-01 Thread kernel test robot
Hi Hui,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on cryptodev/master]
[also build test WARNING on crypto/master v5.12-rc1 next-20210301]
[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]

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: x86_64-randconfig-a001-20210301 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 
5de09ef02e24d234d9fc0cd1c6dfe18a1bb784b0)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# 
https://github.com/0day-ci/linux/commit/54bc41cf4d0517cc36b01680dd2394a48f62da09
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Hui-Tang/crypto-qat-fix-use-of-dma_map_single/20210301-114717
git checkout 54bc41cf4d0517cc36b01680dd2394a48f62da09
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

>> drivers/crypto/qat/qat_common/qat_algs.c:744:7: warning: variable 'blp' is 
>> used uninitialized whenever 'if' condition is true 
>> [-Wsometimes-uninitialized]
   if (unlikely(dma_mapping_error(dev, bufl->bufers[y].addr)))
   ^~
   include/linux/compiler.h:78:22: note: expanded from macro 'unlikely'
   # define unlikely(x)__builtin_expect(!!(x), 0)
   ^~
   drivers/crypto/qat/qat_common/qat_algs.c:809:30: note: uninitialized use 
occurs here
   if (!dma_mapping_error(dev, blp))
   ^~~
   drivers/crypto/qat/qat_common/qat_algs.c:744:3: note: remove the 'if' if its 
condition is always false
   if (unlikely(dma_mapping_error(dev, bufl->bufers[y].addr)))
   ^~~
   drivers/crypto/qat/qat_common/qat_algs.c:721:16: note: initialize the 
variable 'blp' to silence this warning
   dma_addr_t blp;
 ^
  = 0
   1 warning generated.


vim +744 drivers/crypto/qat/qat_common/qat_algs.c

d370cec3219490 Tadeusz Struk   2014-06-05  710  
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 = 
_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(_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