]> www.infradead.org Git - users/hch/misc.git/commitdiff
PCI/P2PDMA: Fix incorrect pointer usage in devm_kfree() call
authorSungho Kim <sungho.kim@furiosa.ai>
Wed, 20 Aug 2025 10:57:14 +0000 (19:57 +0900)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 20 Aug 2025 20:25:54 +0000 (15:25 -0500)
The error handling path in pci_p2pdma_add_resource() contains a bug in its
`pgmap_free` label.

Memory is allocated for the `p2p_pgmap` struct, and the pointer is stored
in `p2p_pgmap`. However, the error path calls devm_kfree() with `pgmap`,
which is a pointer to a member field within the `p2p_pgmap` struct, not the
base pointer of the allocation.

Correct the bug by passing the correct base pointer, `p2p_pgmap`, to
devm_kfree().

Signed-off-by: Sungho Kim <sungho.kim@furiosa.ai>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Link: https://patch.msgid.link/20250820105714.2939896-1-sungho.kim@furiosa.ai
drivers/pci/p2pdma.c

index da5657a020074e4ad59d3763ef6298f251d545a4..1cb5e423eed4f53159f7690f64b5094a02492172 100644 (file)
@@ -360,7 +360,7 @@ int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
 pages_free:
        devm_memunmap_pages(&pdev->dev, pgmap);
 pgmap_free:
-       devm_kfree(&pdev->dev, pgmap);
+       devm_kfree(&pdev->dev, p2p_pgmap);
        return error;
 }
 EXPORT_SYMBOL_GPL(pci_p2pdma_add_resource);