[leon-rdma:dma-static-calls-v1 2/2] kernel/dma/mapping.c:746:12: warning: variable 'sgt' is used uninitialized whenever 'if' condition is false

kernel test robot
2024-07-14T19:24:26Z

tree: https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git dma-static-calls-v1
head: 3acafa88e3e0ffeb1d7d2ae1e78d5c669edb55b6
commit: 3acafa88e3e0ffeb1d7d2ae1e78d5c669edb55b6 [2/2] dma: Add IOMMU static calls with clear default ops
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20240715/202407150312.GTJusNmx-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240715/202407150312.GTJusNmx-lkp@intel.com/reproduce)

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@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202407150312.GTJusNmx-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> kernel/dma/mapping.c:746:12: warning: variable 'sgt' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
746 | else if (ops->alloc_noncontiguous)
| ^~~~~~~~~~~~~~~~~~~~~~~~
kernel/dma/mapping.c:753:6: note: uninitialized use occurs here
753 | if (sgt) {
| ^~~
kernel/dma/mapping.c:746:8: note: remove the 'if' if its condition is always true
746 | else if (ops->alloc_noncontiguous)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
747 | sgt = ops->alloc_noncontiguous(dev, size, dir, gfp,
kernel/dma/mapping.c:735:22: note: initialize the variable 'sgt' to silence this warning
735 | struct sg_table *sgt;
| ^
| = NULL
1 warning generated.

vim +746 kernel/dma/mapping.c

730
731 struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size,
732 enum dma_data_direction dir, gfp_t gfp, unsigned long attrs)
733 {
734 const struct dma_map_ops *ops = get_dma_ops(dev);
735 struct sg_table *sgt;
736
737 if (WARN_ON_ONCE(attrs & ~DMA_ATTR_ALLOC_SINGLE_PAGES))
738 return NULL;
739 if (WARN_ON_ONCE(gfp & __GFP_COMP))
740 return NULL;
741
742 if (ops) {
743 if (dma_is_default_iommu(ops))
744 sgt = iommu_dma_alloc_noncontiguous(dev, size, dir, gfp,
745 attrs);
> 746 else if (ops->alloc_noncontiguous)
747 sgt = ops->alloc_noncontiguous(dev, size, dir, gfp,
748 attrs);
749 }
750 else
751 sgt = alloc_single_sgt(dev, size, dir, gfp);
752
753 if (sgt) {
754 sgt->nents = 1;
755 debug_dma_map_sg(dev, sgt->sgl, sgt->orig_nents, 1, dir, attrs);
756 }
757 return sgt;
758 }
759 EXPORT_SYMBOL_GPL(dma_alloc_noncontiguous);
760

--
0-DAY CI Kernel Test Service