]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/PCI: Check pcie_find_root_port() return for NULL
authorSamasth Norway Ananda <samasth.norway.ananda@oracle.com>
Mon, 12 Aug 2024 20:26:59 +0000 (13:26 -0700)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 21 Aug 2024 20:28:08 +0000 (15:28 -0500)
If pcie_find_root_port() is unable to locate a Root Port, it will return
NULL. Check the pointer for NULL before dereferencing it.

This particular case is in a quirk for devices that are always below a Root
Port, so this won't avoid a problem and doesn't need to be backported, but
check as a matter of style and to prevent copy/paste mistakes.

Link: https://lore.kernel.org/r/20240812202659.1649121-1-samasth.norway.ananda@oracle.com
Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
[bhelgaas: drop Fixes: and explain why there's no problem in this case]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
arch/x86/pci/fixup.c

index b33afb240601b006d5fd27b5245fed16354f3f71..98a9bb92d75c88ac059f518b2c46fcf5c4ed703a 100644 (file)
@@ -980,7 +980,7 @@ static void amd_rp_pme_suspend(struct pci_dev *dev)
                return;
 
        rp = pcie_find_root_port(dev);
-       if (!rp->pm_cap)
+       if (!rp || !rp->pm_cap)
                return;
 
        rp->pme_support &= ~((PCI_PM_CAP_PME_D3hot|PCI_PM_CAP_PME_D3cold) >>
@@ -994,7 +994,7 @@ static void amd_rp_pme_resume(struct pci_dev *dev)
        u16 pmc;
 
        rp = pcie_find_root_port(dev);
-       if (!rp->pm_cap)
+       if (!rp || !rp->pm_cap)
                return;
 
        pci_read_config_word(rp, rp->pm_cap + PCI_PM_PMC, &pmc);