diff options
author | Logan Gunthorpe <logang@deltatee.com> | 2023-02-09 20:29:53 +0300 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2023-02-17 01:31:12 +0300 |
commit | 6606f4c3c48c7a75b13816266d3ea562eeec0b44 (patch) | |
tree | 28f9cd67b7e5029d3e5edf1d8907a965b365491a /drivers/pci | |
parent | 1b929c02afd37871d5afb9d498426f83432e71c2 (diff) | |
download | linux-6606f4c3c48c7a75b13816266d3ea562eeec0b44.tar.xz |
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>
Diffstat (limited to 'drivers/pci')
-rw-r--r-- | drivers/pci/p2pdma.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 86812d2073ea..9e8205572830 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -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); } |