PCI/P2PDMA: Annotate RCU dereference

A dereference of the __rcu pointer was noticed by sparse:

  drivers/pci/p2pdma.c:199:44: sparse: sparse: dereference of noderef expression

Dereference the __rcu pointer using rcu_dereference_protected() instead of
accessing it directly. It's safe to use rcu_dereference_protected() because
a reference is held on the pgmap's percpu reference counter and thus it
cannot disappear.

Link: https://lore.kernel.org/r/20230209172953.4597-1-logang@deltatee.com
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
This commit is contained in:
Logan Gunthorpe 2023-02-09 10:29:53 -07:00 коммит произвёл Bjorn Helgaas
Родитель 1b929c02af
Коммит 6606f4c3c4
1 изменённых файлов: 5 добавлений и 3 удалений

Просмотреть файл

@ -194,11 +194,13 @@ static const struct attribute_group p2pmem_group = {
static void p2pdma_page_free(struct page *page)
{
struct pci_p2pdma_pagemap *pgmap = to_p2p_pgmap(page->pgmap);
/* safe to dereference while a reference is held to the percpu ref */
struct pci_p2pdma *p2pdma =
rcu_dereference_protected(pgmap->provider->p2pdma, 1);
struct percpu_ref *ref;
gen_pool_free_owner(pgmap->provider->p2pdma->pool,
(uintptr_t)page_to_virt(page), PAGE_SIZE,
(void **)&ref);
gen_pool_free_owner(p2pdma->pool, (uintptr_t)page_to_virt(page),
PAGE_SIZE, (void **)&ref);
percpu_ref_put(ref);
}