x86/pci: Return pci_mmconfig_add() failure early
authorBjorn Helgaas <bhelgaas@google.com>
Tue, 21 Nov 2023 18:36:42 +0000 (12:36 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 5 Dec 2023 16:56:59 +0000 (10:56 -0600)
If pci_mmconfig_alloc() fails, return the failure early so it's obvious
that the failure is the exception, and the success is the normal case.  No
functional change intended.

Link: https://lore.kernel.org/r/20231121183643.249006-9-helgaas@kernel.org
Tested-by: Tomasz Pala <gotar@polanet.pl>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
arch/x86/pci/mmconfig-shared.c

index 459e95782bb156e8cae665454ef82291f6bba6ef..0cc9520666efbbe0c61a53aff2467ac5afb433f6 100644 (file)
@@ -102,14 +102,15 @@ struct pci_mmcfg_region *__init pci_mmconfig_add(int segment, int start,
        struct pci_mmcfg_region *new;
 
        new = pci_mmconfig_alloc(segment, start, end, addr);
-       if (new) {
-               mutex_lock(&pci_mmcfg_lock);
-               list_add_sorted(new);
-               mutex_unlock(&pci_mmcfg_lock);
+       if (!new)
+               return NULL;
 
-               pr_info("ECAM %pR (base %#lx) for domain %04x [bus %02x-%02x]\n",
-                       &new->res, (unsigned long)addr, segment, start, end);
-       }
+       mutex_lock(&pci_mmcfg_lock);
+       list_add_sorted(new);
+       mutex_unlock(&pci_mmcfg_lock);
+
+       pr_info("ECAM %pR (base %#lx) for domain %04x [bus %02x-%02x]\n",
+               &new->res, (unsigned long)addr, segment, start, end);
 
        return new;
 }