All of lore.kernel.org
 help / color / mirror / Atom feed
* [leon-rdma:dmabuf-vfio 20/26] drivers/pci/p2pdma.c:378 pci_p2pdma_add_resource() error: uninitialized symbol 'mem'.
@ 2025-08-04  6:40 Dan Carpenter
  2025-08-04  7:01 ` Leon Romanovsky
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2025-08-04  6:40 UTC (permalink / raw)
  To: oe-kbuild, Leon Romanovsky; +Cc: lkp, oe-kbuild-all

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git dmabuf-vfio
head:   f4212771ee1cf899f5ac8c9b6acd3bb7f49691fc
commit: 906b14c15e3d67c3aa9031bc3fee805343fb75c6 [20/26] PCI/P2PDMA: Refactor to separate core P2P functionality from memory allocation
config: x86_64-randconfig-161-20250804 (https://download.01.org/0day-ci/archive/20250804/202508040847.0z9fDkel-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.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@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202508040847.0z9fDkel-lkp@intel.com/

smatch warnings:
drivers/pci/p2pdma.c:378 pci_p2pdma_add_resource() error: uninitialized symbol 'mem'.
drivers/pci/p2pdma.c:391 pci_p2pdma_add_resource() error: we previously assumed 'p2pdma' could be null (see line 356)

vim +/mem +378 drivers/pci/p2pdma.c

52916982af48d9 Logan Gunthorpe   2018-10-04  333  int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
52916982af48d9 Logan Gunthorpe   2018-10-04  334  			    u64 offset)
52916982af48d9 Logan Gunthorpe   2018-10-04  335  {
a6e6fe6549f609 Logan Gunthorpe   2019-08-12  336  	struct pci_p2pdma_pagemap *p2p_pgmap;
906b14c15e3d67 Leon Romanovsky   2025-07-16  337  	struct p2pdma_provider *mem;
52916982af48d9 Logan Gunthorpe   2018-10-04  338  	struct dev_pagemap *pgmap;
ae21f835a5bda0 Eric Dumazet      2021-07-01  339  	struct pci_p2pdma *p2pdma;
52916982af48d9 Logan Gunthorpe   2018-10-04  340  	void *addr;
52916982af48d9 Logan Gunthorpe   2018-10-04  341  	int error;
52916982af48d9 Logan Gunthorpe   2018-10-04  342  
52916982af48d9 Logan Gunthorpe   2018-10-04  343  	if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))
52916982af48d9 Logan Gunthorpe   2018-10-04  344  		return -EINVAL;
52916982af48d9 Logan Gunthorpe   2018-10-04  345  
52916982af48d9 Logan Gunthorpe   2018-10-04  346  	if (offset >= pci_resource_len(pdev, bar))
52916982af48d9 Logan Gunthorpe   2018-10-04  347  		return -EINVAL;
52916982af48d9 Logan Gunthorpe   2018-10-04  348  
52916982af48d9 Logan Gunthorpe   2018-10-04  349  	if (!size)
52916982af48d9 Logan Gunthorpe   2018-10-04  350  		size = pci_resource_len(pdev, bar) - offset;
52916982af48d9 Logan Gunthorpe   2018-10-04  351  
52916982af48d9 Logan Gunthorpe   2018-10-04  352  	if (size + offset > pci_resource_len(pdev, bar))
52916982af48d9 Logan Gunthorpe   2018-10-04  353  		return -EINVAL;
52916982af48d9 Logan Gunthorpe   2018-10-04  354  
906b14c15e3d67 Leon Romanovsky   2025-07-16  355  	p2pdma = rcu_dereference_protected(pdev->p2pdma, 1);
906b14c15e3d67 Leon Romanovsky   2025-07-16 @356  	if (!p2pdma) {
                                                             ^^^^^^
Checked for NULL.

906b14c15e3d67 Leon Romanovsky   2025-07-16  357  		mem = pci_p2pdma_enable(pdev);

mem is uninitialized on else path.

906b14c15e3d67 Leon Romanovsky   2025-07-16  358  		if (IS_ERR(mem))
906b14c15e3d67 Leon Romanovsky   2025-07-16  359  			return PTR_ERR(mem);
906b14c15e3d67 Leon Romanovsky   2025-07-16  360  
906b14c15e3d67 Leon Romanovsky   2025-07-16  361  		error = pci_p2pdma_setup_pool(pdev);
52916982af48d9 Logan Gunthorpe   2018-10-04  362  		if (error)
52916982af48d9 Logan Gunthorpe   2018-10-04  363  			return error;
52916982af48d9 Logan Gunthorpe   2018-10-04  364  	}
52916982af48d9 Logan Gunthorpe   2018-10-04  365  
a6e6fe6549f609 Logan Gunthorpe   2019-08-12  366  	p2p_pgmap = devm_kzalloc(&pdev->dev, sizeof(*p2p_pgmap), GFP_KERNEL);
906b14c15e3d67 Leon Romanovsky   2025-07-16  367  	if (!p2p_pgmap) {
906b14c15e3d67 Leon Romanovsky   2025-07-16  368  		error = -ENOMEM;
906b14c15e3d67 Leon Romanovsky   2025-07-16  369  		goto free_pool;
906b14c15e3d67 Leon Romanovsky   2025-07-16  370  	}
a6e6fe6549f609 Logan Gunthorpe   2019-08-12  371  
a6e6fe6549f609 Logan Gunthorpe   2019-08-12  372  	pgmap = &p2p_pgmap->pgmap;
a4574f63edc6f7 Dan Williams      2020-10-13  373  	pgmap->range.start = pci_resource_start(pdev, bar) + offset;
a4574f63edc6f7 Dan Williams      2020-10-13  374  	pgmap->range.end = pgmap->range.start + size - 1;
b7b3c01b191596 Dan Williams      2020-10-13  375  	pgmap->nr_range = 1;
52916982af48d9 Logan Gunthorpe   2018-10-04  376  	pgmap->type = MEMORY_DEVICE_PCI_P2PDMA;
7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  377  	pgmap->ops = &p2pdma_pgmap_ops;
906b14c15e3d67 Leon Romanovsky   2025-07-16 @378  	p2p_pgmap->mem = mem;
                                                                         ^^^
Uninitialized.

52916982af48d9 Logan Gunthorpe   2018-10-04  379  
52916982af48d9 Logan Gunthorpe   2018-10-04  380  	addr = devm_memremap_pages(&pdev->dev, pgmap);
52916982af48d9 Logan Gunthorpe   2018-10-04  381  	if (IS_ERR(addr)) {
52916982af48d9 Logan Gunthorpe   2018-10-04  382  		error = PTR_ERR(addr);
50f44ee7248ad2 Dan Williams      2019-06-13  383  		goto pgmap_free;
52916982af48d9 Logan Gunthorpe   2018-10-04  384  	}
52916982af48d9 Logan Gunthorpe   2018-10-04  385  
7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  386  	error = devm_add_action_or_reset(&pdev->dev, pci_p2pdma_unmap_mappings,
f3c373972cd38e Leon Romanovsky   2025-07-07  387  					 p2p_pgmap);
7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  388  	if (error)
7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  389  		goto pages_free;
7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  390  
ae21f835a5bda0 Eric Dumazet      2021-07-01 @391  	error = gen_pool_add_owner(p2pdma->pool, (unsigned long)addr,
                                                                                   ^^^^^^^^^^^^
Unchecked dereference.

52916982af48d9 Logan Gunthorpe   2018-10-04  392  			pci_bus_address(pdev, bar) + offset,
a4574f63edc6f7 Dan Williams      2020-10-13  393  			range_len(&pgmap->range), dev_to_node(&pdev->dev),
b80892ca022e9e Christoph Hellwig 2021-10-28  394  			&pgmap->ref);
52916982af48d9 Logan Gunthorpe   2018-10-04  395  	if (error)
e615a191216e3f Dan Williams      2019-06-13  396  		goto pages_free;
52916982af48d9 Logan Gunthorpe   2018-10-04  397  
a4574f63edc6f7 Dan Williams      2020-10-13  398  	pci_info(pdev, "added peer-to-peer DMA memory %#llx-%#llx\n",
a4574f63edc6f7 Dan Williams      2020-10-13  399  		 pgmap->range.start, pgmap->range.end);
52916982af48d9 Logan Gunthorpe   2018-10-04  400  
52916982af48d9 Logan Gunthorpe   2018-10-04  401  	return 0;
52916982af48d9 Logan Gunthorpe   2018-10-04  402  
e615a191216e3f Dan Williams      2019-06-13  403  pages_free:
e615a191216e3f Dan Williams      2019-06-13  404  	devm_memunmap_pages(&pdev->dev, pgmap);
52916982af48d9 Logan Gunthorpe   2018-10-04  405  pgmap_free:
906b14c15e3d67 Leon Romanovsky   2025-07-16  406  	devm_kfree(&pdev->dev, p2p_pgmap);
906b14c15e3d67 Leon Romanovsky   2025-07-16  407  free_pool:
906b14c15e3d67 Leon Romanovsky   2025-07-16  408  	sysfs_remove_group(&pdev->dev.kobj, &p2pmem_group);
906b14c15e3d67 Leon Romanovsky   2025-07-16  409  	gen_pool_destroy(p2pdma->pool);
                                                                         ^^^^^^^^^^^^

52916982af48d9 Logan Gunthorpe   2018-10-04  410  	return error;
52916982af48d9 Logan Gunthorpe   2018-10-04  411  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 3+ messages in thread
* [leon-rdma:dmabuf-vfio 20/26] drivers/pci/p2pdma.c:378 pci_p2pdma_add_resource() error: uninitialized symbol 'mem'.
@ 2025-08-04  0:47 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2025-08-04  0:47 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
TO: Leon Romanovsky <leonro@nvidia.com>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git dmabuf-vfio
head:   f4212771ee1cf899f5ac8c9b6acd3bb7f49691fc
commit: 906b14c15e3d67c3aa9031bc3fee805343fb75c6 [20/26] PCI/P2PDMA: Refactor to separate core P2P functionality from memory allocation
:::::: branch date: 11 hours ago
:::::: commit date: 11 hours ago
config: x86_64-randconfig-161-20250804 (https://download.01.org/0day-ci/archive/20250804/202508040847.0z9fDkel-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.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@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202508040847.0z9fDkel-lkp@intel.com/

smatch warnings:
drivers/pci/p2pdma.c:378 pci_p2pdma_add_resource() error: uninitialized symbol 'mem'.
drivers/pci/p2pdma.c:391 pci_p2pdma_add_resource() error: we previously assumed 'p2pdma' could be null (see line 356)

vim +/mem +378 drivers/pci/p2pdma.c

7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  322  
52916982af48d9 Logan Gunthorpe   2018-10-04  323  /**
52916982af48d9 Logan Gunthorpe   2018-10-04  324   * pci_p2pdma_add_resource - add memory for use as p2p memory
52916982af48d9 Logan Gunthorpe   2018-10-04  325   * @pdev: the device to add the memory to
52916982af48d9 Logan Gunthorpe   2018-10-04  326   * @bar: PCI BAR to add
52916982af48d9 Logan Gunthorpe   2018-10-04  327   * @size: size of the memory to add, may be zero to use the whole BAR
52916982af48d9 Logan Gunthorpe   2018-10-04  328   * @offset: offset into the PCI BAR
52916982af48d9 Logan Gunthorpe   2018-10-04  329   *
52916982af48d9 Logan Gunthorpe   2018-10-04  330   * The memory will be given ZONE_DEVICE struct pages so that it may
52916982af48d9 Logan Gunthorpe   2018-10-04  331   * be used with any DMA request.
52916982af48d9 Logan Gunthorpe   2018-10-04  332   */
52916982af48d9 Logan Gunthorpe   2018-10-04  333  int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
52916982af48d9 Logan Gunthorpe   2018-10-04  334  			    u64 offset)
52916982af48d9 Logan Gunthorpe   2018-10-04  335  {
a6e6fe6549f609 Logan Gunthorpe   2019-08-12  336  	struct pci_p2pdma_pagemap *p2p_pgmap;
906b14c15e3d67 Leon Romanovsky   2025-07-16  337  	struct p2pdma_provider *mem;
52916982af48d9 Logan Gunthorpe   2018-10-04  338  	struct dev_pagemap *pgmap;
ae21f835a5bda0 Eric Dumazet      2021-07-01  339  	struct pci_p2pdma *p2pdma;
52916982af48d9 Logan Gunthorpe   2018-10-04  340  	void *addr;
52916982af48d9 Logan Gunthorpe   2018-10-04  341  	int error;
52916982af48d9 Logan Gunthorpe   2018-10-04  342  
52916982af48d9 Logan Gunthorpe   2018-10-04  343  	if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))
52916982af48d9 Logan Gunthorpe   2018-10-04  344  		return -EINVAL;
52916982af48d9 Logan Gunthorpe   2018-10-04  345  
52916982af48d9 Logan Gunthorpe   2018-10-04  346  	if (offset >= pci_resource_len(pdev, bar))
52916982af48d9 Logan Gunthorpe   2018-10-04  347  		return -EINVAL;
52916982af48d9 Logan Gunthorpe   2018-10-04  348  
52916982af48d9 Logan Gunthorpe   2018-10-04  349  	if (!size)
52916982af48d9 Logan Gunthorpe   2018-10-04  350  		size = pci_resource_len(pdev, bar) - offset;
52916982af48d9 Logan Gunthorpe   2018-10-04  351  
52916982af48d9 Logan Gunthorpe   2018-10-04  352  	if (size + offset > pci_resource_len(pdev, bar))
52916982af48d9 Logan Gunthorpe   2018-10-04  353  		return -EINVAL;
52916982af48d9 Logan Gunthorpe   2018-10-04  354  
906b14c15e3d67 Leon Romanovsky   2025-07-16  355  	p2pdma = rcu_dereference_protected(pdev->p2pdma, 1);
906b14c15e3d67 Leon Romanovsky   2025-07-16 @356  	if (!p2pdma) {
906b14c15e3d67 Leon Romanovsky   2025-07-16  357  		mem = pci_p2pdma_enable(pdev);
906b14c15e3d67 Leon Romanovsky   2025-07-16  358  		if (IS_ERR(mem))
906b14c15e3d67 Leon Romanovsky   2025-07-16  359  			return PTR_ERR(mem);
906b14c15e3d67 Leon Romanovsky   2025-07-16  360  
906b14c15e3d67 Leon Romanovsky   2025-07-16  361  		error = pci_p2pdma_setup_pool(pdev);
52916982af48d9 Logan Gunthorpe   2018-10-04  362  		if (error)
52916982af48d9 Logan Gunthorpe   2018-10-04  363  			return error;
52916982af48d9 Logan Gunthorpe   2018-10-04  364  	}
52916982af48d9 Logan Gunthorpe   2018-10-04  365  
a6e6fe6549f609 Logan Gunthorpe   2019-08-12  366  	p2p_pgmap = devm_kzalloc(&pdev->dev, sizeof(*p2p_pgmap), GFP_KERNEL);
906b14c15e3d67 Leon Romanovsky   2025-07-16  367  	if (!p2p_pgmap) {
906b14c15e3d67 Leon Romanovsky   2025-07-16  368  		error = -ENOMEM;
906b14c15e3d67 Leon Romanovsky   2025-07-16  369  		goto free_pool;
906b14c15e3d67 Leon Romanovsky   2025-07-16  370  	}
a6e6fe6549f609 Logan Gunthorpe   2019-08-12  371  
a6e6fe6549f609 Logan Gunthorpe   2019-08-12  372  	pgmap = &p2p_pgmap->pgmap;
a4574f63edc6f7 Dan Williams      2020-10-13  373  	pgmap->range.start = pci_resource_start(pdev, bar) + offset;
a4574f63edc6f7 Dan Williams      2020-10-13  374  	pgmap->range.end = pgmap->range.start + size - 1;
b7b3c01b191596 Dan Williams      2020-10-13  375  	pgmap->nr_range = 1;
52916982af48d9 Logan Gunthorpe   2018-10-04  376  	pgmap->type = MEMORY_DEVICE_PCI_P2PDMA;
7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  377  	pgmap->ops = &p2pdma_pgmap_ops;
906b14c15e3d67 Leon Romanovsky   2025-07-16 @378  	p2p_pgmap->mem = mem;
52916982af48d9 Logan Gunthorpe   2018-10-04  379  
52916982af48d9 Logan Gunthorpe   2018-10-04  380  	addr = devm_memremap_pages(&pdev->dev, pgmap);
52916982af48d9 Logan Gunthorpe   2018-10-04  381  	if (IS_ERR(addr)) {
52916982af48d9 Logan Gunthorpe   2018-10-04  382  		error = PTR_ERR(addr);
50f44ee7248ad2 Dan Williams      2019-06-13  383  		goto pgmap_free;
52916982af48d9 Logan Gunthorpe   2018-10-04  384  	}
52916982af48d9 Logan Gunthorpe   2018-10-04  385  
7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  386  	error = devm_add_action_or_reset(&pdev->dev, pci_p2pdma_unmap_mappings,
f3c373972cd38e Leon Romanovsky   2025-07-07  387  					 p2p_pgmap);
7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  388  	if (error)
7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  389  		goto pages_free;
7e9c7ef83d7852 Logan Gunthorpe   2022-10-21  390  
ae21f835a5bda0 Eric Dumazet      2021-07-01 @391  	error = gen_pool_add_owner(p2pdma->pool, (unsigned long)addr,
52916982af48d9 Logan Gunthorpe   2018-10-04  392  			pci_bus_address(pdev, bar) + offset,
a4574f63edc6f7 Dan Williams      2020-10-13  393  			range_len(&pgmap->range), dev_to_node(&pdev->dev),
b80892ca022e9e Christoph Hellwig 2021-10-28  394  			&pgmap->ref);
52916982af48d9 Logan Gunthorpe   2018-10-04  395  	if (error)
e615a191216e3f Dan Williams      2019-06-13  396  		goto pages_free;
52916982af48d9 Logan Gunthorpe   2018-10-04  397  
a4574f63edc6f7 Dan Williams      2020-10-13  398  	pci_info(pdev, "added peer-to-peer DMA memory %#llx-%#llx\n",
a4574f63edc6f7 Dan Williams      2020-10-13  399  		 pgmap->range.start, pgmap->range.end);
52916982af48d9 Logan Gunthorpe   2018-10-04  400  
52916982af48d9 Logan Gunthorpe   2018-10-04  401  	return 0;
52916982af48d9 Logan Gunthorpe   2018-10-04  402  
e615a191216e3f Dan Williams      2019-06-13  403  pages_free:
e615a191216e3f Dan Williams      2019-06-13  404  	devm_memunmap_pages(&pdev->dev, pgmap);
52916982af48d9 Logan Gunthorpe   2018-10-04  405  pgmap_free:
906b14c15e3d67 Leon Romanovsky   2025-07-16  406  	devm_kfree(&pdev->dev, p2p_pgmap);
906b14c15e3d67 Leon Romanovsky   2025-07-16  407  free_pool:
906b14c15e3d67 Leon Romanovsky   2025-07-16  408  	sysfs_remove_group(&pdev->dev.kobj, &p2pmem_group);
906b14c15e3d67 Leon Romanovsky   2025-07-16  409  	gen_pool_destroy(p2pdma->pool);
52916982af48d9 Logan Gunthorpe   2018-10-04  410  	return error;
52916982af48d9 Logan Gunthorpe   2018-10-04  411  }
52916982af48d9 Logan Gunthorpe   2018-10-04  412  EXPORT_SYMBOL_GPL(pci_p2pdma_add_resource);
52916982af48d9 Logan Gunthorpe   2018-10-04  413  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-04  7:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-04  6:40 [leon-rdma:dmabuf-vfio 20/26] drivers/pci/p2pdma.c:378 pci_p2pdma_add_resource() error: uninitialized symbol 'mem' Dan Carpenter
2025-08-04  7:01 ` Leon Romanovsky
  -- strict thread matches above, loose matches on Subject: below --
2025-08-04  0:47 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.